FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 02-02-2011, 08:28 PM
"Ryan O'Hara"
 
Default fenced: send dbus signal when node is fenced

This patch adds the ability to send a dbus signal when a node is fenced.
This code is can reestablish a connection with dbus if necessary.

Signed-off-by: Ryan O'Hara <rohara@redhat.com>
---
fence/fenced/Makefile | 7 +++++--
fence/fenced/config.c | 2 ++
fence/fenced/config.h | 3 +++
fence/fenced/fd.h | 10 ++++++++++
fence/fenced/main.c | 14 ++++++++++++--
fence/fenced/recover.c | 2 ++
6 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
index 7455544..d412001 100644
--- a/fence/fenced/Makefile
+++ b/fence/fenced/Makefile
@@ -16,19 +16,22 @@ OBJS= config.o
main.o
member_cman.o
recover.o
- logging.o
+ logging.o
+ dbus.o

-CFLAGS += -D_FILE_OFFSET_BITS=64
+CFLAGS += -D_FILE_OFFSET_BITS=64 -DDBUS
CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${logtincdir} -I${corosyncincdir}
CFLAGS += -I${fenceincdir} -I${fencedincdir}
CFLAGS += -I$(S) -I$(S)/../include -I$(SRCDIR)/group/lib
CFLAGS += -I${incdir}
+CFLAGS += $(shell pkg-config --cflags dbus-1)

LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -lccs -lcman
LDFLAGS += -L${logtlibdir} -L${fencelibdir} -llogthread -lfence
LDFLAGS += -L${corosynclibdir} -lcpg -lpthread
LDFLAGS += -L../../group/lib -l group
LDFLAGS += -L${libdir}
+LDFLAGS += $(shell pkg-config --libs dbus-1)

LDDEPS += ../../group/lib/libgroup.a

diff --git a/fence/fenced/config.c b/fence/fenced/config.c
index 37f98f9..0517c2a 100644
--- a/fence/fenced/config.c
+++ b/fence/fenced/config.c
@@ -9,6 +9,7 @@ int ccs_handle;
int optd_groupd_compat;
int optd_debug_logfile;
int optd_clean_start;
+int optd_disable_dbus;
int optd_skip_undefined;
int optd_post_join_delay;
int optd_post_fail_delay;
@@ -20,6 +21,7 @@ int optd_override_path;
int cfgd_groupd_compat = DEFAULT_GROUPD_COMPAT;
int cfgd_debug_logfile = DEFAULT_DEBUG_LOGFILE;
int cfgd_clean_start = DEFAULT_CLEAN_START;
+int cfgd_disable_dbus = DEFAULT_DISABLE_DBUS;
int cfgd_skip_undefined = DEFAULT_SKIP_UNDEFINED;
int cfgd_post_join_delay = DEFAULT_POST_JOIN_DELAY;
int cfgd_post_fail_delay = DEFAULT_POST_FAIL_DELAY;
diff --git a/fence/fenced/config.h b/fence/fenced/config.h
index f65af0e..d17ed1a 100644
--- a/fence/fenced/config.h
+++ b/fence/fenced/config.h
@@ -4,6 +4,7 @@
#define DEFAULT_GROUPD_COMPAT 0
#define DEFAULT_DEBUG_LOGFILE 0
#define DEFAULT_CLEAN_START 0
+#define DEFAULT_DISABLE_DBUS 0
#define DEFAULT_SKIP_UNDEFINED 0
#define DEFAULT_POST_JOIN_DELAY 6
#define DEFAULT_POST_FAIL_DELAY 0
@@ -13,6 +14,7 @@
extern int optd_groupd_compat;
extern int optd_debug_logfile;
extern int optd_clean_start;
+extern int optd_disable_dbus;
extern int optd_skip_undefined;
extern int optd_post_join_delay;
extern int optd_post_fail_delay;
@@ -22,6 +24,7 @@ extern int optd_override_path;
extern int cfgd_groupd_compat;
extern int cfgd_debug_logfile;
extern int cfgd_clean_start;
+extern int cfgd_disable_dbus;
extern int cfgd_skip_undefined;
extern int cfgd_post_join_delay;
extern int cfgd_post_fail_delay;
diff --git a/fence/fenced/fd.h b/fence/fenced/fd.h
index a5a78bf..4ce18c7 100644
--- a/fence/fenced/fd.h
+++ b/fence/fenced/fd.h
@@ -23,6 +23,10 @@
#include <sys/select.h>
#include <sys/time.h>

