File bsc#1198767-0004-Refactor-libcrmcluster-ability-to-search-for-a-node-.patch of Package pacemaker.34782
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_commands.c | 2 +-
daemons/attrd/attrd_commands.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.0.5+20201202.ba59be712/daemons/attrd/attrd_commands.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/daemons/attrd/attrd_commands.c
+++ pacemaker-2.0.5+20201202.ba59be712/daemons/attrd/attrd_commands.c
@@ -199,7 +199,7 @@ attrd_client_peer_remove(const char *cli
crm_element_value_int(xml, PCMK__XA_ATTR_NODE_ID, &nodeid);
if (nodeid > 0) {
- crm_node_t *node = crm_find_peer(nodeid, NULL);
+ crm_node_t *node = crm_find_peer(nodeid, NULL, NULL);
char *host_alloc = NULL;
if (node && node->uname) {
@@ -709,7 +709,7 @@ attrd_lookup_or_create_value(GHashTable
/* If we previously assumed this node was an unseen cluster node,
* remove its entry from the cluster peer cache.
*/
- crm_node_t *dup = crm_find_peer(0, host);
+ crm_node_t *dup = crm_find_peer(0, host, NULL);
if (dup && (dup->uuid == NULL)) {
reap_crm_member(0, host);
Index: pacemaker-2.0.5+20201202.ba59be712/daemons/based/based_messages.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/daemons/based/based_messages.c
+++ pacemaker-2.0.5+20201202.ba59be712/daemons/based/based_messages.c
@@ -269,7 +269,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 = crm_find_peer(0, host);
+ crm_node_t *origin = crm_find_peer(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.0.5+20201202.ba59be712/daemons/controld/controld_messages.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/daemons/controld/controld_messages.c
+++ pacemaker-2.0.5+20201202.ba59be712/daemons/controld/controld_messages.c
@@ -456,7 +456,7 @@ relay_message(xmlNode * msg, gboolean or
#endif
if (host_to) {
- node_to = crm_find_peer(0, host_to);
+ node_to = crm_find_peer(0, host_to, NULL);
if (node_to == NULL) {
crm_warn("Cannot route message %s: Unknown node %s",
ref, host_to);
@@ -980,7 +980,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 = crm_find_peer(0, from);
+ crm_node_t *node = crm_find_peer(0, from, NULL);
crm_update_peer_expected(__func__, node, CRMD_JOINSTATE_DOWN);
if(AM_I_DC == FALSE) {
Index: pacemaker-2.0.5+20201202.ba59be712/include/crm/cluster/internal.h
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/include/crm/cluster/internal.h
+++ pacemaker-2.0.5+20201202.ba59be712/include/crm/cluster/internal.h
@@ -356,7 +356,8 @@ gboolean cluster_connect_quorum(gboolean
gboolean node_name_is_valid(const char *key, const char *name);
crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags);
-crm_node_t * crm_find_peer(unsigned int id, const char *uname);
+crm_node_t * crm_find_peer(unsigned int id, const char *uname,
+ const char *uuid);
void crm_peer_caches_refresh(xmlNode *cib);
crm_node_t *crm_find_known_peer_full(unsigned int id, const char *uname, int flags);
Index: pacemaker-2.0.5+20201202.ba59be712/lib/cluster/cluster.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/lib/cluster/cluster.c
+++ pacemaker-2.0.5+20201202.ba59be712/lib/cluster/cluster.c
@@ -204,7 +204,7 @@ crm_peer_uname(const char *uuid)
uint32_t id = (uint32_t) crm_parse_ll(uuid, NULL);
if (id != 0) {
- node = crm_find_peer(id, NULL);
+ node = crm_find_peer(id, NULL, NULL);
} else {
crm_err("Invalid node id: %s", uuid);
}
Index: pacemaker-2.0.5+20201202.ba59be712/lib/cluster/cpg.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/lib/cluster/cpg.c
+++ pacemaker-2.0.5+20201202.ba59be712/lib/cluster/cpg.c
@@ -425,7 +425,7 @@ pcmk_cpg_membership(cpg_handle_t handle,
cmp_member_list_nodeid);
for (i = 0; i < left_list_entries; i++) {
- crm_node_t *peer = crm_find_peer(left_list[i].nodeid, NULL);
+ crm_node_t *peer = crm_find_peer(left_list[i].nodeid, NULL, NULL);
const struct cpg_address **rival = NULL;
/* in CPG world, NODE:PROCESS-IN-MEMBERSHIP-OF-G is an 1:N relation
Index: pacemaker-2.0.5+20201202.ba59be712/lib/cluster/membership.c
===================================================================
--- pacemaker-2.0.5+20201202.ba59be712.orig/lib/cluster/membership.c
+++ pacemaker-2.0.5+20201202.ba59be712/lib/cluster/membership.c
@@ -494,7 +494,7 @@ crm_find_peer_full(unsigned int id, cons
}
if (node == NULL && (flags & CRM_GET_PEER_CLUSTER)) {
- node = crm_find_peer(id, uname);
+ node = crm_find_peer(id, uname, NULL);
}
return node;
}
@@ -519,7 +519,7 @@ crm_get_peer_full(unsigned int id, const
}
crm_node_t *
-crm_find_peer(unsigned int id, const char *uname)
+crm_find_peer(unsigned int id, const char *uname, const char *uuid)
{
GHashTableIter iter;
crm_node_t *node = NULL;
@@ -550,6 +550,16 @@ crm_find_peer(unsigned int id, const cha
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 */
@@ -660,7 +670,7 @@ crm_get_peer(unsigned int id, const char
crm_peer_init();
- node = crm_find_peer(id, uname);
+ node = crm_find_peer(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. */
@@ -674,7 +684,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 = crm_find_peer(id, uname);
+ node = crm_find_peer(id, uname, NULL);
}
}