File bsc#1198767-0005-Refactor-libcrmcluster-internal-functions-for-gettin.patch of Package pacemaker.29727
From 9938a467e2de5a37b26affcea9ca9cf1344ce887 Mon Sep 17 00:00:00 2001
From: "Gao,Yan" <ygao@suse.com>
Date: Sat, 27 May 2023 09:36:32 +0200
Subject: [PATCH 5/6] Refactor: libcrmcluster: internal functions for getting a
node cache entry by uuid instead of id
... for future use
---
include/crm/cluster/internal.h | 5 ++++
lib/cluster/membership.c | 49 +++++++++++++++++++++++++++++-----
2 files changed, 48 insertions(+), 6 deletions(-)
diff --git a/include/crm/cluster/internal.h b/include/crm/cluster/internal.h
index da0cc9da4..e20ee4c59 100644
--- a/include/crm/cluster/internal.h
+++ b/include/crm/cluster/internal.h
@@ -131,4 +131,9 @@ void pcmk__refresh_node_caches_from_cib(xmlNode *cib);
crm_node_t *pcmk__search_known_node_cache(unsigned int id, const char *uname,
uint32_t flags);
+crm_node_t *pcmk__get_peer(unsigned int id, const char *uname,
+ const char *uuid);
+crm_node_t *pcmk__get_peer_full(unsigned int id, const char *uname,
+ const char *uuid, int flags);
+
#endif
diff --git a/lib/cluster/membership.c b/lib/cluster/membership.c
index d5db518cb..ce612c839 100644
--- a/lib/cluster/membership.c
+++ b/lib/cluster/membership.c
@@ -525,12 +525,15 @@ pcmk__search_node_caches(unsigned int id, const char *uname, uint32_t flags)
*
* \param[in] id If not 0, cluster node ID to search for
* \param[in] uname If not NULL, node name to search for
+ * \param[in] uuid If not NULL while id is 0, node UUID instead of cluster
+ * node ID to search for
* \param[in] flags Bitmask of enum crm_get_peer_flags
*
* \return (Possibly newly created) node cache entry
*/
crm_node_t *
-crm_get_peer_full(unsigned int id, const char *uname, int flags)
+pcmk__get_peer_full(unsigned int id, const char *uname, const char *uuid,
+ int flags)
{
crm_node_t *node = NULL;
@@ -543,11 +546,26 @@ crm_get_peer_full(unsigned int id, const char *uname, int flags)
}
if ((node == NULL) && pcmk_is_set(flags, CRM_GET_PEER_CLUSTER)) {
- node = crm_get_peer(id, uname);
+ node = pcmk__get_peer(id, uname, uuid);
}
return node;
}
+/*!
+ * \brief Get a node cache entry (cluster or Pacemaker Remote)
+ *
+ * \param[in] id If not 0, cluster node ID to search for
+ * \param[in] uname If not NULL, node name to search for
+ * \param[in] flags Bitmask of enum crm_get_peer_flags
+ *
+ * \return (Possibly newly created) node cache entry
+ */
+crm_node_t *
+crm_get_peer_full(unsigned int id, const char *uname, int flags)
+{
+ return pcmk__get_peer_full(id, uname, NULL, flags);
+}
+
/*!
* \internal
* \brief Search cluster node cache
@@ -706,12 +724,14 @@ remove_conflicting_peer(crm_node_t *node)
*
* \param[in] id If not 0, cluster node ID to search for
* \param[in] uname If not NULL, node name to search for
+ * \param[in] uuid If not NULL while id is 0, node UUID instead of cluster
+ * node ID to search for
*
* \return (Possibly newly created) cluster node cache entry
*/
/* coverity[-alloc] Memory is referenced in one or both hashtables */
crm_node_t *
-crm_get_peer(unsigned int id, const char *uname)
+pcmk__get_peer(unsigned int id, const char *uname, const char *uuid)
{
crm_node_t *node = NULL;
char *uname_lookup = NULL;
@@ -720,7 +740,7 @@ crm_get_peer(unsigned int id, const char *uname)
crm_peer_init();
- node = pcmk__search_cluster_node_cache(id, uname, NULL);
+ node = pcmk__search_cluster_node_cache(id, uname, uuid);
/* 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. */
@@ -734,7 +754,7 @@ crm_get_peer(unsigned int id, const char *uname)
/* try to turn up the node one more time now that we know the uname. */
if (node == NULL) {
- node = pcmk__search_cluster_node_cache(id, uname, NULL);
+ node = pcmk__search_cluster_node_cache(id, uname, uuid);
}
}
@@ -763,7 +783,9 @@ crm_get_peer(unsigned int id, const char *uname)
}
if(node->uuid == NULL) {
- const char *uuid = crm_peer_uuid(node);
+ if (uuid == NULL) {
+ uuid = crm_peer_uuid(node);
+ }
if (uuid) {
crm_info("Node %u has uuid %s", id, uuid);
@@ -778,6 +800,21 @@ crm_get_peer(unsigned int id, const char *uname)
return node;
}
+/*!
+ * \brief Get a cluster node cache entry
+ *
+ * \param[in] id If not 0, cluster node ID to search for
+ * \param[in] uname If not NULL, node name to search for
+ *
+ * \return (Possibly newly created) cluster node cache entry
+ */
+/* coverity[-alloc] Memory is referenced in one or both hashtables */
+crm_node_t *
+crm_get_peer(unsigned int id, const char *uname)
+{
+ return pcmk__get_peer(id, uname, NULL);
+}
+
/*!
* \internal
* \brief Update a node's uname
--
2.35.3