+#ifdef DBUS
+#include <dbus/dbus.h>
+#endif
+
#include <openais/saAis.h>
#include <corosync/cpg.h>
#include <liblogthread.h>
@@ -286,5 +290,11 @@ void init_logging(void);
void setup_logging(void);
void close_logging(void);

+/* dbus.c */
+
+void dbus_init(void);
+void dbus_exit(void);
+void dbus_send(const char *nodename, int nodeid, int result);
+
#endif /* __FD_DOT_H__ */

diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index e5ab568..7db4bbb 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -902,7 +902,7 @@ static void print_usage(void)
printf(" -j <secs> Post-join fencing delay (default %d)
", DEFAULT_POST_JOIN_DELAY);
printf(" -f <secs> Post-fail fencing delay (default %d)
", DEFAULT_POST_FAIL_DELAY);
printf(" -R <secs> Override time (default %d)
", DEFAULT_OVERRIDE_TIME);
-
+ printf(" -q Disable dbus signals
");
printf(" -O <path> Override path (default %s)
", DEFAULT_OVERRIDE_PATH);
printf(" -h Print this help, then exit
");
printf(" -V Print program version information, then exit
");
@@ -912,7 +912,7 @@ static void print_usage(void)
printf("
");
}

-#define OPTION_STRING "Lg:cj:fn:O:hVSse:r:"
+#define OPTION_STRING "Lg:cj:fn:O:hVSse:r:q"

static void read_arguments(int argc, char **argv)
{
@@ -970,6 +970,11 @@ static void read_arguments(int argc, char **argv)
cfgd_override_path = strdup(optarg);
break;

+ case 'q':
+ optd_disable_dbus = 1;
+ cfgd_disable_dbus = 1;
+ break;
+
case 'r':
register_controlled_dir(optarg);
break;
@@ -1042,8 +1047,13 @@ int main(int argc, char **argv)
signal(SIGTERM, sigterm_handler);
set_oom_adj(-16);

+ if (!optd_disable_dbus) {
+ dbus_init();
+ }
+
loop();

+ dbus_exit();
unlink(LOCKFILE_NAME);
return 0;
}
diff --git a/fence/fenced/recover.c b/fence/fenced/recover.c
index a7ca047..5d7680d 100644
--- a/fence/fenced/recover.c
+++ b/fence/fenced/recover.c
@@ -384,6 +384,8 @@ void fence_victims(struct fd *fd)
log_error("fence %s %s", node->name,
error ? "failed" : "success");

+ dbus_send(node->name, node->nodeid, error);
+
skip_log_message:
if (!error) {
node->local_victim_done = 1;
--
1.7.2.3
 
Old 02-02-2011, 09:35 PM
"Ryan O'Hara"
 
Default fenced: send dbus signal when node is fenced

This patch adds the ability to send a dbus signal when a node is fenced.
This code is can reestablish a connection with dbus if necessary.

Signed-off-by: Ryan O'Hara <rohara@redhat.com>
---
fence/fenced/Makefile | 7 +++-
fence/fenced/config.c | 2 +
fence/fenced/config.h | 3 ++
fence/fenced/dbus.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++
fence/fenced/fd.h | 10 +++++
fence/fenced/main.c | 14 ++++++-
fence/fenced/recover.c | 2 +
7 files changed, 124 insertions(+), 4 deletions(-)
create mode 100644 fence/fenced/dbus.c

diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
index 7455544..d412001 100644
--- a/fence/fenced/Makefile
+++ b/fence/fenced/Makefile
@@ -16,19 +16,22 @@ OBJS= config.o
main.o
member_cman.o
recover.o
- logging.o
+ logging.o
+ dbus.o

-CFLAGS += -D_FILE_OFFSET_BITS=64
+CFLAGS += -D_FILE_OFFSET_BITS=64 -DDBUS
CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${logtincdir} -I${corosyncincdir}
CFLAGS += -I${fenceincdir} -I${fencedincdir}
CFLAGS += -I$(S) -I$(S)/../include -I$(SRCDIR)/group/lib
CFLAGS += -I${incdir}
+CFLAGS += $(shell pkg-config --cflags dbus-1)

LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -lccs -lcman
LDFLAGS += -L${logtlibdir} -L${fencelibdir} -llogthread -lfence
LDFLAGS += -L${corosynclibdir} -lcpg -lpthread
LDFLAGS += -L../../group/lib -l group
LDFLAGS += -L${libdir}
+LDFLAGS += $(shell pkg-config --libs dbus-1)

LDDEPS += ../../group/lib/libgroup.a

diff --git a/fence/fenced/config.c b/fence/fenced/config.c
index 37f98f9..0517c2a 100644
--- a/fence/fenced/config.c
+++ b/fence/fenced/config.c
@@ -9,6 +9,7 @@ int ccs_handle;
int optd_groupd_compat;
int optd_debug_logfile;
int optd_clean_start;
+int optd_disable_dbus;
int optd_skip_undefined;
int optd_post_join_delay;
int optd_post_fail_delay;
@@ -20,6 +21,7 @@ int optd_override_path;
int cfgd_groupd_compat = DEFAULT_GROUPD_COMPAT;
int cfgd_debug_logfile = DEFAULT_DEBUG_LOGFILE;
int cfgd_clean_start = DEFAULT_CLEAN_START;
+int cfgd_disable_dbus = DEFAULT_DISABLE_DBUS;
int cfgd_skip_undefined = DEFAULT_SKIP_UNDEFINED;
int cfgd_post_join_delay = DEFAULT_POST_JOIN_DELAY;
int cfgd_post_fail_delay = DEFAULT_POST_FAIL_DELAY;
diff --git a/fence/fenced/config.h b/fence/fenced/config.h
index f65af0e..d17ed1a 100644
--- a/fence/fenced/config.h
+++ b/fence/fenced/config.h
@@ -4,6 +4,7 @@
#define DEFAULT_GROUPD_COMPAT 0
#define DEFAULT_DEBUG_LOGFILE 0
#define DEFAULT_CLEAN_START 0
+#define DEFAULT_DISABLE_DBUS 0
#define DEFAULT_SKIP_UNDEFINED 0
#define DEFAULT_POST_JOIN_DELAY 6
#define DEFAULT_POST_FAIL_DELAY 0
@@ -13,6 +14,7 @@
extern int optd_groupd_compat;
extern int optd_debug_logfile;
extern int optd_clean_start;
+extern int optd_disable_dbus;
extern int optd_skip_undefined;
extern int optd_post_join_delay;
extern int optd_post_fail_delay;
@@ -22,6 +24,7 @@ extern int optd_override_path;
extern int cfgd_groupd_compat;
extern int cfgd_debug_logfile;
extern int cfgd_clean_start;
+extern int cfgd_disable_dbus;
extern int cfgd_skip_undefined;
extern int cfgd_post_join_delay;
extern int cfgd_post_fail_delay;
diff --git a/fence/fenced/dbus.c b/fence/fenced/dbus.c
new file mode 100644
index 0000000..037da2f
--- /dev/null
+++ b/fence/fenced/dbus.c
@@ -0,0 +1,90 @@
+#include "fd.h"
+#include "config.h"
+
+#define DBUS_FENCE_NAME "com.redhat.cluster.fence"
+#define DBUS_FENCE_IFACE "com.redhat.cluster.fence"
+#define DBUS_FENCE_PATH "/com/redhat/cluster/fence"
+
+#ifdef DBUS
+static DBusConnection *bus = NULL;
+#endif
+
+void dbus_init (void)
+{
+#ifdef DBUS
+
+ if (!(bus = dbus_bus_get_private (DBUS_BUS_SYSTEM, NULL))) {
+ log_error ("failed to get dbus connection");
+ } else {
+ log_debug ("connected to dbus %s", dbus_bus_get_unique_name (bus));
+ }
+
+#endif
+
+ return;
+}
+
+void dbus_exit (void)
+{
+#ifdef DBUS
+
+ if (bus) {
+ dbus_connection_close (bus);
+ dbus_connection_unref (bus);
+ }
+ bus = NULL;
+
+#endif
+
+ return;
+}
+
+void dbus_send (const char *nodename, int nodeid, int result)
+{
+#ifdef DBUS
+
+ DBusMessage *msg = NULL;
+
+ if (bus && !dbus_connection_read_write (bus, 1)) {
+ log_debug ("disconnected from dbus");
+ dbus_exit ();
+ }
+
+ if (!bus) {
+ dbus_init ();
+ }
+
+ if (!bus) {
+ goto out;
+ }
+
+ if (!(msg = dbus_message_new_signal (DBUS_FENCE_PATH,
+ DBUS_FENCE_IFACE,
+ "FenceNode")))
+ {
+ log_error ("failed to create dbus signal");
+ goto out;
+ }
+
+ if (!dbus_message_append_args (msg,
+ DBUS_TYPE_STRING, &nodename,
+ DBUS_TYPE_INT32, &nodeid,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID))
+ {
+ log_error ("failed to append args to dbus signal");
+ goto out;
+ }
+
+ dbus_connection_send (bus, msg, NULL);
+ dbus_connection_flush (bus);
+
+out:
+ if (msg) {
+ dbus_message_unref (msg);
+ }
+
+#endif
+
+ return;
+}
diff --git a/fence/fenced/fd.h b/fence/fenced/fd.h
index a5a78bf..4ce18c7 100644
--- a/fence/fenced/fd.h
+++ b/fence/fenced/fd.h
@@ -23,6 +23,10 @@
#include <sys/select.h>
#include <sys/time.h>

+#ifdef DBUS
+#include <dbus/dbus.h>
+#endif
+
#include <openais/saAis.h>
#include <corosync/cpg.h>
#include <liblogthread.h>
@@ -286,5 +290,11 @@ void init_logging(void);
void setup_logging(void);
void close_logging(void);

+/* dbus.c */
+
+void dbus_init(void);
+void dbus_exit(void);
+void dbus_send(const char *nodename, int nodeid, int result);
+
#endif /* __FD_DOT_H__ */

diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index e5ab568..832413e 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -902,7 +902,7 @@ static void print_usage(void)
printf(" -j <secs> Post-join fencing delay (default %d)
", DEFAULT_POST_JOIN_DELAY);
printf(" -f <secs> Post-fail fencing delay (default %d)
", DEFAULT_POST_FAIL_DELAY);
printf(" -R <secs> Override time (default %d)
", DEFAULT_OVERRIDE_TIME);
-
+ printf(" -q Disable dbus signals
");
printf(" -O <path> Override path (default %s)
", DEFAULT_OVERRIDE_PATH);
printf(" -h Print this help, then exit
");
printf(" -V Print program version information, then exit
");
@@ -912,7 +912,7 @@ static void print_usage(void)
printf("
");
}

-#define OPTION_STRING "Lg:cj:fn:O:hVSse:r:"
+#define OPTION_STRING "Lg:cj:fn:O:hVSse:r:q"

static void read_arguments(int argc, char **argv)
{
@@ -970,6 +970,11 @@ static void read_arguments(int argc, char **argv)
cfgd_override_path = strdup(optarg);
break;

+ case 'q':
+ optd_disable_dbus = 1;
+ cfgd_disable_dbus = 1;
+ break;
+
case 'r':
register_controlled_dir(optarg);
break;
@@ -1042,8 +1047,13 @@ int main(int argc, char **argv)
signal(SIGTERM, sigterm_handler);
set_oom_adj(-16);

+ if (!optd_disable_dbus) {
+ dbus_init();
+ }
+
loop();

+ dbus_exit();
unlink(LOCKFILE_NAME);
return 0;
}
diff --git a/fence/fenced/recover.c b/fence/fenced/recover.c
index a7ca047..5d7680d 100644
--- a/fence/fenced/recover.c
+++ b/fence/fenced/recover.c
@@ -384,6 +384,8 @@ void fence_victims(struct fd *fd)
log_error("fence %s %s", node->name,
error ? "failed" : "success");

+ dbus_send(node->name, node->nodeid, error);
+
skip_log_message:
if (!error) {
node->local_victim_done = 1;
--
1.7.2.3
 
Old 02-02-2011, 09:55 PM
Lon Hohberger
 
Default fenced: send dbus signal when node is fenced

On Wed, 2011-02-02 at 15:28 -0600, Ryan O'Hara wrote:
> This patch adds the ability to send a dbus signal when a node is fenced.
> This code is can reestablish a connection with dbus if necessary.

(As discussed on IRC: missing dbus.c)

-- Lon
 
Old 02-02-2011, 09:56 PM
Lon Hohberger
 
Default fenced: send dbus signal when node is fenced

On Wed, 2011-02-02 at 16:35 -0600, Ryan O'Hara wrote:
> This patch adds the ability to send a dbus signal when a node is fenced.
> This code is can reestablish a connection with dbus if necessary.

As discussed on IRC - missing check for optd_disable_dbus; that is,
there's no way to actually disable dbus operation.

-- Lon
 
Old 02-02-2011, 10:30 PM
Lon Hohberger
 
Default fenced: send dbus signal when node is fenced

On Wed, 2011-02-02 at 17:56 -0500, Lon Hohberger wrote:
> On Wed, 2011-02-02 at 16:35 -0600, Ryan O'Hara wrote:
> > This patch adds the ability to send a dbus signal when a node is fenced.
> > This code is can reestablish a connection with dbus if necessary.
>
> As discussed on IRC - missing check for optd_disable_dbus; that is,
> there's no way to actually disable dbus operation.
>

ACK with caveats; see reply to PATCH 2/2 below.

That's some clean dbus code.

-- Lon
 
Old 02-03-2011, 05:24 AM
"Fabio M. Di Nitto"
 
Default fenced: send dbus signal when node is fenced

On 02/02/2011 11:35 PM, Ryan O'Hara wrote:
> diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
> index 7455544..d412001 100644
> --- a/fence/fenced/Makefile
> +++ b/fence/fenced/Makefile
> @@ -16,19 +16,22 @@ OBJS= config.o
> main.o
> member_cman.o
> recover.o
> - logging.o
> + logging.o
> + dbus.o
>
> -CFLAGS += -D_FILE_OFFSET_BITS=64
> +CFLAGS += -D_FILE_OFFSET_BITS=64 -DDBUS
> CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${logtincdir} -I${corosyncincdir}
> CFLAGS += -I${fenceincdir} -I${fencedincdir}
> CFLAGS += -I$(S) -I$(S)/../include -I$(SRCDIR)/group/lib
> CFLAGS += -I${incdir}
> +CFLAGS += $(shell pkg-config --cflags dbus-1)
>
> LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -lccs -lcman
> LDFLAGS += -L${logtlibdir} -L${fencelibdir} -llogthread -lfence
> LDFLAGS += -L${corosynclibdir} -lcpg -lpthread
> LDFLAGS += -L../../group/lib -l group
> LDFLAGS += -L${libdir}
> +LDFLAGS += $(shell pkg-config --libs dbus-1)
>
> LDDEPS += ../../group/lib/libgroup.a
>

since we got the build system patch done, it is best to align this
Makefile to rgmanager one. see commit
5d044c3b62d51c688257faecd69bbf3112d7728f in STABLE31

[snip]
# dbus support for notifications
ifndef disable_dbus
CFLAGS += -DDBUS `pkg-config --cflags dbus-1`
DBUS_LDFLAGS += `pkg-config --libs dbus-1`
endif

this way it is all confined in one chunk and can be driven (on/off) by
configure. Default is dbus enabled. --disable_dbus will stop defining
DBUS and requiring dbus pkgconfig bits.

Thanks
Fabio
 
Old 02-03-2011, 01:53 PM
"Ryan O'Hara"
 
Default fenced: send dbus signal when node is fenced

On Thu, Feb 03, 2011 at 07:24:19AM +0100, Fabio M. Di Nitto wrote:
> On 02/02/2011 11:35 PM, Ryan O'Hara wrote:
> > diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
> > index 7455544..d412001 100644
> > --- a/fence/fenced/Makefile
> > +++ b/fence/fenced/Makefile
> > @@ -16,19 +16,22 @@ OBJS= config.o
> > main.o
> > member_cman.o
> > recover.o
> > - logging.o
> > + logging.o
> > + dbus.o
> >
> > -CFLAGS += -D_FILE_OFFSET_BITS=64
> > +CFLAGS += -D_FILE_OFFSET_BITS=64 -DDBUS
> > CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${logtincdir} -I${corosyncincdir}
> > CFLAGS += -I${fenceincdir} -I${fencedincdir}
> > CFLAGS += -I$(S) -I$(S)/../include -I$(SRCDIR)/group/lib
> > CFLAGS += -I${incdir}
> > +CFLAGS += $(shell pkg-config --cflags dbus-1)
> >
> > LDFLAGS += -L${ccslibdir} -L${cmanlibdir} -lccs -lcman
> > LDFLAGS += -L${logtlibdir} -L${fencelibdir} -llogthread -lfence
> > LDFLAGS += -L${corosynclibdir} -lcpg -lpthread
> > LDFLAGS += -L../../group/lib -l group
> > LDFLAGS += -L${libdir}
> > +LDFLAGS += $(shell pkg-config --libs dbus-1)
> >
> > LDDEPS += ../../group/lib/libgroup.a
> >
>
> since we got the build system patch done, it is best to align this
> Makefile to rgmanager one. see commit
> 5d044c3b62d51c688257faecd69bbf3112d7728f in STABLE31
>
> [snip]
> # dbus support for notifications
> ifndef disable_dbus
> CFLAGS += -DDBUS `pkg-config --cflags dbus-1`
> DBUS_LDFLAGS += `pkg-config --libs dbus-1`
> endif
>
> this way it is all confined in one chunk and can be driven (on/off) by
> configure. Default is dbus enabled. --disable_dbus will stop defining
> DBUS and requiring dbus pkgconfig bits.
>
> Thanks
> Fabio

Can you sent said patch to cluster-devel?

Ryan
 
Old 02-03-2011, 04:43 PM
David Teigland
 
Default fenced: send dbus signal when node is fenced

> +void dbus_init (void)

No space before (

Also, it would be a good idea to put a fenced-specific prefix before
fenced's own dbus functions, e.g. fd_dbus_init(), because dbus_ is the
dbus lib's namespace and open to symbol collisions.

> +{
> +#ifdef DBUS
> +
> + if (!(bus = dbus_bus_get_private (DBUS_BUS_SYSTEM, NULL))) {
> + log_error ("failed to get dbus connection");
> + } else {
> + log_debug ("connected to dbus %s", dbus_bus_get_unique_name (bus));
> + }
> +
> +#endif
> +
> + return;
> +}

It may be neater to put all of these functions under a single #ifdef DBUS
and then add empty stubs in an #else.

> +#ifdef DBUS
> +#include <dbus/dbus.h>
> +#endif

could that go in dbus.c?

> + if (!optd_disable_dbus) {
> + dbus_init();

In this case, the optd/cfgd pair is redundant, but technically this should
be testing the cfgd_disable_dbus value (the optd just indicates if the
option has been set on the command line).
 
Old 02-03-2011, 06:26 PM
"Ryan O'Hara"
 
Default fenced: send dbus signal when node is fenced

This patch adds the ability to send a dbus signal when a node is fenced.
This code is can reestablish a connection with dbus if necessary.

Signed-off-by: Ryan O'Hara <rohara@redhat.com>
---
fence/fenced/Makefile | 8 ++++-
fence/fenced/config.c | 2 +
fence/fenced/config.h | 3 ++
fence/fenced/dbus.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
fence/fenced/fd.h | 6 +++
fence/fenced/main.c | 14 +++++++-
fence/fenced/recover.c | 4 ++
7 files changed, 121 insertions(+), 3 deletions(-)
create mode 100644 fence/fenced/dbus.c

diff --git a/fence/fenced/Makefile b/fence/fenced/Makefile
index 7455544..902c299 100644
--- a/fence/fenced/Makefile
+++ b/fence/fenced/Makefile
@@ -16,7 +16,8 @@ OBJS= config.o
main.o
member_cman.o
recover.o
- logging.o
+ logging.o
+ dbus.o

CFLAGS += -D_FILE_OFFSET_BITS=64
CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${logtincdir} -I${corosyncincdir}
@@ -30,6 +31,11 @@ LDFLAGS += -L${corosynclibdir} -lcpg -lpthread
LDFLAGS += -L../../group/lib -l group
LDFLAGS += -L${libdir}

+ifndef disable_dbus
+CFLAGS += $(shell pkg-config --cflags dbus-1) -DDBUS
+LDFLAGS += $(shell pkg-config --libs dbus-1)
+endif
+
LDDEPS += ../../group/lib/libgroup.a

${TARGET}: ${OBJS} ${LDDEPS}
diff --git a/fence/fenced/config.c b/fence/fenced/config.c
index 37f98f9..0517c2a 100644
--- a/fence/fenced/config.c
+++ b/fence/fenced/config.c
@@ -9,6 +9,7 @@ int ccs_handle;
int optd_groupd_compat;
int optd_debug_logfile;
int optd_clean_start;
+int optd_disable_dbus;
int optd_skip_undefined;
int optd_post_join_delay;
int optd_post_fail_delay;
@@ -20,6 +21,7 @@ int optd_override_path;
int cfgd_groupd_compat = DEFAULT_GROUPD_COMPAT;
int cfgd_debug_logfile = DEFAULT_DEBUG_LOGFILE;
int cfgd_clean_start = DEFAULT_CLEAN_START;
+int cfgd_disable_dbus = DEFAULT_DISABLE_DBUS;
int cfgd_skip_undefined = DEFAULT_SKIP_UNDEFINED;
int cfgd_post_join_delay = DEFAULT_POST_JOIN_DELAY;
int cfgd_post_fail_delay = DEFAULT_POST_FAIL_DELAY;
diff --git a/fence/fenced/config.h b/fence/fenced/config.h
index f65af0e..d17ed1a 100644
--- a/fence/fenced/config.h
+++ b/fence/fenced/config.h
@@ -4,6 +4,7 @@
#define DEFAULT_GROUPD_COMPAT 0
#define DEFAULT_DEBUG_LOGFILE 0
#define DEFAULT_CLEAN_START 0
+#define DEFAULT_DISABLE_DBUS 0
#define DEFAULT_SKIP_UNDEFINED 0
#define DEFAULT_POST_JOIN_DELAY 6
#define DEFAULT_POST_FAIL_DELAY 0
@@ -13,6 +14,7 @@
extern int optd_groupd_compat;
extern int optd_debug_logfile;
extern int optd_clean_start;
+extern int optd_disable_dbus;
extern int optd_skip_undefined;
extern int optd_post_join_delay;
extern int optd_post_fail_delay;
@@ -22,6 +24,7 @@ extern int optd_override_path;
extern int cfgd_groupd_compat;
extern int cfgd_debug_logfile;
extern int cfgd_clean_start;
+extern int cfgd_disable_dbus;
extern int cfgd_skip_undefined;
extern int cfgd_post_join_delay;
extern int cfgd_post_fail_delay;
diff --git a/fence/fenced/dbus.c b/fence/fenced/dbus.c
new file mode 100644
index 0000000..a1ee9f0
--- /dev/null
+++ b/fence/fenced/dbus.c
@@ -0,0 +1,87 @@
+#include "fd.h"
+#include "config.h"
+
+#ifdef DBUS
+#include <dbus/dbus.h>
+
+#define DBUS_FENCE_NAME "com.redhat.cluster.fence"
+#define DBUS_FENCE_IFACE "com.redhat.cluster.fence"
+#define DBUS_FENCE_PATH "/com/redhat/cluster/fence"
+
+static DBusConnection *bus = NULL;
+
+void fd_dbus_init(void)
+{
+ if (!(bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL))) {
+ log_error("failed to get dbus connection");
+ } else {
+ log_debug("connected to dbus %s", dbus_bus_get_unique_name(bus));
+ }
+}
+
+void fd_dbus_exit(void)
+{
+ if (bus) {
+ dbus_connection_close(bus);
+ dbus_connection_unref(bus);
+ }
+ bus = NULL;
+}
+
+void fd_dbus_send(const char *nodename, int nodeid, int result)
+{
+ DBusMessage *msg = NULL;
+
+ if (bus && !dbus_connection_read_write(bus, 1)) {
+ log_debug("disconnected from dbus");
+ dbus_exit();
+ }
+
+ if (!bus) {
+ dbus_init();
+ }
+
+ if (!bus) {
+ goto out;
+ }
+
+ if (!(msg = dbus_message_new_signal(DBUS_FENCE_PATH,
+ DBUS_FENCE_IFACE,
+ "FenceNode"))) {
+ log_error("failed to create dbus signal");
+ goto out;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &nodename,
+ DBUS_TYPE_INT32, &nodeid,
+ DBUS_TYPE_INT32, &result,
+ DBUS_TYPE_INVALID)) {
+ log_error("failed to append args to dbus signal");
+ goto out;
+ }
+
+ dbus_connection_send(bus, msg, NULL);
+ dbus_connection_flush(bus);
+
+out:
+ if (msg) {
+ dbus_message_unref(msg);
+ }
+}
+
+#else
+
+void fd_dbus_init(void)
+{
+}
+
+void fd_dbus_exit(void)
+{
+}
+
+void fd_dbus_send(const char *nodename, int nodeid, int result)
+{
+}
+
+#endif /* DBUS */
diff --git a/fence/fenced/fd.h b/fence/fenced/fd.h
index a5a78bf..21855b2 100644
--- a/fence/fenced/fd.h
+++ b/fence/fenced/fd.h
@@ -286,5 +286,11 @@ void init_logging(void);
void setup_logging(void);
void close_logging(void);

+/* dbus.c */
+
+void fd_dbus_init(void);
+void fd_dbus_exit(void);
+void fd_dbus_send(const char *nodename, int nodeid, int result);
+
#endif /* __FD_DOT_H__ */

diff --git a/fence/fenced/main.c b/fence/fenced/main.c
index e5ab568..b9783fd 100644
--- a/fence/fenced/main.c
+++ b/fence/fenced/main.c
@@ -902,7 +902,7 @@ static void print_usage(void)
printf(" -j <secs> Post-join fencing delay (default %d)
", DEFAULT_POST_JOIN_DELAY);
printf(" -f <secs> Post-fail fencing delay (default %d)
", DEFAULT_POST_FAIL_DELAY);
printf(" -R <secs> Override time (default %d)
", DEFAULT_OVERRIDE_TIME);
-
+ printf(" -q Disable dbus signals
");
printf(" -O <path> Override path (default %s)
", DEFAULT_OVERRIDE_PATH);
printf(" -h Print this help, then exit
");
printf(" -V Print program version information, then exit
");
@@ -912,7 +912,7 @@ static void print_usage(void)
printf("
");
}

-#define OPTION_STRING "Lg:cj:fn:O:hVSse:r:"
+#define OPTION_STRING "Lg:cj:fn:O:hVSse:r:q"

static void read_arguments(int argc, char **argv)
{
@@ -970,6 +970,11 @@ static void read_arguments(int argc, char **argv)
cfgd_override_path = strdup(optarg);
break;

+ case 'q':
+ optd_disable_dbus = 1;
+ cfgd_disable_dbus = 1;
+ break;
+
case 'r':
register_controlled_dir(optarg);
break;
@@ -1042,8 +1047,13 @@ int main(int argc, char **argv)
signal(SIGTERM, sigterm_handler);
set_oom_adj(-16);

+ if (!cfgd_disable_dbus) {
+ dbus_init();
+ }
+
loop();

+ dbus_exit();
unlink(LOCKFILE_NAME);
return 0;
}
diff --git a/fence/fenced/recover.c b/fence/fenced/recover.c
index a7ca047..13014c8 100644
--- a/fence/fenced/recover.c
+++ b/fence/fenced/recover.c
@@ -384,6 +384,10 @@ void fence_victims(struct fd *fd)
log_error("fence %s %s", node->name,
error ? "failed" : "success");

+ if (!cfgd_disable_dbus) {
+ fd_dbus_send(node->name, node->nodeid, error);
+ }
+
skip_log_message:
if (!error) {
node->local_victim_done = 1;
--
1.7.3.4
 
Old 02-03-2011, 06:45 PM
David Teigland
 
Default fenced: send dbus signal when node is fenced

On Thu, Feb 03, 2011 at 01:26:07PM -0600, Ryan O'Hara wrote:
> This patch adds the ability to send a dbus signal when a node is fenced.
> This code is can reestablish a connection with dbus if necessary.

ACK
 

Thread Tools




All times are GMT. The time now is 10:11 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org