Blob Blame History Raw
From 29cc1018cb98b1ff864f2aed090cb6b591963275 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Wed, 23 Dec 2015 15:01:48 -0600
Subject: [PATCH 104/105] Feature: lrmd,liblrmd: add lrmd IPC operations for
 requesting and acknowledging shutdown

This adds two new lrmd IPC operations, LRMD_IPC_OP_SHUTDOWN_REQ and
LRMD_IPC_OP_SHUTDOWN_ACK, along with functions to send them.
This will support the ability to stop pacemaker_remote gracefully.

At this point, no code uses these new operations.
---
 include/crm/lrmd.h      |  2 ++
 include/crm_internal.h  |  1 +
 lib/lrmd/proxy_common.c | 14 ++++++++++++++
 lrmd/ipc_proxy.c        | 24 ++++++++++++++++++++++++
 lrmd/lrmd_private.h     |  1 +
 5 files changed, 42 insertions(+)

diff --git a/include/crm/lrmd.h b/include/crm/lrmd.h
index 5c74798..6660fb9 100644
--- a/include/crm/lrmd.h
+++ b/include/crm/lrmd.h
@@ -95,6 +95,8 @@ typedef struct lrmd_key_value_s {
 #define LRMD_IPC_OP_EVENT         "event"
 #define LRMD_IPC_OP_REQUEST       "request"
 #define LRMD_IPC_OP_RESPONSE      "response"
+#define LRMD_IPC_OP_SHUTDOWN_REQ  "shutdown_req"
+#define LRMD_IPC_OP_SHUTDOWN_ACK  "shutdown_ack"
 
 #define F_LRMD_IPC_OP           "lrmd_ipc_op"
 #define F_LRMD_IPC_IPC_SERVER   "lrmd_ipc_server"
diff --git a/include/crm_internal.h b/include/crm_internal.h
index e0bbb06..c5fbcb7 100644
--- a/include/crm_internal.h
+++ b/include/crm_internal.h
@@ -380,6 +380,7 @@ typedef struct remote_proxy_s {
 
 } remote_proxy_t;
 void remote_proxy_notify_destroy(lrmd_t *lrmd, const char *session_id);
+void remote_proxy_ack_shutdown(lrmd_t *lrmd);
 void remote_proxy_relay_event(lrmd_t *lrmd, const char *session_id, xmlNode *msg);
 void remote_proxy_relay_response(lrmd_t *lrmd, const char *session_id, xmlNode *msg, int msg_id);
 void remote_proxy_end_session(const char *session);
diff --git a/lib/lrmd/proxy_common.c b/lib/lrmd/proxy_common.c
index a0f5e62..eb17e4e 100644
--- a/lib/lrmd/proxy_common.c
+++ b/lib/lrmd/proxy_common.c
@@ -45,6 +45,20 @@ remote_proxy_notify_destroy(lrmd_t *lrmd, const char *session_id)
     free_xml(msg);
 }
 
+/*!
+ * \brief Send an acknowledgment of a remote proxy shutdown request.
+ *
+ * \param[in] lrmd  Connection to proxy
+ */
+void
+remote_proxy_ack_shutdown(lrmd_t *lrmd)
+{
+    xmlNode *msg = create_xml_node(NULL, T_LRMD_IPC_PROXY);
+    crm_xml_add(msg, F_LRMD_IPC_OP, LRMD_IPC_OP_SHUTDOWN_ACK);
+    lrmd_internal_proxy_send(lrmd, msg);
+    free_xml(msg);
+}
+
 void
 remote_proxy_relay_event(lrmd_t *lrmd, const char *session_id, xmlNode *msg)
 {
diff --git a/lrmd/ipc_proxy.c b/lrmd/ipc_proxy.c
index 164a9ff..9633a67 100644
--- a/lrmd/ipc_proxy.c
+++ b/lrmd/ipc_proxy.c
@@ -259,6 +259,30 @@ ipc_proxy_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
     return 0;
 }
 
+/*!
+ * \internal
+ * \brief Notify a proxy provider that we wish to shut down
+ *
+ * \return 0 on success, -1 on error
+ */
+int
+ipc_proxy_shutdown_req(crm_client_t *ipc_proxy)
+{
+    xmlNode *msg = create_xml_node(NULL, T_LRMD_IPC_PROXY);
+    int rc;
+
+    crm_xml_add(msg, F_LRMD_IPC_OP, LRMD_IPC_OP_SHUTDOWN_REQ);
+
+    /* We don't really have a session, but crmd needs this attribute
+     * to recognize this as proxy communication.
+     */
+    crm_xml_add(msg, F_LRMD_IPC_SESSION, "0");
+
+    rc = (lrmd_server_send_notify(ipc_proxy, msg) < 0)? -1 : 0;
+    free_xml(msg);
+    return rc;
+}
+
 static int32_t
 ipc_proxy_closed(qb_ipcs_connection_t * c)
 {
diff --git a/lrmd/lrmd_private.h b/lrmd/lrmd_private.h
index 52f79b8..78f14c9 100644
--- a/lrmd/lrmd_private.h
+++ b/lrmd/lrmd_private.h
@@ -104,6 +104,7 @@ void ipc_proxy_add_provider(crm_client_t *client);
 void ipc_proxy_remove_provider(crm_client_t *client);
 void ipc_proxy_forward_client(crm_client_t *client, xmlNode *xml);
 crm_client_t *ipc_proxy_get_provider(void);
+int ipc_proxy_shutdown_req(crm_client_t *ipc_proxy);
 #endif
 
 #endif
-- 
1.8.3.1