diff options
Diffstat (limited to 'lib/cluster')
-rw-r--r-- | lib/cluster/Makefile.am | 19 | ||||
-rw-r--r-- | lib/cluster/cluster.c | 33 | ||||
-rw-r--r-- | lib/cluster/cpg.c | 18 | ||||
-rw-r--r-- | lib/cluster/crmcluster_private.h | 6 | ||||
-rw-r--r-- | lib/cluster/membership.c | 85 |
5 files changed, 115 insertions, 46 deletions
diff --git a/lib/cluster/Makefile.am b/lib/cluster/Makefile.am index 9225f29..2ddbffb 100644 --- a/lib/cluster/Makefile.am +++ b/lib/cluster/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2004-2018 the Pacemaker project contributors +# Copyright 2004-2023 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -13,17 +13,20 @@ noinst_HEADERS = crmcluster_private.h ## libraries lib_LTLIBRARIES = libcrmcluster.la -libcrmcluster_la_LDFLAGS = -version-info 30:0:1 +libcrmcluster_la_LDFLAGS = -version-info 31:0:2 libcrmcluster_la_CFLAGS = $(CFLAGS_HARDENED_LIB) libcrmcluster_la_LDFLAGS += $(LDFLAGS_HARDENED_LIB) -libcrmcluster_la_LIBADD = $(top_builddir)/lib/common/libcrmcommon.la $(top_builddir)/lib/fencing/libstonithd.la $(CLUSTERLIBS) +libcrmcluster_la_LIBADD = $(top_builddir)/lib/fencing/libstonithd.la +libcrmcluster_la_LIBADD += $(top_builddir)/lib/common/libcrmcommon.la +libcrmcluster_la_LIBADD += $(CLUSTERLIBS) -libcrmcluster_la_SOURCES = election.c cluster.c membership.c +## Library sources (*must* use += format for bumplibs) +libcrmcluster_la_SOURCES = cluster.c +libcrmcluster_la_SOURCES += election.c +libcrmcluster_la_SOURCES += membership.c if BUILD_CS_SUPPORT -libcrmcluster_la_SOURCES += cpg.c corosync.c +libcrmcluster_la_SOURCES += corosync.c +libcrmcluster_la_SOURCES += cpg.c endif - -clean-generic: - rm -f *.log *.debug *.xml *~ diff --git a/lib/cluster/cluster.c b/lib/cluster/cluster.c index 011e053..f2cd428 100644 --- a/lib/cluster/cluster.c +++ b/lib/cluster/cluster.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the Pacemaker project contributors + * Copyright 2004-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -160,7 +160,7 @@ pcmk_cluster_free(crm_cluster_t *cluster) */ gboolean send_cluster_message(const crm_node_t *node, enum crm_ais_msg_types service, - xmlNode *data, gboolean ordered) + const xmlNode *data, gboolean ordered) { switch (get_cluster_type()) { case pcmk_cluster_corosync: @@ -280,7 +280,7 @@ crm_peer_uname(const char *uuid) return NULL; } - node = pcmk__search_cluster_node_cache((uint32_t) id, NULL); + node = pcmk__search_cluster_node_cache((uint32_t) id, NULL, NULL); if (node != NULL) { crm_info("Setting uuid for node %s[%u] to %s", node->uname, node->id, uuid); @@ -294,19 +294,6 @@ crm_peer_uname(const char *uuid) } /*! - * \brief Add a node's UUID as an XML attribute - * - * \param[in,out] xml XML element to add UUID to - * \param[in] attr XML attribute name to set - * \param[in,out] node Node whose UUID should be used as attribute value - */ -void -set_uuid(xmlNode *xml, const char *attr, crm_node_t *node) -{ - crm_xml_add(xml, attr, crm_peer_uuid(node)); -} - -/*! * \brief Get a log-friendly string equivalent of a cluster type * * \param[in] type Cluster type @@ -403,3 +390,17 @@ is_corosync_cluster(void) { return get_cluster_type() == pcmk_cluster_corosync; } + +// Deprecated functions kept only for backward API compatibility +// LCOV_EXCL_START + +#include <crm/cluster/compat.h> + +void +set_uuid(xmlNode *xml, const char *attr, crm_node_t *node) +{ + crm_xml_add(xml, attr, crm_peer_uuid(node)); +} + +// LCOV_EXCL_STOP +// End deprecated API diff --git a/lib/cluster/cpg.c b/lib/cluster/cpg.c index 2af4a50..d1decc6 100644 --- a/lib/cluster/cpg.c +++ b/lib/cluster/cpg.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2022 the Pacemaker project contributors + * Copyright 2004-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -506,14 +506,14 @@ pcmk_message_common_cs(cpg_handle_t handle, uint32_t nodeid, uint32_t pid, void uncompressed = calloc(1, new_size); rc = BZ2_bzBuffToBuffDecompress(uncompressed, &new_size, msg->data, msg->compressed_size, 1, 0); - if (rc != BZ_OK) { - crm_err("Decompression failed: %s " CRM_XS " bzerror=%d", - bz2_strerror(rc), rc); + rc = pcmk__bzlib2rc(rc); + + if (rc != pcmk_rc_ok) { + crm_err("Decompression failed: %s " CRM_XS " rc=%d", pcmk_rc_str(rc), rc); free(uncompressed); goto badmsg; } - CRM_ASSERT(rc == BZ_OK); CRM_ASSERT(new_size == msg->size); data = uncompressed; @@ -628,7 +628,7 @@ node_left(const char *cpg_group_name, int event_counter, size_t member_list_entries) { crm_node_t *peer = pcmk__search_cluster_node_cache(cpg_peer->nodeid, - NULL); + NULL, NULL); const struct cpg_address **rival = NULL; /* Most CPG-related Pacemaker code assumes that only one process on a node @@ -888,11 +888,11 @@ cluster_connect_cpg(crm_cluster_t *cluster) * * \return TRUE on success, otherwise FALSE */ -gboolean -pcmk__cpg_send_xml(xmlNode *msg, const crm_node_t *node, +bool +pcmk__cpg_send_xml(const xmlNode *msg, const crm_node_t *node, enum crm_ais_msg_types dest) { - gboolean rc = TRUE; + bool rc = true; char *data = NULL; data = dump_xml_unformatted(msg); diff --git a/lib/cluster/crmcluster_private.h b/lib/cluster/crmcluster_private.h index 6933b73..370bca5 100644 --- a/lib/cluster/crmcluster_private.h +++ b/lib/cluster/crmcluster_private.h @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 the Pacemaker project contributors + * Copyright 2020-2023 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -41,7 +41,7 @@ G_GNUC_INTERNAL void pcmk__corosync_disconnect(crm_cluster_t *cluster); G_GNUC_INTERNAL -gboolean pcmk__cpg_send_xml(xmlNode *msg, const crm_node_t *node, - enum crm_ais_msg_types dest); +bool pcmk__cpg_send_xml(const xmlNode *msg, const crm_node_t *node, + enum crm_ais_msg_types dest); #endif // PCMK__CRMCLUSTER_PRIVATE__H diff --git a/lib/cluster/membership.c b/lib/cluster/membership.c index 0c54f19..f856cca 100644 --- a/lib/cluster/membership.c +++ b/lib/cluster/membership.c @@ -157,7 +157,7 @@ crm_remote_peer_cache_remove(const char *node_name) * * \param[in] node_state XML of node state * - * \return CRM_NODE_LOST if XML_NODE_IN_CLUSTER is false in node_state, + * \return CRM_NODE_LOST if PCMK__XA_IN_CCM is false in node_state, * CRM_NODE_MEMBER otherwise * \note Unlike most boolean XML attributes, this one defaults to true, for * backward compatibility with older controllers that don't set it. @@ -167,7 +167,8 @@ remote_state_from_cib(const xmlNode *node_state) { bool status = false; - if (pcmk__xe_get_bool_attr(node_state, XML_NODE_IN_CLUSTER, &status) == pcmk_rc_ok && !status) { + if ((pcmk__xe_get_bool_attr(node_state, PCMK__XA_IN_CCM, + &status) == pcmk_rc_ok) && !status) { return CRM_NODE_LOST; } else { return CRM_NODE_MEMBER; @@ -515,7 +516,7 @@ pcmk__search_node_caches(unsigned int id, const char *uname, uint32_t flags) } if ((node == NULL) && pcmk_is_set(flags, CRM_GET_PEER_CLUSTER)) { - node = pcmk__search_cluster_node_cache(id, uname); + node = pcmk__search_cluster_node_cache(id, uname, NULL); } return node; } @@ -525,12 +526,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,22 +547,40 @@ 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 * * \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 Cluster node cache entry if found, otherwise NULL */ crm_node_t * -pcmk__search_cluster_node_cache(unsigned int id, const char *uname) +pcmk__search_cluster_node_cache(unsigned int id, const char *uname, + const char *uuid) { GHashTableIter iter; crm_node_t *node = NULL; @@ -589,6 +611,16 @@ pcmk__search_cluster_node_cache(unsigned int id, const char *uname) 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 */ @@ -693,12 +725,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; @@ -707,7 +741,7 @@ crm_get_peer(unsigned int id, const char *uname) crm_peer_init(); - node = pcmk__search_cluster_node_cache(id, uname); + 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. */ @@ -721,7 +755,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); + node = pcmk__search_cluster_node_cache(id, uname, uuid); } } @@ -750,7 +784,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); @@ -766,6 +802,21 @@ crm_get_peer(unsigned int id, const char *uname) } /*! + * \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 * @@ -917,6 +968,13 @@ crm_update_peer_proc(const char *source, crm_node_t * node, uint32_t flag, const proc2text(flag), status); } + if (pcmk_is_set(node->processes, crm_get_cluster_proc())) { + node->when_online = time(NULL); + + } else { + node->when_online = 0; + } + /* Call the client callback first, then update the peer state, * in case the node will be reaped */ @@ -1025,6 +1083,13 @@ update_peer_state_iter(const char *source, crm_node_t *node, const char *state, if (state && !pcmk__str_eq(node->state, state, pcmk__str_casei)) { char *last = node->state; + if (is_member) { + node->when_member = time(NULL); + + } else { + node->when_member = 0; + } + node->state = strdup(state); crm_notice("Node %s state is now %s " CRM_XS " nodeid=%u previous=%s source=%s", node->uname, state, |