Gitweb: http://git.fedorahosted.org/git/fence.git?p=fence.git;a=commitdiff;h=a8e523a... Commit: a8e523a8ed9df5d54d9c41349a19e1c95252a45e Parent: c36edde1d07fa8ba54cc9e9f78a3b4905b8b4f68 Author: Ryan O'Hara rohara@redhat.com AuthorDate: Wed Feb 2 18:15:32 2011 -0600 Committer: Ryan O'Hara <rohara@cyclone.(none)> CommitterDate: Fri Feb 18 11:03:42 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@redhat.com Reviewed-by: David Teigland teigland@redhat.com --- fence/fenced/config.c | 2 + fence/fenced/config.h | 3 ++ fence/fenced/dbus.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ fence/fenced/fd.h | 6 +++ fence/fenced/main.c | 18 +++++++++- fence/fenced/recover.c | 4 ++ 6 files changed, 118 insertions(+), 2 deletions(-)
diff --git a/fence/fenced/config.c b/fence/fenced/config.c index f8e9846..5b657d0 100644 --- a/fence/fenced/config.c +++ b/fence/fenced/config.c @@ -10,6 +10,7 @@ int ccs_handle;
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_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 102b91a..18cc762 100644 --- a/fence/fenced/config.h +++ b/fence/fenced/config.h @@ -5,6 +5,7 @@
#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_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; @@ -21,6 +23,7 @@ extern int optd_override_path;
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 1182ef5..aead409 100644 --- a/fence/fenced/fd.h +++ b/fence/fenced/fd.h @@ -258,5 +258,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 2a4678f..555fb36 100644 --- a/fence/fenced/main.c +++ b/fence/fenced/main.c @@ -855,7 +855,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"); @@ -865,7 +865,7 @@ static void print_usage(void) printf("\n"); }
-#define OPTION_STRING "Lcj:f:Dn:O:hVSse:r:" +#define OPTION_STRING "Lcj:f:Dn:O:hVSse:r:q:"
static void read_arguments(int argc, char **argv) { @@ -918,6 +918,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; @@ -977,8 +982,17 @@ int main(int argc, char **argv) log_level(LOG_INFO, "fenced %s started", VERSION); signal(SIGTERM, sigterm_handler);
+ if (!cfgd_disable_dbus) { + fd_dbus_init(); + } + loop();
+<<<<<<< HEAD +======= + fd_dbus_exit(); + unlink(LOCKFILE_NAME); +>>>>>>> 4536bfb... fenced: send dbus signal when node is fenced return 0; }
diff --git a/fence/fenced/recover.c b/fence/fenced/recover.c index 1847246..4434256 100644 --- a/fence/fenced/recover.c +++ b/fence/fenced/recover.c @@ -383,6 +383,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;