File bsc#1217259-0001-Fix-controld-leave-xml-src-attribute-empty-when-no-D.patch of Package pacemaker.36873

From 9243124df1d22107403148ad9c0a573d7a8cec06 Mon Sep 17 00:00:00 2001
From: Aleksei Burlakov <aburlakov@suse.com>
Date: Thu, 17 Oct 2024 11:31:02 +0200
Subject: [PATCH] Fix: controld: leave xml-src attribute empty when no DC
 selected #2902

Right after starting the cluster the DC is offline for short time,
and if you call 'crmadmin --dc_lookup' during this time, it would hang.
This change leaves the xml-src attribute that the crmadmin receives from
the pacemaker-controld empty, so that crmadmin knows the DC was not
selected.
ref: https://projects.clusterlabs.org/T735
---
 daemons/controld/controld_messages.c | 35 +++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 8 deletions(-)

Index: pacemaker-2.1.2+20211124.ada5c3b36/daemons/controld/controld_messages.c
===================================================================
--- pacemaker-2.1.2+20211124.ada5c3b36.orig/daemons/controld/controld_messages.c
+++ pacemaker-2.1.2+20211124.ada5c3b36/daemons/controld/controld_messages.c
@@ -27,11 +27,12 @@ extern void crm_shutdown(int nsig);
 
 static enum crmd_fsa_input handle_message(xmlNode *msg,
                                           enum crmd_fsa_cause cause);
+static xmlNode* create_ping_reply(const xmlNode *msg);
 static void handle_response(xmlNode *stored_msg);
 static enum crmd_fsa_input handle_request(xmlNode *stored_msg,
                                           enum crmd_fsa_cause cause);
 static enum crmd_fsa_input handle_shutdown_request(xmlNode *stored_msg);
-static void send_msg_via_ipc(xmlNode * msg, const char *sys);
+static void send_msg_via_ipc(xmlNode * msg, const char *sys, const char *src);
 
 /* debug only, can wrap all it likes */
 int last_data_id = 0;
@@ -404,10 +405,22 @@ relay_message(xmlNode * msg, gboolean or
         }
     }
 
+    // If is for DC and DC is not yet selected
+    if (is_for_dc && pcmk__str_eq(task, CRM_OP_PING, pcmk__str_casei)
+        && (fsa_our_dc == NULL)) {
+
+        xmlNode *reply = create_ping_reply(msg);
+        sys_to = crm_element_value(reply, F_CRM_SYS_TO);
+        // Explicitly leave src empty. It indicates that dc is "not yet selected"
+        send_msg_via_ipc(reply, sys_to, NULL);
+        free_xml(reply);
+        return TRUE;
+    }
+
     if (is_for_dc || is_for_dcib || is_for_te) {
         if (AM_I_DC && is_for_te) {
             crm_trace("Route message %s locally as transition request", ref);
-            send_msg_via_ipc(msg, sys_to);
+            send_msg_via_ipc(msg, sys_to, fsa_our_uname);
 
         } else if (AM_I_DC) {
             crm_trace("Route message %s locally as DC request", ref);
@@ -440,7 +453,7 @@ relay_message(xmlNode * msg, gboolean or
         crm_trace("Relay message %s locally to %s",
                   ref, (sys_to? sys_to : "unknown client"));
         crm_log_xml_trace(msg, "[IPC relay]");
-        send_msg_via_ipc(msg, sys_to);
+        send_msg_via_ipc(msg, sys_to, fsa_our_uname);
 
     } else {
         crm_node_t *node_to = NULL;
@@ -743,11 +756,12 @@ handle_remote_state(xmlNode *msg)
  *
  * \return Next FSA input
  */
-static enum crmd_fsa_input
-handle_ping(xmlNode *msg)
+static xmlNode*
+create_ping_reply(const xmlNode *msg)
 {
     const char *value = NULL;
     xmlNode *ping = NULL;
+    xmlNode *reply = NULL;
 
     // Build reply
 
@@ -764,12 +778,18 @@ handle_ping(xmlNode *msg)
     // @TODO maybe do some checks to determine meaningful status
     crm_xml_add(ping, XML_PING_ATTR_STATUS, "ok");
 
-    // Send reply
-    msg = create_reply(msg, ping);
+    reply = create_reply(msg, ping);
     free_xml(ping);
-    if (msg) {
-        (void) relay_message(msg, TRUE);
-        free_xml(msg);
+    return reply;
+}
+
+static enum crmd_fsa_input
+handle_ping(const xmlNode *msg)
+{
+    xmlNode *reply = create_ping_reply(msg);
+    if (reply != NULL) {
+        (void) relay_message(reply, TRUE);
+        free_xml(reply);
     }
 
     // Nothing further to do
@@ -1198,12 +1218,12 @@ handle_shutdown_request(xmlNode * stored
 extern gboolean process_te_message(xmlNode * msg, xmlNode * xml_data);
 
 static void
-send_msg_via_ipc(xmlNode * msg, const char *sys)
+send_msg_via_ipc(xmlNode * msg, const char *sys, const char *src)
 {
     pcmk__client_t *client_channel = pcmk__find_client_by_id(sys);
 
     if (crm_element_value(msg, F_CRM_HOST_FROM) == NULL) {
-        crm_xml_add(msg, F_CRM_HOST_FROM, fsa_our_uname);
+        crm_xml_add(msg, F_CRM_HOST_FROM, src);
     }
 
     if (client_channel != NULL) {
openSUSE Build Service is sponsored by