FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 02-02-2011, 11:18 PM
Lon Hohberger
 
Default rgmanager: DBus notifications for service state changes

Clean cherry-pick in to RHEL6 branch

Resolves: rhbz#657756

Signed-off-by: Lon Hohberger <lhh@redhat.com>
---
rgmanager/include/rg_dbus.h | 14 ++++
rgmanager/man/rgmanager.8 | 2 +
rgmanager/src/daemons/Makefile | 7 +-
rgmanager/src/daemons/main.c | 88 ++++++++++++++++++++-
rgmanager/src/daemons/update-dbus.c | 144 +++++++++++++++++++++++++++++++++++
5 files changed, 250 insertions(+), 5 deletions(-)
create mode 100644 rgmanager/include/rg_dbus.h
create mode 100644 rgmanager/src/daemons/update-dbus.c

diff --git a/rgmanager/include/rg_dbus.h b/rgmanager/include/rg_dbus.h
new file mode 100644
index 0000000..6454f29
--- /dev/null
+++ b/rgmanager/include/rg_dbus.h
@@ -0,0 +1,14 @@
+#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);
+
+#endif
+#endif
diff --git a/rgmanager/man/rgmanager.8 b/rgmanager/man/rgmanager.8
index 39b2195..a4e2c73 100644
--- a/rgmanager/man/rgmanager.8
+++ b/rgmanager/man/rgmanager.8
@@ -371,6 +371,8 @@ will leave the virtual machine running.
Run in the foreground (do not fork).
.IP -d
Enable debug-level logging.
+.IP -D
+Disable DBus signals which are normally sent when services change state.
.IP -w
Disable internal process monitoring (for debugging).
.IP -N
diff --git a/rgmanager/src/daemons/Makefile b/rgmanager/src/daemons/Makefile
index 94e0dbb..4dbbe5a 100644
--- a/rgmanager/src/daemons/Makefile
+++ b/rgmanager/src/daemons/Makefile
@@ -29,6 +29,7 @@ OBJS1= fo_domain.o
service_op.o
slang_event.o
event_config.o
+ update-dbus.o
watchdog.o

OBJS2= test-noccs.o
@@ -40,12 +41,13 @@ OBJS2= test-noccs.o
rg_locks-noccs.o
event_config-noccs.o

-CFLAGS += -DSHAREDIR="${sharedir}" -D_GNU_SOURCE
+CFLAGS += -DDBUS -DSHAREDIR="${sharedir}" -D_GNU_SOURCE
CFLAGS += -fPIC
CFLAGS += -I${ccsincdir} -I${cmanincdir} -I${dlmincdir} -I${logtincdir}
CFLAGS += `xml2-config --cflags` -I${slangincdir}
CFLAGS += -I$(S)/../../include
CFLAGS += -I${incdir}
+CFLAGS += `pkg-config --cflags dbus-1`

NOCCS_CFLAGS += -DNO_CCS

@@ -59,6 +61,7 @@ DLM_LDFLAGS += -L${dlmlibdir} -ldlm
XML2_LDFLAGS += `xml2-config --libs`
SLANG_LDFLAGS += -L${slanglibdir} -lslang
EXTRA_LDFLAGS += -lpthread
+DBUS_LDFLAGS += `pkg-config --libs dbus-1`

LDDEPS += ../clulib/libclulib.a

@@ -66,7 +69,7 @@ ${TARGET1}: ${OBJS1} ${LDDEPS}
$(CC) -o $@ $^ $(CCS_LDFLAGS) $(CMAN_LDFLAGS)
$(DLM_LDFLAGS) $(XML2_LDFLAGS)
$(SLANG_LDFLAGS) $(EXTRA_LDFLAGS)
- $(LOGSYS_LDFLAGS) $(LD_FLAGS)
+ $(LOGSYS_LDFLAGS) $(LD_FLAGS) $(DBUS_LDFLAGS)

#
# Our test program links against the local allocator so that
diff --git a/rgmanager/src/daemons/main.c b/rgmanager/src/daemons/main.c
index 4e34246..303e0c0 100644
--- a/rgmanager/src/daemons/main.c
+++ b/rgmanager/src/daemons/main.c
@@ -23,6 +23,7 @@
#include <members.h>
#include <daemon_init.h>
#include <groups.h>
+#include <rg_dbus.h>

#ifdef WRAP_THREADS
void dump_thread_states(FILE *);
@@ -42,7 +43,9 @@ 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)
@@ -935,6 +938,68 @@ 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
", 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
@@ -949,7 +1014,7 @@ main(int argc, char **argv)
pthread_t th;
cman_handle_t clu = NULL;

