From 634ce35492459b03f26ecb217033fc033264287c Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Mon, 28 Oct 2024 12:26:12 -0500
Subject: [PATCH 06/16] Refactor: libcrmcluster: rename
 pcmk__cluster_node_uuid()

... to pcmk__cluster_get_xml_id(). It's getting the CIB XML ID; there's
no such thing as a cluster-layer UUID, and it can be used with Pacemaker
Remote nodes as well as cluster nodes.
---
 daemons/attrd/attrd_cib.c              | 2 +-
 daemons/controld/controld_control.c    | 2 +-
 daemons/controld/controld_fencing.c    | 4 ++--
 daemons/controld/controld_join_dc.c    | 2 +-
 daemons/controld/controld_membership.c | 2 +-
 include/crm/cluster/internal.h         | 2 +-
 lib/cluster/cluster.c                  | 9 ++++++---
 lib/cluster/membership.c               | 2 +-
 8 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c
index 808a7bc7e3..ad2bf2052c 100644
--- a/daemons/attrd/attrd_cib.c
+++ b/daemons/attrd/attrd_cib.c
@@ -564,7 +564,7 @@ write_attribute(attribute_t *a, bool ignore_delay)
                                                        NULL,
                                                        pcmk__node_search_any);
 
-            node_xml_id = pcmk__cluster_node_uuid(peer);
+            node_xml_id = pcmk__cluster_get_xml_id(peer);
 
             // Remember peer's node ID if we're just now learning it
             if ((peer->cluster_layer_id != 0) && (v->nodeid == 0)) {
diff --git a/daemons/controld/controld_control.c b/daemons/controld/controld_control.c
index 4b00f894ef..ed4751b8d7 100644
--- a/daemons/controld/controld_control.c
+++ b/daemons/controld/controld_control.c
@@ -69,7 +69,7 @@ do_ha_control(long long action,
 
             free(controld_globals.our_uuid);
             controld_globals.our_uuid =
-                pcmk__str_copy(pcmk__cluster_node_uuid(node));
+                pcmk__str_copy(pcmk__cluster_get_xml_id(node));
 
             if (controld_globals.our_uuid == NULL) {
                 crm_err("Could not obtain local uuid");
diff --git a/daemons/controld/controld_fencing.c b/daemons/controld/controld_fencing.c
index 093f48eb45..7565b6c6c4 100644
--- a/daemons/controld/controld_fencing.c
+++ b/daemons/controld/controld_fencing.c
@@ -384,7 +384,7 @@ execute_stonith_cleanup(void)
         char *target = iter->data;
         pcmk__node_status_t *target_node =
             pcmk__get_node(0, target, NULL, pcmk__node_search_cluster_member);
-        const char *uuid = pcmk__cluster_node_uuid(target_node);
+        const char *uuid = pcmk__cluster_get_xml_id(target_node);
 
         crm_notice("Marking %s, target of a previous stonith action, as clean", target);
         send_stonith_update(NULL, target, uuid);
@@ -598,7 +598,7 @@ handle_fence_notification(stonith_t *st, stonith_event_t *event)
             return;
         }
 
-        uuid = pcmk__cluster_node_uuid(peer);
+        uuid = pcmk__cluster_get_xml_id(peer);
 
         if (AM_I_DC) {
             /* The DC always sends updates */
diff --git a/daemons/controld/controld_join_dc.c b/daemons/controld/controld_join_dc.c
index 7ada26949d..9960966c6b 100644
--- a/daemons/controld/controld_join_dc.c
+++ b/daemons/controld/controld_join_dc.c
@@ -920,7 +920,7 @@ finalize_join_for(gpointer key, gpointer value, gpointer user_data)
      */
     crm_trace("Updating node name and UUID in CIB for %s", join_to);
     tmp1 = pcmk__xe_create(NULL, PCMK_XE_NODE);
-    crm_xml_add(tmp1, PCMK_XA_ID, pcmk__cluster_node_uuid(join_node));
+    crm_xml_add(tmp1, PCMK_XA_ID, pcmk__cluster_get_xml_id(join_node));
     crm_xml_add(tmp1, PCMK_XA_UNAME, join_to);
     fsa_cib_anon_update(PCMK_XE_NODES, tmp1);
     pcmk__xml_free(tmp1);
diff --git a/daemons/controld/controld_membership.c b/daemons/controld/controld_membership.c
index 8075955953..daf0c5fd43 100644
--- a/daemons/controld/controld_membership.c
+++ b/daemons/controld/controld_membership.c
@@ -142,7 +142,7 @@ create_node_state_update(pcmk__node_status_t *node, int flags,
     }
 
     if (crm_xml_add(node_state, PCMK_XA_ID,
-                    pcmk__cluster_node_uuid(node)) == NULL) {
+                    pcmk__cluster_get_xml_id(node)) == NULL) {
         crm_info("Node update for %s cancelled: no ID", node->name);
         pcmk__xml_free(node_state);
         return NULL;
diff --git a/include/crm/cluster/internal.h b/include/crm/cluster/internal.h
index 0afca28950..bc722cb3de 100644
--- a/include/crm/cluster/internal.h
+++ b/include/crm/cluster/internal.h
@@ -260,7 +260,7 @@ char *pcmk__cpg_message_data(cpg_handle_t handle, uint32_t sender_id,
 
 #  endif
 
-const char *pcmk__cluster_node_uuid(pcmk__node_status_t *node);
+const char *pcmk__cluster_get_xml_id(pcmk__node_status_t *node);
 char *pcmk__cluster_node_name(uint32_t nodeid);
 const char *pcmk__cluster_local_node_name(void);
 const char *pcmk__node_name_from_uuid(const char *uuid);
diff --git a/lib/cluster/cluster.c b/lib/cluster/cluster.c
index 3427a409f3..87abcfc43e 100644
--- a/lib/cluster/cluster.c
+++ b/lib/cluster/cluster.c
@@ -34,14 +34,14 @@ CRM_TRACE_INIT_DATA(cluster);
 
 /*!
  * \internal
- * \brief Get a node's cluster-layer UUID, setting it if not already set
+ * \brief Get a node's XML ID in the CIB, setting it if not already set
  *
  * \param[in,out] node  Node to check
  *
- * \return Cluster-layer node UUID of \p node, or \c NULL if unknown
+ * \return CIB XML ID of \p node if known, otherwise \c NULL
  */
 const char *
-pcmk__cluster_node_uuid(pcmk__node_status_t *node)
+pcmk__cluster_get_xml_id(pcmk__node_status_t *node)
 {
     const enum pcmk_cluster_layer cluster_layer = pcmk_get_cluster_layer();
 
@@ -52,6 +52,9 @@ pcmk__cluster_node_uuid(pcmk__node_status_t *node)
         return node->xml_id;
     }
 
+    // xml_id is always set when a Pacemaker Remote node entry is created
+    CRM_CHECK(!pcmk_is_set(node->flags, pcmk__node_status_remote), return NULL);
+
     switch (cluster_layer) {
 #if SUPPORT_COROSYNC
         case pcmk_cluster_layer_corosync:
diff --git a/lib/cluster/membership.c b/lib/cluster/membership.c
index bccbe12aa7..ad55658d78 100644
--- a/lib/cluster/membership.c
+++ b/lib/cluster/membership.c
@@ -1000,7 +1000,7 @@ pcmk__get_node(unsigned int id, const char *uname, const char *xml_id,
     }
 
     if ((xml_id == NULL) && (node->xml_id == NULL)) {
-        xml_id = pcmk__cluster_node_uuid(node);
+        xml_id = pcmk__cluster_get_xml_id(node);
         if (xml_id == NULL) {
             crm_debug("Cannot obtain an XML ID for node %s[%u] at this time",
                       node->name, id);
-- 
2.43.0

