File pacemaker#3304-0001-Fix-attrd-write-Pacemaker-Remote-node-attributes-eve.patch of Package pacemaker.34782

From 238cd1697e59e1aef174b494eb89af265d0b08b9 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Mon, 18 Dec 2023 10:08:30 -0600
Subject: [PATCH] Fix: attrd: write Pacemaker Remote node attributes even if
 not in cache

Previously, we required a node to be in one of the node caches in order to
write out its attributes. However for Pacemaker Remote nodes, we only need the
node name to do the write, and we already have that even if it's not cached.
---
 daemons/attrd/attrd_commands.c | 55 +++++++++++++++++++++------------------
 1 file changed, 30 insertions(+), 25 deletions(-)

Index: pacemaker-2.1.2+20211124.ada5c3b36/daemons/attrd/attrd_commands.c
===================================================================
--- pacemaker-2.1.2+20211124.ada5c3b36.orig/daemons/attrd/attrd_commands.c
+++ pacemaker-2.1.2+20211124.ada5c3b36/daemons/attrd/attrd_commands.c
@@ -10,6 +10,7 @@
 #include <crm_internal.h>
 
 #include <sys/types.h>
+#include <inttypes.h>   // PRIu32
 #include <regex.h>
 #include <glib.h>
 
@@ -1293,19 +1294,26 @@ write_attribute(attribute_t *a, bool ign
     /* Iterate over each peer value of this attribute */
     g_hash_table_iter_init(&iter, a->values);
     while (g_hash_table_iter_next(&iter, NULL, (gpointer *) & v)) {
-        crm_node_t *peer = crm_get_peer_full(v->nodeid, v->nodename, CRM_GET_PEER_ANY);
+        const char *uuid = NULL;
 
-        /* If the value's peer info does not correspond to a peer, ignore it */
-        if (peer == NULL) {
-            crm_notice("Cannot update %s[%s]=%s because peer not known",
-                       a->id, v->nodename, v->current);
-            continue;
-        }
+        if (v->is_remote) {
+            /* If this is a Pacemaker Remote node, the node's UUID is the same
+             * as its name, which we already have.
+             */
+            uuid = v->nodename;
 
-        /* If we're just learning the peer's node id, remember it */
-        if (peer->id && (v->nodeid == 0)) {
-            crm_trace("Learned ID %u for node %s", peer->id, v->nodename);
-            v->nodeid = peer->id;
+        } else {
+            // This will create a cluster node cache entry if none exists
+            crm_node_t *peer = pcmk__get_peer_full(v->nodeid, v->nodename, NULL,
+                                                   CRM_GET_PEER_ANY);
+
+            uuid = peer->uuid;
+
+            // Remember peer's node ID if we're just now learning it
+            if ((peer->id != 0) && (v->nodeid == 0)) {
+                crm_trace("Learned ID %u for node %s", peer->id, v->nodename);
+                v->nodeid = peer->id;
+            }
         }
 
         /* If this is a private attribute, no update needs to be sent */
@@ -1314,20 +1322,19 @@ write_attribute(attribute_t *a, bool ign
             continue;
         }
 
-        /* If the peer is found, but its uuid is unknown, defer write */
-        if (peer->uuid == NULL) {
-            a->unknown_peer_uuids = TRUE;
-            crm_notice("Cannot update %s[%s]=%s because peer UUID not known "
-                       "(will retry if learned)",
+        // Defer write if this is a cluster node that's never been seen
+        if (uuid == NULL) {
+            a->unknown_peer_uuids = true;
+            crm_notice("Cannot update %s[%s]='%s' now because node's UUID is "
+                       "unknown (will retry if learned)",
                        a->id, v->nodename, v->current);
             continue;
         }
 
         /* Add this value to status update XML */
-        crm_debug("Updating %s[%s]=%s (peer known as %s, UUID %s, ID %u/%u)",
-                  a->id, v->nodename, v->current,
-                  peer->uname, peer->uuid, peer->id, v->nodeid);
-        build_update_element(xml_top, a, peer->uuid, v->current);
+        crm_debug("Updating %s[%s]=%s (node uuid=%s id=%" PRIu32 ")",
+                  a->id, v->nodename, v->current, uuid, v->nodeid);
+        build_update_element(xml_top, a, uuid, v->current);
         cib_updates++;
 
         /* Preservation of the attribute to transmit alert */
openSUSE Build Service is sponsored by