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

[Cluster-devel] [PATCH 2/5] rgmanager: Clean up dbus notifications



Clean cherry-pick in to RHEL6 branch

Resolves: rhbz#657756

Signed-off-by: Lon Hohberger <lhh redhat com>
---
 rgmanager/include/rg_dbus.h         |   20 ++++--
 rgmanager/src/daemons/Makefile      |    2 +-
 rgmanager/src/daemons/main.c        |   82 +--------------------------
 rgmanager/src/daemons/update-dbus.c |  105 ++++++++++++++++++++++++++++++++---
 4 files changed, 115 insertions(+), 94 deletions(-)

diff --git a/rgmanager/include/rg_dbus.h b/rgmanager/include/rg_dbus.h
index 6454f29..3ef5ae1 100644
--- a/rgmanager/include/rg_dbus.h
+++ b/rgmanager/include/rg_dbus.h
@@ -1,14 +1,20 @@
-#ifdef DBUS
 #ifndef _RGM_DBUS_H
 #define _RGM_DBUS_H
 
 int rgm_dbus_init(void);
 int rgm_dbus_release(void);
-int rgm_dbus_notify(const char *svcname,
-    		    const char *svcstatus,
-    		    const char *svcflags,
-    		    const char *svcowner,
-    		    const char *svclast);
+extern int rgm_dbus_notify;
 
-#endif
+#ifdef DBUS
+
+#define RGM_DBUS_DEFAULT 1
+#define RGM_DBUS_UPDATE (rgm_dbus_notify?rgm_dbus_update:0)
+int32_t rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size);
+
+#else
+
+#define RGM_DBUS_DEFAULT 0
+#define RGM_DBUS_UPDATE NULL
+
+#endif /* DBUS */
 #endif
diff --git a/rgmanager/src/daemons/Makefile b/rgmanager/src/daemons/Makefile
index 4dbbe5a..9619990 100644
--- a/rgmanager/src/daemons/Makefile
+++ b/rgmanager/src/daemons/Makefile
@@ -41,7 +41,7 @@ OBJS2=	test-noccs.o \
 	rg_locks-noccs.o \
 	event_config-noccs.o
 
-CFLAGS += -DDBUS -DSHAREDIR=\"${sharedir}\" -D_GNU_SOURCE
+CFLAGS += -DSHAREDIR=\"${sharedir}\" -D_GNU_SOURCE
 CFLAGS += -fPIC
 CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir} -I${logtincdir}
 CFLAGS += `xml2-config --cflags` -I${slangincdir}
diff --git a/rgmanager/src/daemons/main.c b/rgmanager/src/daemons/main.c
index 303e0c0..1929072 100644
--- a/rgmanager/src/daemons/main.c
+++ b/rgmanager/src/daemons/main.c
@@ -43,9 +43,6 @@ static int signalled = 0;
 static uint8_t ALIGNED port = RG_PORT;
 static char *rgmanager_lsname = (char *)"rgmanager"; /* XXX default */
 static int status_poll_interval = DEFAULT_CHECK_INTERVAL;
-#ifdef DBUS
-static int state_notify = 1;
-#endif
 
 static void
 segfault(int __attribute__ ((unused)) sig)
@@ -938,68 +935,6 @@ shutdown_thread(void __attribute__ ((unused)) *arg)
 }
 
 
-#ifdef DBUS
-static int32_t
-svc_update(char *key, uint64_t view, void *data, uint32_t size)
-{
-	char flags[64];
-	rg_state_t *st;
-	cluster_member_list_t *m;
-	const char *owner;
-	const char *last;
-	int ret = 0;
-
-	if (!state_notify)
-		goto out_free;
-	if (view == 1)
-		goto out_free;
-	if (size != (sizeof(*st)))
-		goto out_free;
-
-	st = (rg_state_t *)data;
-	swab_rg_state_t(st);
-
-	/* Don't send transitional states */
-	if (st->rs_state == RG_STATE_STARTING ||
-	    st->rs_state == RG_STATE_STOPPING)
-		goto out_free;
-
-	m = member_list();
-	if (!m)
-		goto out_free;
-
-	owner = memb_id_to_name(m, st->rs_owner);
-	last = memb_id_to_name(m, st->rs_last_owner);
-
-	if (!owner)
-		owner = "(none)";
-	if (!last)
-		last = "(none)";
-
-	rg_flags_str(flags, sizeof(flags), st->rs_flags, (char *)" ");
-	if (flags[0] == 0)
-		snprintf(flags, sizeof(flags), "(none)");
-
-	ret = rgm_dbus_notify(st->rs_name,
-			      rg_state_str(st->rs_state),
-			      (char *)flags, owner, last);
-
-	if (ret < 0) {
-		logt_print(LOG_ERR, "Error sending update for %s; "
-			   "notifications disabled\n", key);
-		rgm_dbus_release();
-		state_notify = 0;
-	}
-
-out_free:
-	if (m)
-		free_member_list(m);
-	free(data);
-	return 0;
-}
-#endif
-
-
 #ifdef WRAP_THREADS
 void dump_thread_states(FILE *);
 #endif
@@ -1029,9 +964,7 @@ main(int argc, char **argv)
 			foreground = 1;
 			break;
 		case 'D':
-#ifdef DBUS
-			state_notify = 0;
-#endif
+			rgm_dbus_notify = 0;
 			break;
 		default:
 			return 1;
@@ -1102,10 +1035,8 @@ main(int argc, char **argv)
 	configure_rgmanager(-1, debug, &cluster_timeout);
 	logt_print(LOG_NOTICE, "Resource Group Manager Starting\n");
 
