[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH] 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)\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;
 }
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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]