Skip to contentSkip to conversation

fenced: send dbus signal when node is fenced

PATCH New Ryan O'Hara 4 participants 6 messages Feb 2, 2011 – Feb 3, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 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
fence/fenced/Makefile +5 -2
index 7455544..d412001 100644
@@ -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
 
fence/fenced/config.c +2 -0
index 37f98f9..0517c2a 100644
@@ -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;
fence/fenced/config.h +3 -0
index f65af0e..d17ed1a 100644
@@ -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;
fence/fenced/dbus.c new file +90 -0

90 lines not on this page · raw message

fence/fenced/fd.h +10 -0
index a5a78bf..4ce18c7 100644
@@ -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__  */
 
fence/fenced/main.c +12 -2
index e5ab568..832413e 100644
@@ -902,7 +902,7 @@ static void print_usage(void)
 	printf("  -j <secs>    Post-join fencing delay (default %d)\n", DEFAULT_POST_JOIN_DELAY);
 	printf("  -f <secs>    Post-fail fencing delay (default %d)\n", DEFAULT_POST_FAIL_DELAY);
 	printf("  -R <secs>    Override time (default %d)\n", DEFAULT_OVERRIDE_TIME);
-
+	printf("  -q           Disable dbus signals\n");
 	printf("  -O <path>    Override path (default %s)\n", DEFAULT_OVERRIDE_PATH);
 	printf("  -h           Print this help, then exit\n");
 	printf("  -V           Print program version information, then exit\n");
@@ -912,7 +912,7 @@ static void print_usage(void)
 	printf("\n");
 }
 
-#define OPTION_STRING	"Lg:cj:f:Dn:O:hVSse:r:"
+#define OPTION_STRING	"Lg:cj:f:Dn: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;
 }
fence/fenced/recover.c +2 -0
index a7ca047..5d7680d 100644
@@ -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;
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 1/1 fenced: send dbus signal when node is fenced

Quoted 2 lines · Ryan O'Hara

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

#2 lore raw

PATCH 1/1 fenced: send dbus signal when node is fenced

Quoted 7 lines · Lon Hohberger
Quoted 2 lines · Ryan O'Hara

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

#3 lore raw

PATCH 1/1 fenced: send dbus signal when node is fenced

In reply to Ryan O'Hara
Quoted 19 lines · Ryan O'Hara
fence/fenced/Makefile +4 -2
index 7455544..d412001 100644
@@ -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)

fence/fenced/Makefile OBJS= config.o \ · line 37

Quoted 10 lines
fence/fenced/Makefile +1 -0
 
 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

#4 lore raw

PATCH 1/1 fenced: send dbus signal when node is fenced

Quoted 42 lines · Fabio M. Di Nitto
Quoted 19 lines · Ryan O'Hara
fence/fenced/Makefile +4 -2
index 7455544..d412001 100644
@@ -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)

fence/fenced/Makefile OBJS= config.o \ · line 37

Quoted 10 lines
fence/fenced/Makefile +1 -0
 
 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
Quoted 6 lines

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

#5 lore raw

PATCH 1/1 fenced: send dbus signal when node is fenced

In reply to Ryan O'Hara
Quoted 1 line

+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.

fence/fenced/dbus.c line 25

Quoted 13 lines
fence/fenced/dbus.c new file +13 -0
+{
+#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.

fence/fenced/fd.h line 28

Quoted 3 lines
fence/fenced/fd.h +3 -0
+#ifdef DBUS
+#include <dbus/dbus.h>
+#endif

could that go in dbus.c?

fence/fenced/main.c int main(int argc, char **argv) · line 1051

Quoted 2 lines
fence/fenced/main.c +2 -0
+	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).