From 8b4d6075c778f374f7289a910dad03f425e27728 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Mon, 28 Oct 2024 12:40:14 -0500
Subject: [PATCH 07/16] Low: libcrmcluster: use pcmk__cluster_get_xml_id() when
 possible

... rather than using node->xml_id directly, so it gets set whenever
possible. Also, make comparisons case-sensitive.
---
 lib/cluster/cluster.c    |  3 ++-
 lib/cluster/election.c   |  7 ++++---
 lib/cluster/membership.c | 14 +++++++++-----
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/lib/cluster/cluster.c b/lib/cluster/cluster.c
index 87abcfc43e..b560eaae52 100644
--- a/lib/cluster/cluster.c
+++ b/lib/cluster/cluster.c
@@ -337,7 +337,8 @@ pcmk__node_name_from_uuid(const char *uuid)
 
     g_hash_table_iter_init(&iter, pcmk__peer_cache);
     while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
-        if (pcmk__str_eq(node->xml_id, uuid, pcmk__str_casei)) {
+        if (pcmk__str_eq(uuid, pcmk__cluster_get_xml_id(node),
+                         pcmk__str_none)) {
             return node->name;
         }
     }
diff --git a/lib/cluster/election.c b/lib/cluster/election.c
index 60a9156de9..51d4630b18 100644
--- a/lib/cluster/election.c
+++ b/lib/cluster/election.c
@@ -307,7 +307,8 @@ election_vote(pcmk_cluster_t *cluster)
                              NULL, message_type, CRM_OP_VOTE, NULL);
 
     cluster->priv->election->count++;
-    crm_xml_add(vote, PCMK__XA_ELECTION_OWNER, our_node->xml_id);
+    crm_xml_add(vote, PCMK__XA_ELECTION_OWNER,
+                pcmk__cluster_get_xml_id(our_node));
     crm_xml_add_int(vote, PCMK__XA_ELECTION_ID, cluster->priv->election->count);
 
     // Warning: PCMK__XA_ELECTION_AGE_NANO_SEC value is actually microseconds
@@ -546,8 +547,8 @@ election_count_vote(pcmk_cluster_t *cluster, const xmlNode *message,
     our_node = pcmk__get_node(0, cluster->priv->node_name, NULL,
                               pcmk__node_search_cluster_member);
     we_are_owner = (our_node != NULL)
-                   && pcmk__str_eq(our_node->xml_id, vote.election_owner,
-                                   pcmk__str_none);
+                   && pcmk__str_eq(pcmk__cluster_get_xml_id(our_node),
+                                   vote.election_owner, pcmk__str_none);
 
     if (!can_win) {
         reason = "Not eligible";
diff --git a/lib/cluster/membership.c b/lib/cluster/membership.c
index ad55658d78..e033f4e754 100644
--- a/lib/cluster/membership.c
+++ b/lib/cluster/membership.c
@@ -153,7 +153,7 @@ pcmk__cluster_lookup_remote_node(const char *node_name)
 
     /* It's theoretically possible that the node was added to the cluster peer
      * cache before it was known to be a Pacemaker Remote node. Remove that
-     * entry unless it has a node ID, which means the name actually is
+     * entry unless it has an XML ID, which means the name actually is
      * associated with a cluster node. (@TODO return an error in that case?)
      */
     node = pcmk__search_node_caches(0, node_name, NULL,
@@ -713,8 +713,11 @@ search_cluster_member_cache(unsigned int id, const char *uname,
     } else if (uuid != NULL) {
         g_hash_table_iter_init(&iter, pcmk__peer_cache);
         while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
-            if (pcmk__str_eq(node->xml_id, uuid, pcmk__str_casei)) {
-                crm_trace("UUID match: %s", node->xml_id);
+            const char *this_xml_id = pcmk__cluster_get_xml_id(node);
+
+            if (pcmk__str_eq(uuid, this_xml_id, pcmk__str_none)) {
+                crm_trace("Found cluster node cache entry by XML ID %s",
+                          this_xml_id);
                 by_id = node;
                 break;
             }
@@ -1388,7 +1391,8 @@ find_cib_cluster_node(const char *id, const char *uname)
     if (id) {
         g_hash_table_iter_init(&iter, cluster_node_cib_cache);
         while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
-            if (pcmk__str_eq(node->xml_id, id, pcmk__str_casei)) {
+            if (pcmk__str_eq(id, pcmk__cluster_get_xml_id(node),
+                             pcmk__str_none)) {
                 crm_trace("ID match: %s= %p", id, node);
                 by_id = node;
                 break;
@@ -1424,7 +1428,7 @@ find_cib_cluster_node(const char *id, const char *uname)
          * Return by_id. */
 
     } else if ((id != NULL) && (by_name->xml_id != NULL)
-               && pcmk__str_eq(id, by_name->xml_id, pcmk__str_casei)) {
+               && pcmk__str_eq(id, by_name->xml_id, pcmk__str_none)) {
         /* Multiple nodes have the same id in the CIB.
          * Return by_name. */
         node = by_name;
-- 
2.43.0

