24 #include <sys/param.h>
25 #include <sys/types.h>
35 #define s_if_plural(i) (((i) == 1)? "" : "s")
66 static gboolean crm_autoreap = TRUE;
93 if (node_name == NULL) {
112 node->
uuid = strdup(node_name);
113 if (node->
uuid == NULL) {
121 crm_trace(
"added %s to remote cache", node_name);
146 crm_trace(
"removed %s from remote peer cache", node_name);
162 remote_state_from_cib(xmlNode *node_state)
176 struct refresh_data {
189 remote_cache_refresh_helper(xmlNode *result,
void *user_data)
191 struct refresh_data *
data = user_data;
193 const char *state = NULL;
199 if (data->has_state) {
200 state = remote_state_from_cib(result);
224 mark_dirty(gpointer key, gpointer value, gpointer user_data)
230 is_dirty(gpointer key, gpointer value, gpointer user_data)
236 #define XPATH_GUEST_NODE_CONFIG \
237 "//" XML_TAG_CIB "//" XML_CIB_TAG_CONFIGURATION "//" XML_CIB_TAG_RESOURCE \
238 "//" XML_TAG_META_SETS "//" XML_CIB_TAG_NVPAIR \
239 "[@name='" XML_RSC_ATTR_REMOTE_NODE "']"
242 #define XPATH_REMOTE_NODE_CONFIG \
243 "//" XML_TAG_CIB "//" XML_CIB_TAG_CONFIGURATION "//" XML_CIB_TAG_RESOURCE \
244 "[@type='remote'][@provider='pacemaker']"
247 #define XPATH_REMOTE_NODE_STATUS \
248 "//" XML_TAG_CIB "//" XML_CIB_TAG_STATUS "//" XML_CIB_TAG_STATE \
249 "[@" XML_NODE_IS_REMOTE "='true']"
259 struct refresh_data data;
271 data.has_state = TRUE;
273 remote_cache_refresh_helper, &data);
281 data.field =
"value";
282 data.has_state = FALSE;
284 remote_cache_refresh_helper, &data);
286 data.has_state = FALSE;
288 remote_cache_refresh_helper, &data);
311 #if SUPPORT_HEARTBEAT
313 return crm_is_heartbeat_peer_active(node);
321 crm_reap_dead_member(gpointer key, gpointer value, gpointer user_data)
326 if (search == NULL) {
329 }
else if (search->
id && node->
id != search->
id) {
336 crm_info(
"Removing node with name %s and id %u from membership cache",
358 crm_trace(
"Membership cache not initialized, ignoring purge request");
363 search.
uname = name ? strdup(name) : NULL;
364 matches = g_hash_table_foreach_remove(
crm_peer_cache, crm_reap_dead_member, &search);
366 crm_notice(
"Purged %d peer%s with id=%u%s%s from the membership cache",
368 (search.
uname?
" and/or uname=" :
""),
372 crm_info(
"No peers with id=%u%s%s to purge from the membership cache",
373 search.
id, (search.
uname?
" and/or uname=" :
""),
382 crm_count_peer(gpointer key, gpointer value, gpointer user_data)
384 guint *count = user_data;
404 destroy_crm_node(gpointer data)
478 crm_autoreap = autoreap;
481 static void crm_dump_peer_hash(
int level,
const char *caller)
484 const char *
id = NULL;
485 crm_node_t *node = NULL;
488 while (g_hash_table_iter_next(&iter, (gpointer *) &
id, (gpointer *) &node)) {
489 do_crm_log(level,
"%s: Node %u/%s = %p - %s", caller, node->
id, node->
uname, node,
id);
493 static gboolean crm_hash_find_by_data(gpointer key, gpointer value, gpointer user_data)
495 if(value == user_data) {
504 crm_node_t *node = NULL;
523 crm_node_t *node = NULL;
543 crm_node_t *node = NULL;
544 crm_node_t *by_id = NULL;
545 crm_node_t *by_name = NULL;
553 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
554 if(node->
uname && strcasecmp(node->
uname, uname) == 0) {
564 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
574 if(by_id == by_name) {
576 crm_trace(
"Consistent: %p for %u/%s", by_id,
id, uname);
578 }
else if(by_id == NULL && by_name) {
579 crm_trace(
"Only one: %p for %u/%s", by_name,
id, uname);
581 if(
id && by_name->
id) {
582 crm_dump_peer_hash(LOG_WARNING, __FUNCTION__);
583 crm_crit(
"Node %u and %u share the same name '%s'",
584 id, by_name->
id, uname);
591 }
else if(by_name == NULL && by_id) {
592 crm_trace(
"Only one: %p for %u/%s", by_id,
id, uname);
594 if(uname && by_id->
uname) {
595 crm_dump_peer_hash(LOG_WARNING, __FUNCTION__);
596 crm_crit(
"Node '%s' and '%s' share the same cluster nodeid %u: assuming '%s' is correct",
597 uname, by_id->
uname,
id, uname);
600 }
else if(uname && by_id->
uname) {
602 crm_notice(
"Node '%s' has changed its ID from %u to %u", by_id->
uname, by_name->
id, by_id->
id);
603 g_hash_table_foreach_remove(
crm_peer_cache, crm_hash_find_by_data, by_name);
606 crm_warn(
"Node '%s' and '%s' share the same cluster nodeid: %u %s", by_id->
uname, by_name->
uname,
id, uname);
607 crm_dump_peer_hash(LOG_INFO, __FUNCTION__);
608 crm_abort(__FILE__, __FUNCTION__, __LINE__,
"member weirdness", TRUE, TRUE);
611 }
else if(
id && by_name->
id) {
612 crm_warn(
"Node %u and %u share the same name: '%s'", by_id->
id, by_name->
id, uname);
624 crm_dump_peer_hash(LOG_DEBUG, __FUNCTION__);
626 crm_info(
"Merging %p into %p", by_name, by_id);
627 g_hash_table_foreach_remove(
crm_peer_cache, crm_hash_find_by_data, by_name);
635 crm_remove_conflicting_peer(crm_node_t *node)
639 crm_node_t *existing_node = NULL;
641 if (node->
id == 0 || node->
uname == NULL) {
652 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &existing_node)) {
653 if (existing_node->
id > 0
654 && existing_node->
id != node->
id
655 && existing_node->
uname != NULL
656 && strcasecmp(existing_node->
uname, node->
uname) == 0) {
662 crm_warn(
"Removing cached offline node %u/%s which has conflicting uname with %u",
663 existing_node->
id, existing_node->
uname, node->
id);
665 g_hash_table_iter_remove(&iter);
678 crm_node_t *node = NULL;
679 char *uname_lookup = NULL;
689 if ((node == NULL || node->
uname == NULL) && (uname == NULL)) {
694 uname = uname_lookup;
695 crm_trace(
"Inferred a name of '%s' for node %u", uname,
id);
707 node = calloc(1,
sizeof(crm_node_t));
710 crm_info(
"Created entry %s/%p for node %s/%u (%d total)",
711 uniqueid, node, uname,
id, 1 + g_hash_table_size(
crm_peer_cache));
715 if(
id > 0 && uname && (node->
id == 0 || node->
uname == NULL)) {
716 crm_info(
"Node %u is now known as %s",
id, uname);
719 if(
id > 0 && node->
id == 0) {
723 if (uname && (node->
uname == NULL)) {
727 if(node->
uuid == NULL) {
731 crm_info(
"Node %u has uuid %s",
id, uuid);
734 crm_info(
"Cannot obtain a UUID for node %u/%s",
id, node->
uname);
756 uint32_t children,
const char *uuid,
const char *
uname,
const char *addr,
760 gboolean addr_changed = FALSE;
761 gboolean votes_changed = FALSE;
763 crm_node_t *node = NULL;
770 if (node->
uuid == NULL) {
775 }
else if (uuid != NULL) {
776 node->
uuid = strdup(uuid);
791 #if SUPPORT_HEARTBEAT
803 if (votes > 0 && node->
votes != votes) {
804 votes_changed = TRUE;
812 node->
addr = strdup(addr);
815 if (addr_changed || votes_changed) {
816 crm_info(
"%s: Node %s: id=%u state=%s addr=%s%s votes=%d%s born=" U64T " seen=" U64T
817 " proc=%.32x", source, node->
uname, node->
id, node->
state,
818 node->
addr, addr_changed ?
" (new)" :
"", node->
votes,
841 crm_err(
"Bug: can't update node name without name");
return);
843 crm_err(
"Bug: can't update node name to %s without node", uname);
847 crm_debug(
"Node uname '%s' did not change", uname);
851 for (
const char *c = uname; *c; ++c) {
852 if ((*c >=
'A') && (*c <=
'Z')) {
853 crm_warn(
"Node names with capitals are discouraged, consider changing '%s'",
860 node->
uname = strdup(uname);
869 crm_remove_conflicting_peer(node);
894 gboolean changed = FALSE;
897 source, peer2text(flag), status);
return NULL);
905 if (status == NULL) {
918 if (flag > 0 && node->
processes != flag) {
931 crm_info(
"%s: Node %s[%u] - all processes are now offline", source, node->
uname,
934 crm_info(
"%s: Node %s[%u] - %s is now %s", source, node->
uname, node->
id,
935 peer2text(flag), status);
954 is_set(node->
processes, crm_get_cluster_proc())?
958 crm_trace(
"%s: Node %s[%u] - %s is unchanged (%s)", source, node->
uname, node->
id,
959 peer2text(flag), status);
968 gboolean changed = FALSE;
970 CRM_CHECK(node != NULL,
crm_err(
"%s: Could not set 'expected' to %s", source, expected);
985 crm_info(
"%s: Node %s[%u] - expected state is now %s (was %s)", source, node->
uname, node->
id,
989 crm_trace(
"%s: Node %s[%u] - expected state is unchanged (%s)", source, node->
uname,
1011 crm_update_peer_state_iter(
const char *source, crm_node_t * node,
const char *state,
int membership,
GHashTableIter *iter)
1016 crm_err(
"Could not set state for unknown host to %s"
1017 CRM_XS " source=%s", state, source);
1021 if (membership && is_member) {
1026 char *last = node->
state;
1030 node->
state = strdup(state);
1032 " nodeid=%u previous=%s source=%s", node->
uname, state,
1033 node->
id, (last? last :
"unknown"), source);
1045 crm_notice(
"Purged 1 peer with id=%u and/or uname=%s from the membership cache", node->
id, node->
uname);
1046 g_hash_table_iter_remove(iter);
1056 " nodeid=%u source=%s", node->
uname, state, node->
id, source);
1079 return crm_update_peer_state_iter(source, node, state, membership, NULL);
1092 crm_node_t *node = NULL;
1096 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&node)) {
1104 crm_update_peer_state_iter(__FUNCTION__, node,
CRM_NODE_LOST, membership, &iter);
1107 crm_info(
"State of node %s[%u] is still unknown",
void crm_peer_destroy(void)
#define CRM_CHECK(expr, failure_action)
#define crm_notice(fmt, args...)
#define XPATH_REMOTE_NODE_STATUS
void crm_set_status_callback(void(*dispatch)(enum crm_status_type, crm_node_t *, const void *))
Set a client function that will be called after peer status changes.
gboolean is_openais_cluster(void)
#define crm_crit(fmt, args...)
gboolean safe_str_neq(const char *a, const char *b)
char * crm_generate_uuid(void)
void crm_reap_unseen_nodes(uint64_t ring_id)
gboolean is_heartbeat_cluster(void)
gboolean crm_is_peer_active(const crm_node_t *node)
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
int crm_terminate_member(int nodeid, const char *uname, void *unused)
void crm_set_autoreap(gboolean autoreap)
Tell the library whether to automatically reap lost nodes.
int get_corosync_id(int id, const char *uuid)
GHashTable * crm_remote_peer_cache
void crm_remote_peer_cache_add(const char *node_name)
Add a node to the remote peer cache.
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
guint crm_active_peers(void)
#define clear_bit(word, bit)
char * get_node_name(uint32_t nodeid)
crm_node_t * crm_get_peer_full(unsigned int id, const char *uname, int flags)
crm_node_t * crm_update_peer(const char *source, unsigned int id, uint64_t born, uint64_t seen, int32_t votes, uint32_t children, const char *uuid, const char *uname, const char *addr, const char *state)
gboolean crm_is_corosync_peer_active(const crm_node_t *node)
#define crm_warn(fmt, args...)
#define set_bit(word, bit)
void crm_remote_peer_cache_remove(const char *node_name)
#define crm_debug(fmt, args...)
#define XPATH_GUEST_NODE_CONFIG
#define crm_trace(fmt, args...)
#define do_crm_log(level, fmt, args...)
Log a message.
crm_node_t * crm_update_peer_proc(const char *source, crm_node_t *peer, uint32_t flag, const char *status)
guint crm_strcase_hash(gconstpointer v)
const char * crm_element_value(xmlNode *data, const char *name)
int corosync_cmap_has_config(const char *prefix)
void(* crm_status_callback)(enum crm_status_type, crm_node_t *, const void *)
unsigned long long crm_peer_seq
guint reap_crm_member(uint32_t id, const char *name)
Remove all peer cache entries matching a node ID and/or uname.
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
const char * name_for_cluster_type(enum cluster_type_e type)
void crm_update_peer_expected(const char *source, crm_node_t *node, const char *expected)
crm_node_t * crm_update_peer_state(const char *source, crm_node_t *node, const char *state, int membership)
Update a node's state and membership information.
crm_node_t * crm_remote_peer_get(const char *node_name)
Get a remote node peer cache entry, creating it if necessary.
#define crm_err(fmt, args...)
crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags)
void crm_foreach_xpath_result(xmlNode *xml, const char *xpath, void(*helper)(xmlNode *, void *), void *user_data)
Run a supplied function for each result of an xpath search.
Wrappers for and extensions to libqb IPC.
#define XML_NODE_IN_CLUSTER
gboolean crm_is_true(const char *s)
void crm_update_peer_uname(crm_node_t *node, const char *uname)
#define safe_str_eq(a, b)
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection)
crm_node_t * crm_find_peer(unsigned int id, const char *uname)
void crm_remote_peer_cache_refresh(xmlNode *cib)
Repopulate the remote peer cache based on CIB XML.
GHashTable * crm_peer_cache
#define XPATH_REMOTE_NODE_CONFIG
#define crm_info(fmt, args...)
const char * crm_peer_uuid(crm_node_t *node)
enum cluster_type_e get_cluster_type(void)
int crm_remote_peer_cache_size(void)