commit 54c8cb75f473e448c7a38d3fe953fae0f973e5de
Author: Gao,Yan <ygao@suse.com>
Date:   Wed May 27 16:42:06 2015 +0200

    Fix: dbus: Use operation timeout for dbus reply timeout
    
    The reply timeout of dbus defaults to 25 seconds. That's not sufficient
    in case the system is under high load. This commit uses operation timeout
    for dbus reply timeout instead.

Index: pacemaker/lib/services/dbus.c
===================================================================
--- pacemaker.orig/lib/services/dbus.c
+++ pacemaker/lib/services/dbus.c
@@ -97,7 +97,7 @@ pcmk_dbus_find_error(const char *method,
     return FALSE;
 }
 
-DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, DBusError *error)
+DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, DBusError *error, int timeout)
 {
     const char *method = NULL;
     DBusMessage *reply = NULL;
@@ -106,8 +106,12 @@ DBusMessage *pcmk_dbus_send_recv(DBusMes
     CRM_ASSERT(dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_METHOD_CALL);
     method = dbus_message_get_member (msg);
 
+    if (timeout <= 0) {
+        timeout = DBUS_TIMEOUT_USE_DEFAULT;
+    }
+
     // send message and get a handle for a reply
-    if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout
+    if (!dbus_connection_send_with_reply (connection, msg, &pending, timeout/* -1 is default timeout, aka. DBUS_TIMEOUT_USE_DEFAULT */)) {
         if(error) {
             error->message = "Call to dbus_connection_send_with_reply() failed";
             error->name = "org.clusterlabs.pacemaker.SendFailed";
@@ -143,7 +147,7 @@ DBusMessage *pcmk_dbus_send_recv(DBusMes
 }
 
 bool pcmk_dbus_send(DBusMessage *msg, DBusConnection *connection,
-                    void(*done)(DBusPendingCall *pending, void *user_data), void *user_data)
+                    void(*done)(DBusPendingCall *pending, void *user_data), void *user_data, int timeout)
 {
     DBusError error;
     const char *method = NULL;
@@ -155,8 +159,12 @@ bool pcmk_dbus_send(DBusMessage *msg, DB
     CRM_ASSERT(dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_METHOD_CALL);
     method = dbus_message_get_member (msg);
 
+    if (timeout <= 0) {
+        timeout = DBUS_TIMEOUT_USE_DEFAULT;
+    }
+
     // send message and get a handle for a reply
-    if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout
+    if (!dbus_connection_send_with_reply (connection, msg, &pending, timeout/* -1 is default timeout, aka. DBUS_TIMEOUT_USE_DEFAULT */)) {
         crm_err("Send with reply failed for %s", method);
         return FALSE;
 
@@ -215,7 +223,7 @@ bool pcmk_dbus_type_check(DBusMessage *m
 
 char *
 pcmk_dbus_get_property(
-    DBusConnection *connection, const char *target, const char *obj, const gchar * iface, const char *name)
+    DBusConnection *connection, const char *target, const char *obj, const gchar * iface, const char *name, int timeout)
 {
     DBusMessage *msg;
     DBusMessageIter args;
@@ -242,7 +250,7 @@ pcmk_dbus_get_property(
 
     CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &iface, DBUS_TYPE_INVALID));
 
-    reply = pcmk_dbus_send_recv(msg, connection, &error);
+    reply = pcmk_dbus_send_recv(msg, connection, &error, timeout);
     dbus_message_unref(msg);
 
     if(error.name) {
Index: pacemaker/lib/services/pcmk-dbus.h
===================================================================
--- pacemaker.orig/lib/services/pcmk-dbus.h
+++ pacemaker/lib/services/pcmk-dbus.h
@@ -3,10 +3,10 @@ void pcmk_dbus_connection_setup_with_sel
 void pcmk_dbus_disconnect(DBusConnection *connection);
 
 bool pcmk_dbus_send(DBusMessage *msg, DBusConnection *connection,
-                    void(*done)(DBusPendingCall *pending, void *user_data), void *user_data);
-DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, DBusError *error);
+                    void(*done)(DBusPendingCall *pending, void *user_data), void *user_data, int timeout);
+DBusMessage *pcmk_dbus_send_recv(DBusMessage *msg, DBusConnection *connection, DBusError *error, int timeout);
 bool pcmk_dbus_type_check(DBusMessage *msg, DBusMessageIter *field, int expected, const char *function, int line);
-char *pcmk_dbus_get_property(DBusConnection *connection, const char *target, const char *obj, const gchar * iface, const char *name);
+char *pcmk_dbus_get_property(DBusConnection *connection, const char *target, const char *obj, const gchar * iface, const char *name, int timeout);
 
 bool pcmk_dbus_find_error(const char *method, DBusPendingCall* pending, DBusMessage *reply, DBusError *error);
 
Index: pacemaker/lib/services/systemd.c
===================================================================
--- pacemaker.orig/lib/services/systemd.c
+++ pacemaker/lib/services/systemd.c
@@ -99,14 +99,14 @@ systemd_service_name(const char *name)
 }
 
 static bool
-systemd_daemon_reload(void)
+systemd_daemon_reload(int timeout)
 {
     const char *method = "Reload";
     DBusMessage *reply = NULL;
     DBusMessage *msg = systemd_new_method(BUS_NAME".Manager", method);
 
     CRM_ASSERT(msg != NULL);
-    reply = pcmk_dbus_send_recv(msg, systemd_proxy, NULL);
+    reply = pcmk_dbus_send_recv(msg, systemd_proxy, NULL, timeout);
     dbus_message_unref(msg);
     if(reply) {
         dbus_message_unref(reply);
@@ -115,7 +115,7 @@ systemd_daemon_reload(void)
 }
 
 static gboolean
-systemd_unit_by_name(const gchar * arg_name, gchar ** out_unit)
+systemd_unit_by_name(const gchar * arg_name, gchar ** out_unit, int timeout)
 {
     DBusMessage *msg;
     DBusMessage *reply = NULL;
@@ -148,7 +148,7 @@ systemd_unit_by_name(const gchar * arg_n
         CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID));
 
         dbus_error_init(&error);
-        reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
+        reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error, timeout);
         dbus_message_unref(msg);
 
         if(error.name) {
@@ -172,7 +172,7 @@ systemd_unit_by_name(const gchar * arg_n
         if(strcmp(method, "LoadUnit") != 0) {
             method = "LoadUnit";
             crm_debug("Cannot find %s, reloading the systemd manager configuration", name);
-            systemd_daemon_reload();
+            systemd_daemon_reload(timeout);
             if(reply) {
                 dbus_message_unref(reply);
                 reply = NULL;
@@ -213,7 +213,7 @@ systemd_unit_listall(void)
     msg = systemd_new_method(BUS_NAME".Manager", method);
     CRM_ASSERT(msg != NULL);
 
-    reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
+    reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error, DBUS_TIMEOUT_USE_DEFAULT);
     dbus_message_unref(msg);
 
     if(error.name) {
@@ -269,19 +269,19 @@ systemd_unit_listall(void)
 gboolean
 systemd_unit_exists(const char *name)
 {
-    return systemd_unit_by_name(name, NULL);
+    return systemd_unit_by_name(name, NULL, DBUS_TIMEOUT_USE_DEFAULT);
 }
 
 static char *
-systemd_unit_metadata(const char *name)
+systemd_unit_metadata(const char *name, int timeout)
 {
     char *path = NULL;
     char *meta = NULL;
     char *desc = NULL;
 
-    if (systemd_unit_by_name(name, &path)) {
+    if (systemd_unit_by_name(name, &path, timeout)) {
         CRM_ASSERT(path);
-        desc = pcmk_dbus_get_property(systemd_proxy, BUS_NAME, path, BUS_NAME ".Unit", "Description");
+        desc = pcmk_dbus_get_property(systemd_proxy, BUS_NAME, path, BUS_NAME ".Unit", "Description", timeout);
     } else {
         desc = g_strdup_printf("systemd unit file for %s", name);
     }
@@ -403,12 +403,12 @@ systemd_unit_exec(svc_action_t * op, gbo
               synchronous ? "" : "a", op->action, op->agent, op->rsc);
 
     if (safe_str_eq(op->action, "meta-data")) {
-        op->stdout_data = systemd_unit_metadata(op->agent);
+        op->stdout_data = systemd_unit_metadata(op->agent, op->timeout);
         op->rc = PCMK_OCF_OK;
         goto cleanup;
     }
 
-    pass = systemd_unit_by_name(op->agent, &unit);
+    pass = systemd_unit_by_name(op->agent, &unit, op->timeout);
     if (pass == FALSE) {
         crm_debug("Could not obtain unit named '%s'", op->agent);
 #if 0
@@ -421,7 +421,7 @@ systemd_unit_exec(svc_action_t * op, gbo
     }
 
     if (safe_str_eq(op->action, "monitor") || safe_str_eq(method, "status")) {
-        char *state = pcmk_dbus_get_property(systemd_proxy, BUS_NAME, unit, BUS_NAME ".Unit", "ActiveState");
+        char *state = pcmk_dbus_get_property(systemd_proxy, BUS_NAME, unit, BUS_NAME ".Unit", "ActiveState", op->timeout);
 
         if (g_strcmp0(state, "active") == 0) {
             op->rc = PCMK_OCF_OK;
@@ -457,7 +457,7 @@ systemd_unit_exec(svc_action_t * op, gbo
             fflush(file_strm);
             fclose(file_strm);
         }
-        systemd_daemon_reload();
+        systemd_daemon_reload(op->timeout);
         free(override_file);
         free(override_dir);
 
@@ -467,7 +467,7 @@ systemd_unit_exec(svc_action_t * op, gbo
         method = "StopUnit";
         unlink(override_file);
         free(override_file);
-        systemd_daemon_reload();
+        systemd_daemon_reload(op->timeout);
 
     } else if (g_strcmp0(method, "restart") == 0) {
         method = "RestartUnit";
@@ -488,11 +488,11 @@ systemd_unit_exec(svc_action_t * op, gbo
     if (synchronous == FALSE) {
         free(unit);
         free(name);
-        return pcmk_dbus_send(msg, systemd_proxy, systemd_async_dispatch, op);
+        return pcmk_dbus_send(msg, systemd_proxy, systemd_async_dispatch, op, op->timeout);
     }
 
     dbus_error_init(&error);
-    reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error);
+    reply = pcmk_dbus_send_recv(msg, systemd_proxy, &error, op->timeout);
 
     if(error.name) {
         /* ignore "already started" or "not running" errors */
Index: pacemaker/lib/services/upstart.c
===================================================================
--- pacemaker.orig/lib/services/upstart.c
+++ pacemaker/lib/services/upstart.c
@@ -77,7 +77,7 @@ upstart_cleanup(void)
 }
 
 static gboolean
-upstart_job_by_name(const gchar * arg_name, gchar ** out_unit)
+upstart_job_by_name(const gchar * arg_name, gchar ** out_unit, int timeout)
 {
 /*
   com.ubuntu.Upstart0_6.GetJobByName (in String name, out ObjectPath job)
@@ -97,7 +97,7 @@ upstart_job_by_name(const gchar * arg_na
 
     dbus_error_init(&error);
     CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_STRING, &arg_name, DBUS_TYPE_INVALID));
-    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error);
+    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, timeout);
     dbus_message_unref(msg);
 
     if(error.name) {
@@ -190,7 +190,7 @@ upstart_job_listall(void)
                                        method); // method name
     CRM_ASSERT(msg != NULL);
 
-    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error);
+    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, DBUS_TIMEOUT_USE_DEFAULT);
     dbus_message_unref(msg);
 
     if(error.name) {
@@ -246,11 +246,11 @@ upstart_job_listall(void)
 gboolean
 upstart_job_exists(const char *name)
 {
-    return upstart_job_by_name(name, NULL);
+    return upstart_job_by_name(name, NULL, DBUS_TIMEOUT_USE_DEFAULT);
 }
 
 static char *
-get_first_instance(const gchar * job)
+get_first_instance(const gchar * job, int timeout)
 {
     char *instance = NULL;
     const char *method = "GetAllInstances";
@@ -268,7 +268,7 @@ get_first_instance(const gchar * job)
     CRM_ASSERT(msg != NULL);
 
     dbus_message_append_args(msg, DBUS_TYPE_INVALID);
-    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error);
+    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, timeout);
     dbus_message_unref(msg);
 
     if(error.name) {
@@ -305,17 +305,17 @@ get_first_instance(const gchar * job)
 }
 
 gboolean
-upstart_job_running(const gchar * name)
+upstart_job_running(const gchar * name, int timeout)
 {
     bool running = FALSE;
     char *job = NULL;
 
-    if(upstart_job_by_name(name, &job)) {
-        char *path = get_first_instance(job);
+    if(upstart_job_by_name(name, &job, timeout)) {
+        char *path = get_first_instance(job, timeout);
 
         if (path) {
             char *state = pcmk_dbus_get_property(
-                upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state");
+                upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state", timeout);
 
             crm_info("State of %s: %s", name, state);
             if (state) {
@@ -452,7 +452,7 @@ upstart_job_exec(svc_action_t * op, gboo
         goto cleanup;
     }
 
-    if(!upstart_job_by_name(op->agent, &job)) {
+    if(!upstart_job_by_name(op->agent, &job, op->timeout)) {
         crm_debug("Could not obtain job named '%s' to %s", op->agent, action);
         if (!g_strcmp0(action, "stop")) {
             op->rc = PCMK_OCF_OK;
@@ -465,7 +465,7 @@ upstart_job_exec(svc_action_t * op, gboo
     }
 
     if (safe_str_eq(op->action, "monitor") || safe_str_eq(action, "status")) {
-        if (upstart_job_running(op->agent)) {
+        if (upstart_job_running(op->agent, op->timeout)) {
             op->rc = PCMK_OCF_OK;
         } else {
             op->rc = PCMK_OCF_NOT_RUNNING;
@@ -505,11 +505,11 @@ upstart_job_exec(svc_action_t * op, gboo
 
     if (synchronous == FALSE) {
         free(job);
-        return pcmk_dbus_send(msg, upstart_proxy, upstart_async_dispatch, op);
+        return pcmk_dbus_send(msg, upstart_proxy, upstart_async_dispatch, op, op->timeout);
     }
 
     dbus_error_init(&error);
-    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error);
+    reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, op->timeout);
 
     if(error.name) {
         if(!upstart_mask_error(op, error.name)) {
Index: pacemaker/lib/services/upstart.h
===================================================================
--- pacemaker.orig/lib/services/upstart.h
+++ pacemaker/lib/services/upstart.h
@@ -26,7 +26,7 @@
 G_GNUC_INTERNAL GList *upstart_job_listall(void);
 G_GNUC_INTERNAL int upstart_job_exec(svc_action_t * op, gboolean synchronous);
 G_GNUC_INTERNAL gboolean upstart_job_exists(const gchar * name);
-G_GNUC_INTERNAL gboolean upstart_job_running(const gchar * name);
+G_GNUC_INTERNAL gboolean upstart_job_running(const gchar * name, int timeout);
 G_GNUC_INTERNAL void upstart_cleanup(void);
 
 #endif                          /* _UPSTART_DBUS_H_ */
