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: Retry dbus if we get disconnected

Clean cherry-pick in to RHEL6 branch

Resolves: rhbz#657756

Signed-off-by: Lon Hohberger <lhh@redhat.com>
---
rgmanager/src/daemons/main.c | 9 ++++-
rgmanager/src/daemons/update-dbus.c | 60 ++++++++++++++++++++++++-----------
2 files changed, 48 insertions(+), 21 deletions(-)

diff --git a/rgmanager/src/daemons/main.c b/rgmanager/src/daemons/main.c
index 1929072..dad379a 100644
--- a/rgmanager/src/daemons/main.c
+++ b/rgmanager/src/daemons/main.c
@@ -684,6 +684,8 @@ event_loop(msgctx_t *localctx, msgctx_t *clusterctx)
dump_internal_state("/var/lib/cluster/rgmanager-dump");
}

+ rgm_dbus_init();
+
while (running && (tv.tv_sec || tv.tv_usec)) {
FD_ZERO(&rfds);
max = -1;
@@ -1035,8 +1037,11 @@ main(int argc, char **argv)
configure_rgmanager(-1, debug, &cluster_timeout);
logt_print(LOG_NOTICE, "Resource Group Manager Starting
");

- if (rgm_dbus_notify && rgm_dbus_init() != 0)
- logt_print(LOG_NOTICE, "Failed to initialize DBus
");
+ if (rgm_dbus_notify && rgm_dbus_init() != 0) {
+ rgm_dbus_notify = 0;
+ logt_print(LOG_NOTICE, "Failed to initialize DBus; "
+ "notifications disabled
");
+ }

if (init_resource_groups(0, do_init) != 0) {
logt_print(LOG_CRIT, "#8: Couldn't initialize services
");
diff --git a/rgmanager/src/daemons/update-dbus.c b/rgmanager/src/daemons/update-dbus.c
index a3fb5e7..c9bbf40 100644
--- a/rgmanager/src/daemons/update-dbus.c
+++ b/rgmanager/src/daemons/update-dbus.c
@@ -21,8 +21,6 @@
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;
#endif

/* Set this to the desired value prior to calling rgm_dbus_init() */
@@ -39,20 +37,29 @@ rgm_dbus_init(void)
if (!rgm_dbus_notify)
return 0;

+ pthread_mutex_lock(&mu);
+ if (db) {
+ pthread_mutex_unlock(&mu);
+ return 0;
+ }
+
dbus_error_init(&err);

- dbc = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
+ dbc = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
if (!dbc) {
- snprintf(_err, sizeof(_err),
- "dbus_bus_get: %s", err.message);
- err_set = 1;
+ logt_print(LOG_ERR,
+ "DBus Failed to initialize: dbus_bus_get: %s
",
+ err.message);
dbus_error_free(&err);
+ pthread_mutex_unlock(&mu);
return -1;
}

dbus_connection_set_exit_on_disconnect(dbc, FALSE);

db = dbc;
+ pthread_mutex_unlock(&mu);
+ logt_print(LOG_DEBUG, "DBus Notifications Initialized
");
return 0;
}
#else
@@ -63,9 +70,9 @@ rgm_dbus_init(void)
#endif


-int
-rgm_dbus_release(void)
#ifdef DBUS
+static int
+_rgm_dbus_release(int err)
{
pthread_t t;

@@ -74,17 +81,39 @@ rgm_dbus_release(void)

/* tell thread to exit - not sure how to tell dbus
* to wake up, so just have it poll XXX */
+
+ /* if the thread left because the dbus connection died,
+ this block is avoided since the thread exits */
if (th) {
t = th;
th = 0;
pthread_join(t, NULL);
}

+ dbus_connection_close(db);
dbus_connection_unref(db);
db = NULL;

+ if (err)
+ logt_print(LOG_ERR, "DBus Connection Lost
");
+ else
+ logt_print(LOG_DEBUG, "DBus Released
");
return 0;
}
+#endif
+
+
+int
+rgm_dbus_release(void)
+#ifdef DBUS
+{
+ int ret;
+
+ pthread_mutex_lock(&mu);
+ ret = _rgm_dbus_release(0);
+ pthread_mutex_unlock(&mu);
+ return ret;
+}
#else
{
return 0;
@@ -98,14 +127,12 @@ _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;
}
@@ -121,11 +148,6 @@ _rgm_dbus_notify(const char *svcname,
DBusMessage *msg = NULL;
int ret = -1;

- if (err_set) {
- fprintf(stderr, "%s
", _err);
- err_set = 0;
- }
-
if (!db) {
goto out_free;
}
@@ -133,9 +155,7 @@ _rgm_dbus_notify(const char *svcname,
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();
+ _rgm_dbus_release(1);
goto out_unlock;
}

@@ -184,6 +204,8 @@ rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)

if (!rgm_dbus_notify)
goto out_free;
+ if (!db)
+ goto out_free;
if (view == 1)
goto out_free;
if (size != (sizeof(*st)))
@@ -209,6 +231,7 @@ rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
if (!last)
last = "(none)";

+ flags[0] = 0;
rg_flags_str(flags, sizeof(flags), st->rs_flags, (char *)" ");
if (flags[0] == 0)
snprintf(flags, sizeof(flags), "(none)");
@@ -221,7 +244,6 @@ rgm_dbus_update(char *key, uint64_t view, void *data, uint32_t size)
logt_print(LOG_ERR, "Error sending update for %s; "
"notifications disabled
", key);
rgm_dbus_release();
- rgm_dbus_notify = 0;
}

out_free:
--
1.7.2.3
 

Thread Tools




All times are GMT. The time now is 05:30 AM.

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