- while ((rv = getopt(argc, argv, "wfdN")) != EOF) {
+ while ((rv = getopt(argc, argv, "wfdND")) != EOF) {
switch (rv) {
case 'w':
wd = 0;
@@ -963,6 +1028,11 @@ main(int argc, char **argv)
case 'f':
foreground = 1;
break;
+ case 'D':
+#ifdef DBUS
+ state_notify = 0;
+#endif
+ break;
default:
return 1;
break;
@@ -1032,6 +1102,11 @@ main(int argc, char **argv)
configure_rgmanager(-1, debug, &cluster_timeout);
logt_print(LOG_NOTICE, "Resource Group Manager Starting
");

+#ifdef DBUS
+ if (state_notify && rgm_dbus_init() != 0)
+ logt_print(LOG_NOTICE, "Failed to initialize DBus
");
+#endif
+
if (init_resource_groups(0, do_init) != 0) {
logt_print(LOG_CRIT, "#8: Couldn't initialize services
");
goto out_ls;
@@ -1074,7 +1149,11 @@ main(int argc, char **argv)

ds_key_init("rg_lockdown", 32, 10);
#else
- if (vf_init(me.cn_nodeid, port, NULL, NULL, cluster_timeout) != 0) {
+ if (vf_init(me.cn_nodeid, port, NULL,
+#ifdef DBUS /* Ugly */
+ state_notify ? svc_update :
+#endif
+ NULL, cluster_timeout) != 0) {
logt_print(LOG_CRIT, "#11: Couldn't set up VF listen socket
");
goto out_ls;
}
@@ -1106,6 +1185,9 @@ out_ls:
clu_lock_finished(rgmanager_lsname);

out:
+#ifdef DBUS
+ rgm_dbus_release();
+#endif
logt_print(LOG_NOTICE, "Shutdown complete, exiting
");
cman_finish(clu);

diff --git a/rgmanager/src/daemons/update-dbus.c b/rgmanager/src/daemons/update-dbus.c
new file mode 100644
index 0000000..9e3078d
--- /dev/null
+++ b/rgmanager/src/daemons/update-dbus.c
@@ -0,0 +1,144 @@
+/* DBus notifications */
+#include <stdio.h>
+#include <stdint.h>
+#include <resgroup.h>
+#include <poll.h>
+#include <dbus/dbus.h>
+#include <rg_dbus.h>
+#ifdef DBUS
+
+#define DBUS_RGM_NAME "com.redhat.cluster.rgmanager"
+#define DBUS_RGM_IFACE "com.redhat.cluster.rgmanager"
+#define DBUS_RGM_PATH "/com/redhat/cluster/rgmanager"
+
+static DBusConnection *db = NULL;
+static pthread_mutex_t mu = PTHREAD_MUTEX_INITIALIZER;
+static pthread_t th = 0;
+static char _err[512];
+static int err_set = 0;
+
+int
+rgm_dbus_init(void)
+{
+ DBusConnection *dbc = NULL;
+ DBusError err;
+
+ dbus_error_init(&err);
+
+ dbc = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ if (!dbc) {
+ snprintf(_err, sizeof(_err),
+ "dbus_bus_get: %s", err.message);
+ err_set = 1;
+ dbus_error_free(&err);
+ return -1;
+ }
+
+ dbus_connection_set_exit_on_disconnect(dbc, FALSE);
+
+ db = dbc;
+ return 0;
+}
+
+
+int
+rgm_dbus_release(void)
+{
+ pthread_t t;
+
+ if (!db)
+ return 0;
+
+ /* tell thread to exit - not sure how to tell dbus
+ * to wake up, so just have it poll XXX */
+ if (th) {
+ t = th;
+ th = 0;
+ pthread_join(t, NULL);
+ }
+
+ dbus_connection_unref(db);
+ db = NULL;
+
+ return 0;
+}
+
+
+static void *
+_dbus_auto_flush(void *arg)
+{
+ /* DBus connection functions are thread safe */
+ dbus_connection_ref(db);
+
+ while (dbus_connection_read_write(db, 500)) {
+ if (!th)
+ break;
+ }
+
+ dbus_connection_unref(db);
+
+ th = 0;
+ return NULL;
+}
+
+
+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;
+
+ if (err_set) {
+ fprintf(stderr, "%s
", _err);
+ err_set = 0;
+ }
+
+ if (!db) {
+ goto out_free;
+ }
+
+ pthread_mutex_lock(&mu);
+
+ if (dbus_connection_get_is_connected(db) != TRUE) {
+ err_set = 1;
+ snprintf(_err, sizeof(_err), "DBus connection lost");
+ rgm_dbus_release();
+ goto out_unlock;
+ }
+
+ if (!th) {
+ /* start auto-flush thread if needed */
+ pthread_create(&th, NULL, _dbus_auto_flush, NULL);
+ }
+
+ if (!(msg = dbus_message_new_signal(DBUS_RGM_PATH,
+ DBUS_RGM_IFACE,
+ "ServiceStateChange"))) {
+ goto out_unlock;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &svcname,
+ DBUS_TYPE_STRING, &svcstatus,
+ DBUS_TYPE_STRING, &svcflags,
+ DBUS_TYPE_STRING, &svcowner,
+ DBUS_TYPE_STRING, &svclast,
+ DBUS_TYPE_INVALID)) {
+ goto out_unlock;
+ }
+
+ dbus_connection_send(db, msg, NULL);
+ ret = 0;
+
+out_unlock:
+ pthread_mutex_unlock(&mu);
+ if (msg)
+ dbus_message_unref(msg);
+out_free:
+ return ret;
+}
+#endif
--
1.7.2.3
 

Thread Tools




All times are GMT. The time now is 04:02 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org