Blame SOURCES/0101-Refactor-lrmd-make-proxied-IPC-providers-clients-opa.patch

0240e4
From 68e7bb19d69a999443524ba79203979b35f54e83 Mon Sep 17 00:00:00 2001
0240e4
From: Ken Gaillot <kgaillot@redhat.com>
0240e4
Date: Tue, 22 Dec 2015 11:41:56 -0600
0240e4
Subject: [PATCH 101/105] Refactor: lrmd: make proxied IPC providers/clients
0240e4
 opaque
0240e4
0240e4
This removes an unused extern declaration in crmd.h,
0240e4
makes the ipc_providers and ipc_clients tables static to ipc_proxy.c,
0240e4
and adds an ipc_proxy_get_provider() function for future use.
0240e4
---
0240e4
 crmd/crmd.h         |  1 -
0240e4
 lrmd/ipc_proxy.c    | 48 ++++++++++++++++++++++++++++++------------------
0240e4
 lrmd/lrmd_private.h |  1 +
0240e4
 3 files changed, 31 insertions(+), 19 deletions(-)
0240e4
0240e4
diff --git a/crmd/crmd.h b/crmd/crmd.h
0240e4
index 031f414..6039c85 100644
0240e4
--- a/crmd/crmd.h
0240e4
+++ b/crmd/crmd.h
0240e4
@@ -24,7 +24,6 @@
0240e4
 #  define DAEMON_DEBUG DEVEL_DIR"/"SYS_NAME".debug"
0240e4
 
0240e4
 extern GMainLoop *crmd_mainloop;
0240e4
-extern GHashTable *ipc_clients;
0240e4
 extern bool no_quorum_suicide_escalation;
0240e4
 
0240e4
 extern void crmd_metadata(void);
0240e4
diff --git a/lrmd/ipc_proxy.c b/lrmd/ipc_proxy.c
0240e4
index 84fb3ec..d95a396 100644
0240e4
--- a/lrmd/ipc_proxy.c
0240e4
+++ b/lrmd/ipc_proxy.c
0240e4
@@ -42,34 +42,46 @@ static qb_ipcs_service_t *crmd_ipcs = NULL;
0240e4
 static qb_ipcs_service_t *stonith_ipcs = NULL;
0240e4
 
0240e4
 /* ipc providers == crmd clients connecting from cluster nodes */
0240e4
-GHashTable *ipc_providers;
0240e4
+static GHashTable *ipc_providers = NULL;
0240e4
 /* ipc clients == things like cibadmin, crm_resource, connecting locally */
0240e4
-GHashTable *ipc_clients;
0240e4
+static GHashTable *ipc_clients = NULL;
0240e4
+
0240e4
+/*!
0240e4
+ * \internal
0240e4
+ * \brief Get an IPC proxy provider
0240e4
+ *
0240e4
+ * \return Pointer to a provider if one exists, NULL otherwise
0240e4
+ *
0240e4
+ * \note Grab the first provider available; any provider will work, and usually
0240e4
+ *       there will be only one. These are client connections originating from a
0240e4
+ *       cluster node's crmd.
0240e4
+ */
0240e4
+crm_client_t *
0240e4
+ipc_proxy_get_provider()
0240e4
+{
0240e4
+    if (ipc_providers) {
0240e4
+        GHashTableIter iter;
0240e4
+        gpointer key = NULL;
0240e4
+        gpointer value = NULL;
0240e4
+
0240e4
+        g_hash_table_iter_init(&iter, ipc_providers);
0240e4
+        if (g_hash_table_iter_next(&iter, &key, &value)) {
0240e4
+            return (crm_client_t*)value;
0240e4
+        }
0240e4
+    }
0240e4
+    return NULL;
0240e4
+}
0240e4
 
0240e4
 static int32_t
0240e4
 ipc_proxy_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid, const char *ipc_channel)
0240e4
 {
0240e4
-    void *key = NULL;
0240e4
-    void *value = NULL;
0240e4
     crm_client_t *client;
0240e4
-    crm_client_t *ipc_proxy = NULL;
0240e4
-    GHashTableIter iter;
0240e4
+    crm_client_t *ipc_proxy = ipc_proxy_get_provider();
0240e4
     xmlNode *msg;
0240e4
 
0240e4
     crm_trace("Connection %p on channel %s", c, ipc_channel);
0240e4
 
0240e4
-    if (g_hash_table_size(ipc_providers) == 0) {
0240e4
-        crm_err("No ipc providers available for uid %d gid %d", uid, gid);
0240e4
-        return -EREMOTEIO;
0240e4
-    }
0240e4
-
0240e4
-    g_hash_table_iter_init(&iter, ipc_providers);
0240e4
-    if (g_hash_table_iter_next(&iter, (gpointer *) & key, (gpointer *) & value)) {
0240e4
-        /* grab the first provider available, any provider in this
0240e4
-         * table will work. Usually there will only be one. These are
0240e4
-         * lrmd client connections originating for a cluster node's crmd. */
0240e4
-        ipc_proxy = value;
0240e4
-    } else {
0240e4
+    if (ipc_proxy == NULL) {
0240e4
         crm_err("No ipc providers available for uid %d gid %d", uid, gid);
0240e4
         return -EREMOTEIO;
0240e4
     }
0240e4
diff --git a/lrmd/lrmd_private.h b/lrmd/lrmd_private.h
0240e4
index ddb1506..52f79b8 100644
0240e4
--- a/lrmd/lrmd_private.h
0240e4
+++ b/lrmd/lrmd_private.h
0240e4
@@ -103,6 +103,7 @@ void ipc_proxy_cleanup(void);
0240e4
 void ipc_proxy_add_provider(crm_client_t *client);
0240e4
 void ipc_proxy_remove_provider(crm_client_t *client);
0240e4
 void ipc_proxy_forward_client(crm_client_t *client, xmlNode *xml);
0240e4
+crm_client_t *ipc_proxy_get_provider(void);
0240e4
 #endif
0240e4
 
0240e4
 #endif
0240e4
-- 
0240e4
1.8.3.1
0240e4