File bsc#1198767-0004-Refactor-libcrmcluster-ability-to-search-for-a-node-.patch of Package pacemaker.38493

From 1123695ad22197bbadb1f3f2ca507716ff169b09 Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Sat, 27 May 2023 08:40:54 +0200
Subject: [PATCH 4/6] Refactor: libcrmcluster: ability to search for a node
 cache entry by uuid instead of id

... for future use
---
 daemons/attrd/attrd_corosync.c       |  2 +-
 daemons/attrd/attrd_ipc.c            |  3 ++-
 daemons/based/based_messages.c       |  2 +-
 daemons/controld/controld_corosync.c |  3 ++-
 daemons/controld/controld_messages.c |  4 ++--
 include/crm/cluster/internal.h       |  3 ++-
 lib/cluster/cluster.c                |  2 +-
 lib/cluster/cpg.c                    |  2 +-
 lib/cluster/membership.c             | 21 +++++++++++++++++----
 9 files changed, 29 insertions(+), 13 deletions(-)

Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/attrd/attrd_corosync.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/attrd/attrd_corosync.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/attrd/attrd_corosync.c
@@ -141,7 +141,7 @@ cache_remote_node(const char *node_name)
     /* If we previously assumed this node was an unseen cluster node,
      * remove its entry from the cluster peer cache.
      */
