diff options
Diffstat (limited to 'lib/cluster/membership.c')
-rw-r--r-- | lib/cluster/membership.c | 85 |
1 files changed, 75 insertions, 10 deletions
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, |