cluster: RHEL6 - fenced: send dbus signal when node is fenced
rohara
rohara at fedoraproject.org
Thu Feb 3 19:54:59 UTC 2011
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=4536bfb712dffa40a0e26910a8977babd902743e
Commit: 4536bfb712dffa40a0e26910a8977babd902743e
Parent: 5cb72e7ab6105f78af396a7e68d19ddaf3d06289
Author: Ryan O'Hara <rohara at redhat.com>
AuthorDate: Wed Feb 2 18:15:32 2011 -0600
Committer: Ryan O'Hara <rohara at redhat.com>
CommitterDate: Thu Feb 3 13:54:47 2011 -0600
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 at redhat.com>
Reviewed-by: David Teigland <teigland at 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(-)
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..5d1e1d5
--- /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");
+ fd_dbus_exit();
+ }
+
+ if (!bus) {
+ fd_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..835dc76 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 (!cfgd_disable_dbus) {
+ fd_dbus_init();
+ }
+
loop();
+ fd_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;
More information about the cluster-commits
mailing list