From 63198fda240afa2517970c36681bfd143a1e6146 Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Fri, 21 Mar 2025 14:18:15 +0100
Subject: [PATCH 7/8] Refactor: pacemaker-attrd: ability to send a protocol
 message to a single peer

Rename attrd_broadcast_protocol() to attrd_send_protocol().
---
 daemons/attrd/attrd_messages.c  | 24 +++++++++++++++++++-----
 daemons/attrd/pacemaker-attrd.c |  2 +-
 daemons/attrd/pacemaker-attrd.h |  2 +-
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/daemons/attrd/attrd_messages.c b/daemons/attrd/attrd_messages.c
index 8411ce5ef1..5afc3c54c1 100644
--- a/daemons/attrd/attrd_messages.c
+++ b/daemons/attrd/attrd_messages.c
@@ -302,10 +302,10 @@ attrd_handle_request(pcmk__request_t *request)
 
 /*!
     \internal
-    \brief Broadcast private attribute for local node with protocol version
+    \brief Send or broadcast private attribute for local node with protocol version
 */
 void
-attrd_broadcast_protocol(void)
+attrd_send_protocol(const pcmk__node_status_t *peer)
 {
     xmlNode *attrd_op = pcmk__xe_create(NULL, __func__);
 
@@ -319,10 +319,24 @@ attrd_broadcast_protocol(void)
     crm_xml_add(attrd_op, PCMK__XA_ATTR_HOST_ID,
                 attrd_cluster->priv->node_xml_id);
 
-    crm_debug("Broadcasting attrd protocol version %s for node %s",
-              ATTRD_PROTOCOL_VERSION, attrd_cluster->priv->node_name);
+    if (peer == NULL) {
+        crm_debug("Broadcasting attrd protocol version %s for node %s[%" PRIu32
+                  "]",
+                  ATTRD_PROTOCOL_VERSION,
+                  pcmk__s(attrd_cluster->priv->node_name, "unknown"),
+                  attrd_cluster->priv->node_id);
 
-    attrd_send_message(NULL, attrd_op, false); /* ends up at attrd_peer_message() */
+    } else {
+        crm_debug("Sending attrd protocol version %s for node %s[%" PRIu32
+                  "] to node %s[%" PRIu32 "]",
+                  ATTRD_PROTOCOL_VERSION,
+                  pcmk__s(attrd_cluster->priv->node_name, "unknown"),
+                  attrd_cluster->priv->node_id,
+                  pcmk__s(peer->name, "unknown"),
+                  peer->cluster_layer_id);
+    }
+
+    attrd_send_message(peer, attrd_op, false); /* ends up at attrd_peer_message() */
 
     pcmk__xml_free(attrd_op);
 }
diff --git a/daemons/attrd/pacemaker-attrd.c b/daemons/attrd/pacemaker-attrd.c
index 3c31bcd932..ee479c6447 100644
--- a/daemons/attrd/pacemaker-attrd.c
+++ b/daemons/attrd/pacemaker-attrd.c
@@ -184,7 +184,7 @@ main(int argc, char **argv)
      * across all nodes. It also ensures that the writer learns our node name,
      * so it can send our attributes to the CIB.
      */
-    attrd_broadcast_protocol();
+    attrd_send_protocol(NULL);
 
     attrd_init_ipc();
     crm_notice("Pacemaker node attribute manager successfully started and accepting connections");
diff --git a/daemons/attrd/pacemaker-attrd.h b/daemons/attrd/pacemaker-attrd.h
index f818e3b0a8..d9423c8915 100644
--- a/daemons/attrd/pacemaker-attrd.h
+++ b/daemons/attrd/pacemaker-attrd.h
@@ -194,7 +194,7 @@ void attrd_peer_clear_failure(pcmk__request_t *request);
 void attrd_peer_sync_response(const pcmk__node_status_t *peer, bool peer_won,
                               xmlNode *xml);
 
-void attrd_broadcast_protocol(void);
+void attrd_send_protocol(const pcmk__node_status_t *peer);
 xmlNode *attrd_client_peer_remove(pcmk__request_t *request);
 xmlNode *attrd_client_clear_failure(pcmk__request_t *request);
 xmlNode *attrd_client_update(pcmk__request_t *request);
-- 
2.43.0