-#ifdef DBUS
-	if (state_notify && rgm_dbus_init() != 0) 
+	if (rgm_dbus_notify && rgm_dbus_init() != 0) 
 		logt_print(LOG_NOTICE, "Failed to initialize DBus\n");
-#endif
 
 	if (init_resource_groups(0, do_init) != 0) {
 		logt_print(LOG_CRIT, "#8: Couldn't initialize services\n");
@@ -1149,11 +1080,8 @@ main(int argc, char **argv)
 
 	ds_key_init("rg_lockdown", 32, 10);
 #else
-	if (vf_init(me.cn_nodeid, port, NULL, 
-#ifdef DBUS /* Ugly */
-		    state_notify ? svc_update :
-#endif
-		    NULL, cluster_timeout) != 0) {
+	if (vf_init(me.cn_nodeid, port, NULL, RGM_DBUS_UPDATE,
+		    cluster_timeout) != 0) {
 		logt_print(LOG_CRIT, "#11: Couldn't set up VF listen socket\n");
 		goto out_ls;
 	}
@@ -1185,9 +1113,7 @@ out_ls:
 	clu_lock_finished(rgmanager_lsname);
 
 out:
-#ifdef DBUS
 	rgm_dbus_release();
-#endif
 	logt_print(LOG_NOTICE, "Shutdown complete, exiting\n");
 	cman_finish(clu);
 	
diff --git a/rgmanager/src/daemons/update-dbus.c b/rgmanager/src/daemons/update-dbus.c
index 9e3078d..a3fb5e7 100644
--- a/rgmanager/src/daemons/update-dbus.c
+++ b/rgmanager/src/daemons/update-dbus.c
@@ -1,11 +1,18 @@
 /* DBus notifications */
+#include <stdint.h>
+#include <rg_dbus.h>
+#include <errno.h>
+
+#ifdef DBUS
+
 #include <stdio.h>
 #include <stdint.h>
 #include <resgroup.h>
 #include <poll.h>
 #include <dbus/dbus.h>
-#include <rg_dbus.h>
-#ifdef DBUS
+#include <liblogthread.h>
+#include <members.h>
+
 
 #define DBUS_RGM_NAME	"com.redhat.cluster.rgmanager"
 #define DBUS_RGM_IFACE	"com.redhat.cluster.rgmanager"
@@ -16,13 +23,22 @@ static pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
 static pthread_t th = 0;
 static char _err[512];
 static int err_set = 0;
+#endif
+
+/* Set this to the desired value prior to calling rgm_dbus_init() */
+int rgm_dbus_notify = RGM_DBUS_DEFAULT;
+
 
 int 
 rgm_dbus_init(void)
+#ifdef DBUS
 {
 	DBusConnection *dbc = NULL;
 	DBusError err;
 
+	if (!rgm_dbus_notify)
+		return 0;
+
 	dbus_error_init(&err);
 
 	dbc = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
@@ -39,10 +55,17 @@ rgm_dbus_init(void)
 	db = dbc;
 	return 0;
 }
+#else
+{
+	errno = ENOSYS;
+	return -1;
+}
+#endif
 
 
 int
 rgm_dbus_release(void)
+#ifdef DBUS
 {
 	pthread_t t;
 
@@ -62,8 +85,14 @@ rgm_dbus_release(void)
 
 	return 0;
 }
+#else
+{
+	return 0;
+}
+#endif
 
 
+#ifdef DBUS
 static void *
 _dbus_auto_flush(void *arg)
 {
@@ -82,12 +111,12 @@ _dbus_auto_flush(void *arg)
 }
 
 
-int
-rgm_dbus_notify(const char *svcname,
-		const char *svcstatus,
-		const char *svcflags,
-		const char *svcowner,
-		const char *svclast)
+static int
+_rgm_dbus_notify(const char *svcname,
+		 const char *svcstatus,
+		 const char *svcflags,
+		 const char *svcowner,
+		 const char *svclast)
 {
 	DBusMessage *msg = NULL;
 	int ret = -1;
@@ -141,4 +170,64 @@ out_unlock:
 out_free:
 	return ret;
 }
+
+
+int32_t
+rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
+{
+	char flags[64];
+	rg_state_t *st;
+	cluster_member_list_t *m = NULL;
+	const char *owner;
+	const char *last;
+	int ret = 0;
+
+	if (!rgm_dbus_notify)
+		goto out_free;
+	if (view == 1)
+		goto out_free;
+	if (size != (sizeof(*st)))
+		goto out_free;
+
+	st = (rg_state_t *)data;
+	swab_rg_state_t(st);
+
+	/* Don't send transitional states */
+	if (st->rs_state == RG_STATE_STARTING ||
+	    st->rs_state == RG_STATE_STOPPING)
+		goto out_free;
+
+	m = member_list();
+	if (!m)
+		goto out_free;
+
+	owner = memb_id_to_name(m, st->rs_owner);
+	last = memb_id_to_name(m, st->rs_last_owner);
+
+	if (!owner)
+		owner = "(none)";
+	if (!last)
+		last = "(none)";
+
+	rg_flags_str(flags, sizeof(flags), st->rs_flags, (char *)" ");
+	if (flags[0] == 0)
+		snprintf(flags, sizeof(flags), "(none)");
+
+	ret = _rgm_dbus_notify(st->rs_name,
+			       rg_state_str(st->rs_state),
+			       (char *)flags, owner, last);
+
+	if (ret < 0) {
+		logt_print(LOG_ERR, "Error sending update for %s; "
+			   "notifications disabled\n", key);
+		rgm_dbus_release();
+		rgm_dbus_notify = 0;
+	}
+
+out_free:
+	if (m)
+		free_member_list(m);
+	free(data);
+	return 0;
+}
 #endif
-- 
1.7.2.3


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