-    crm_node_t *dup = pcmk__search_cluster_node_cache(0, node_name);
+    crm_node_t *dup = pcmk__search_cluster_node_cache(0, node_name, NULL);
 
     if (dup && (dup->uuid == NULL)) {
         reap_crm_member(0, node_name);
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/attrd/attrd_ipc.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/attrd/attrd_ipc.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/attrd/attrd_ipc.c
@@ -168,7 +168,8 @@ attrd_client_peer_remove(pcmk__request_t
 
         crm_element_value_int(xml, PCMK__XA_ATTR_NODE_ID, &nodeid);
         if (nodeid > 0) {
-            crm_node_t *node = pcmk__search_cluster_node_cache(nodeid, NULL);
+            crm_node_t *node = pcmk__search_cluster_node_cache(nodeid, NULL,
+                                                               NULL);
             char *host_alloc = NULL;
 
             if (node && node->uname) {
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/based/based_messages.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/based/based_messages.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/based/based_messages.c
@@ -266,7 +266,7 @@ cib_process_upgrade_server(const char *o
 
         if (rc != pcmk_ok) {
             // Notify originating peer so it can notify its local clients
-            crm_node_t *origin = pcmk__search_cluster_node_cache(0, host);
+            crm_node_t *origin = pcmk__search_cluster_node_cache(0, host, NULL);
 
             crm_info("Rejecting upgrade request from %s: %s "
                      CRM_XS " rc=%d peer=%s", host, pcmk_strerror(rc), rc,
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/controld/controld_corosync.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/controld/controld_corosync.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/controld/controld_corosync.c
@@ -122,8 +122,10 @@ cpg_membership_callback(cpg_handle_t han
      * use by the peer callback.
      */
     if (fsa_our_dc != NULL) {
-        crm_node_t *peer = pcmk__search_cluster_node_cache(0, fsa_our_dc);
+        crm_node_t *peer = NULL;
 
+        peer = pcmk__search_cluster_node_cache(0, fsa_our_dc,
+                                               NULL);
         if (peer != NULL) {
             for (int i = 0; i < left_list_entries; ++i) {
                 if (left_list[i].nodeid == peer->id) {
Index: pacemaker-2.1.5+20221208.a3f44794f/daemons/controld/controld_messages.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/daemons/controld/controld_messages.c
+++ pacemaker-2.1.5+20221208.a3f44794f/daemons/controld/controld_messages.c
@@ -455,7 +455,7 @@ relay_message(xmlNode * msg, gboolean or
 #endif
 
         if (host_to) {
-            node_to = pcmk__search_cluster_node_cache(0, host_to);
+            node_to = pcmk__search_cluster_node_cache(0, host_to, NULL);
             if (node_to == NULL) {
                 crm_warn("Cannot route message %s: Unknown node %s",
                          ref, host_to);
@@ -977,7 +977,7 @@ handle_request(xmlNode *stored_msg, enum
 
     if (strcmp(op, CRM_OP_SHUTDOWN_REQ) == 0) {
         const char *from = crm_element_value(stored_msg, F_CRM_HOST_FROM);
-        crm_node_t *node = pcmk__search_cluster_node_cache(0, from);
+        crm_node_t *node = pcmk__search_cluster_node_cache(0, from, NULL);
 
         pcmk__update_peer_expected(__func__, node, CRMD_JOINSTATE_DOWN);
         if(AM_I_DC == FALSE) {
Index: pacemaker-2.1.5+20221208.a3f44794f/include/crm/cluster/internal.h
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/include/crm/cluster/internal.h
+++ pacemaker-2.1.5+20221208.a3f44794f/include/crm/cluster/internal.h
@@ -124,7 +124,8 @@ void pcmk__corosync_quorum_connect(gbool
                                    void (*destroy) (gpointer));
 crm_node_t *pcmk__search_node_caches(unsigned int id, const char *uname,
                                      uint32_t flags);
-crm_node_t *pcmk__search_cluster_node_cache(unsigned int id, const char *uname);
+crm_node_t *pcmk__search_cluster_node_cache(unsigned int id, const char *uname,
+                                            const char *uuid);
 
 void pcmk__refresh_node_caches_from_cib(xmlNode *cib);
 crm_node_t *pcmk__search_known_node_cache(unsigned int id, const char *uname,
Index: pacemaker-2.1.5+20221208.a3f44794f/lib/cluster/cluster.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/lib/cluster/cluster.c
+++ pacemaker-2.1.5+20221208.a3f44794f/lib/cluster/cluster.c
@@ -252,7 +252,7 @@ crm_peer_uname(const char *uuid)
             return NULL;
         }
 
-        node = pcmk__search_cluster_node_cache((uint32_t) id, NULL);
+        node = pcmk__search_cluster_node_cache((uint32_t) id, NULL, NULL);
         if (node != NULL) {
             crm_info("Setting uuid for node %s[%u] to %s",
                      node->uname, node->id, uuid);
Index: pacemaker-2.1.5+20221208.a3f44794f/lib/cluster/cpg.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/lib/cluster/cpg.c
+++ pacemaker-2.1.5+20221208.a3f44794f/lib/cluster/cpg.c
@@ -628,7 +628,7 @@ node_left(const char *cpg_group_name, in
           size_t member_list_entries)
 {
     crm_node_t *peer = pcmk__search_cluster_node_cache(cpg_peer->nodeid,
-                                                       NULL);
+                                                       NULL, NULL);
     const struct cpg_address **rival = NULL;
 
     /* Most CPG-related Pacemaker code assumes that only one process on a node
Index: pacemaker-2.1.5+20221208.a3f44794f/lib/cluster/membership.c
===================================================================
--- pacemaker-2.1.5+20221208.a3f44794f.orig/lib/cluster/membership.c
+++ pacemaker-2.1.5+20221208.a3f44794f/lib/cluster/membership.c
@@ -514,7 +514,7 @@ pcmk__search_node_caches(unsigned int id
     }
 
     if ((node == NULL) && pcmk_is_set(flags, CRM_GET_PEER_CLUSTER)) {
-        node = pcmk__search_cluster_node_cache(id, uname);
+        node = pcmk__search_cluster_node_cache(id, uname, NULL);
     }
     return node;
 }
@@ -553,11 +553,14 @@ crm_get_peer_full(unsigned int id, const
  *
  * \param[in] id     If not 0, cluster node ID to search for
  * \param[in] uname  If not NULL, node name to search for
+ * \param[in] uuid   If not NULL while id is 0, node UUID instead of cluster
+ *                   node ID to search for
  *
  * \return Cluster node cache entry if found, otherwise NULL
  */
 crm_node_t *
-pcmk__search_cluster_node_cache(unsigned int id, const char *uname)
+pcmk__search_cluster_node_cache(unsigned int id, const char *uname,
+                                const char *uuid)
 {
     GHashTableIter iter;
     crm_node_t *node = NULL;
@@ -588,6 +591,16 @@ pcmk__search_cluster_node_cache(unsigned
                 break;
             }
         }
+
+    } else if (uuid != NULL) {
+        g_hash_table_iter_init(&iter, crm_peer_cache);
+        while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
+            if (pcmk__str_eq(node->uuid, uuid, pcmk__str_casei)) {
+                crm_trace("UUID match: %s = %p", node->uuid, node);
+                by_id = node;
+                break;
+            }
+        }
     }
 
     node = by_id; /* Good default */
@@ -706,7 +719,7 @@ crm_get_peer(unsigned int id, const char
 
     crm_peer_init();
 
-    node = pcmk__search_cluster_node_cache(id, uname);
+    node = pcmk__search_cluster_node_cache(id, uname, NULL);
 
     /* if uname wasn't provided, and find_peer did not turn up a uname based on id.
      * we need to do a lookup of the node name using the id in the cluster membership. */
@@ -720,7 +733,7 @@ crm_get_peer(unsigned int id, const char
 
         /* try to turn up the node one more time now that we know the uname. */
         if (node == NULL) {
-            node = pcmk__search_cluster_node_cache(id, uname);
+            node = pcmk__search_cluster_node_cache(id, uname, NULL);
         }
     }
 
openSUSE Build Service is sponsored by