24 #include <sys/param.h>
25 #include <sys/types.h>
64 static gboolean crm_autoreap = TRUE;
91 if (node_name == NULL) {
110 node->
uuid = strdup(node_name);
111 if (node->
uuid == NULL) {
119 crm_trace(
"added %s to remote cache", node_name);
144 crm_trace(
"removed %s from remote peer cache", node_name);
160 remote_state_from_cib(xmlNode *node_state)
174 struct refresh_data {
187 remote_cache_refresh_helper(xmlNode *result,
void *user_data)
189 struct refresh_data *
data = user_data;
191 const char *state = NULL;
197 if (data->has_state) {
198 state = remote_state_from_cib(result);
222 mark_dirty(gpointer key, gpointer value, gpointer user_data)
228 is_dirty(gpointer key, gpointer value, gpointer user_data)
234 #define XPATH_GUEST_NODE_CONFIG \
235 "//" XML_TAG_CIB "//" XML_CIB_TAG_CONFIGURATION "//" XML_CIB_TAG_RESOURCE \
236 "//" XML_TAG_META_SETS "//" XML_CIB_TAG_NVPAIR \
237 "[@name='" XML_RSC_ATTR_REMOTE_NODE "']"
240 #define XPATH_REMOTE_NODE_CONFIG \
241 "//" XML_TAG_CIB "//" XML_CIB_TAG_CONFIGURATION "//" XML_CIB_TAG_RESOURCE \
242 "[@type='remote'][@provider='pacemaker']"
245 #define XPATH_REMOTE_NODE_STATUS \
246 "//" XML_TAG_CIB "//" XML_CIB_TAG_STATUS "//" XML_CIB_TAG_STATE \
247 "[@" XML_NODE_IS_REMOTE "='true']"
257 struct refresh_data data;
269 data.has_state = TRUE;
271 remote_cache_refresh_helper, &data);
279 data.field =
"value";
280 data.has_state = FALSE;
282 remote_cache_refresh_helper, &data);
284 data.has_state = FALSE;
286 remote_cache_refresh_helper, &data);
309 #if SUPPORT_HEARTBEAT
311 return crm_is_heartbeat_peer_active(node);
319 crm_reap_dead_member(gpointer key, gpointer value, gpointer user_data)
324 if (search == NULL) {
327 }
else if (search->
id && node->
id != search->
id) {
334 crm_info(
"Removing node with name %s and id %u from membership cache",
356 crm_trace(
"Membership cache not initialized, ignoring purge request");
361 search.
uname = name ? strdup(name) : NULL;
362 matches = g_hash_table_foreach_remove(
crm_peer_cache, crm_reap_dead_member, &search);
364 crm_notice(
"Purged %d peers with id=%u%s%s from the membership cache",
366 (search.
uname?
" and/or uname=" :
""),
370 crm_info(
"No peers with id=%u%s%s to purge from the membership cache",
371 search.
id, (search.
uname?
" and/or uname=" :
""),
380 crm_count_peer(gpointer key, gpointer value, gpointer user_data)
382 guint *count = user_data;
402 destroy_crm_node(gpointer data)
476 crm_autoreap = autoreap;
479 static void crm_dump_peer_hash(
int level,
const char *caller)
482 const char *
id = NULL;
483 crm_node_t *node = NULL;
486 while (g_hash_table_iter_next(&iter, (gpointer *) &
id, (gpointer *) &node)) {
487 do_crm_log(level,
"%s: Node %u/%s = %p - %s", caller, node->
id, node->
uname, node,
id);
491 static gboolean crm_hash_find_by_data(gpointer key, gpointer value, gpointer user_data)
493 if(value == user_data) {
502 crm_node_t *node = NULL;
521 crm_node_t *node = NULL;
541 crm_node_t *node = NULL;
542 crm_node_t *by_id = NULL;
543 crm_node_t *by_name = NULL;
551 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
552 if(node->
uname && strcasecmp(node->
uname, uname) == 0) {
562 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
572 if(by_id == by_name) {
574 crm_trace(
"Consistent: %p for %u/%s", by_id,
id, uname);
576 }
else if(by_id == NULL && by_name) {
577 crm_trace(
"Only one: %p for %u/%s", by_name,
id, uname);
579 if(
id && by_name->
id) {
580 crm_dump_peer_hash(LOG_WARNING, __FUNCTION__);
581 crm_crit(
"Node %u and %u share the same name '%s'",
582 id, by_name->
id, uname);
589 }
else if(by_name == NULL && by_id) {
590 crm_trace(
"Only one: %p for %u/%s", by_id,
id, uname);
592 if(uname && by_id->
uname) {
593 crm_dump_peer_hash(LOG_WARNING, __FUNCTION__);
594 crm_crit(
"Node '%s' and '%s' share the same cluster nodeid %u: assuming '%s' is correct",
595 uname, by_id->
uname,
id, uname);
598 }
else if(uname && by_id->
uname) {
600 crm_notice(
"Node '%s' has changed its ID from %u to %u", by_id->
uname, by_name->
id, by_id->
id);
601 g_hash_table_foreach_remove(
crm_peer_cache, crm_hash_find_by_data, by_name);
604 crm_warn(
"Node '%s' and '%s' share the same cluster nodeid: %u %s", by_id->
uname, by_name->
uname,
id, uname);
605 crm_dump_peer_hash(LOG_INFO, __FUNCTION__);
606 crm_abort(__FILE__, __FUNCTION__, __LINE__,
"member weirdness", TRUE, TRUE);
609 }
else if(
id && by_name->
id) {
610 crm_warn(
"Node %u and %u share the same name: '%s'", by_id->
id, by_name->
id, uname);
622 crm_dump_peer_hash(LOG_DEBUG, __FUNCTION__);
624 crm_info(
"Merging %p into %p", by_name, by_id);
625 g_hash_table_foreach_remove(
crm_peer_cache, crm_hash_find_by_data, by_name);
633 crm_remove_conflicting_peer(crm_node_t *node)
637 crm_node_t *existing_node = NULL;
639 if (node->
id == 0 || node->
uname == NULL) {
650 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &existing_node)) {
651 if (existing_node->
id > 0
652 && existing_node->
id != node->
id
653 && existing_node->
uname != NULL
654 && strcasecmp(existing_node->
uname, node->
uname) == 0) {
660 crm_warn(
"Removing cached offline node %u/%s which has conflicting uname with %u",
661 existing_node->
id, existing_node->
uname, node->
id);
663 g_hash_table_iter_remove(&iter);
676 crm_node_t *node = NULL;
677 char *uname_lookup = NULL;
687 if ((node == NULL || node->
uname == NULL) && (uname == NULL)) {
692 uname = uname_lookup;
693 crm_trace(
"Inferred a name of '%s' for node %u", uname,
id);
705 node = calloc(1,
sizeof(crm_node_t));
708 crm_info(
"Created entry %s/%p for node %s/%u (%d total)",
709 uniqueid, node, uname,
id, 1 + g_hash_table_size(
crm_peer_cache));
713 if(
id > 0 && uname && (node->
id == 0 || node->
uname == NULL)) {
714 crm_info(
"Node %u is now known as %s",
id, uname);
717 if(
id > 0 && node->
id == 0) {
721 if (uname && (node->
uname == NULL)) {
725 if(node->
uuid == NULL) {
729 crm_info(
"Node %u has uuid %s",
id, uuid);
732 crm_info(
"Cannot obtain a UUID for node %u/%s",
id, node->
uname);
754 uint32_t children,
const char *uuid,
const char *
uname,
const char *addr,
758 gboolean addr_changed = FALSE;
759 gboolean votes_changed = FALSE;
761 crm_node_t *node = NULL;
768 if (node->
uuid == NULL) {
773 }
else if (uuid != NULL) {
774 node->
uuid = strdup(uuid);
789 #if SUPPORT_HEARTBEAT
801 if (votes > 0 && node->
votes != votes) {
802 votes_changed = TRUE;
810 node->
addr = strdup(addr);
813 if (addr_changed || votes_changed) {
814 crm_info(
"%s: Node %s: id=%u state=%s addr=%s%s votes=%d%s born=" U64T " seen=" U64T
815 " proc=%.32x", source, node->
uname, node->
id, node->
state,
816 node->
addr, addr_changed ?
" (new)" :
"", node->
votes,
838 int i, len = strlen(uname);
840 for (i = 0; i < len; i++) {
841 if (uname[i] >=
'A' && uname[i] <=
'Z') {
842 crm_warn(
"Node names with capitals are discouraged, consider changing '%s'",
849 node->
uname = strdup(uname);
856 crm_remove_conflicting_peer(node);
881 gboolean changed = FALSE;
884 source, peer2text(flag), status);
return NULL);
892 if (status == NULL) {
905 if (flag > 0 && node->
processes != flag) {
918 crm_info(
"%s: Node %s[%u] - all processes are now offline", source, node->
uname,
921 crm_info(
"%s: Node %s[%u] - %s is now %s", source, node->
uname, node->
id,
922 peer2text(flag), status);
941 is_set(node->
processes, crm_get_cluster_proc())?
945 crm_trace(
"%s: Node %s[%u] - %s is unchanged (%s)", source, node->
uname, node->
id,
946 peer2text(flag), status);
955 gboolean changed = FALSE;
957 CRM_CHECK(node != NULL,
crm_err(
"%s: Could not set 'expected' to %s", source, expected);
972 crm_info(
"%s: Node %s[%u] - expected state is now %s (was %s)", source, node->
uname, node->
id,
976 crm_trace(
"%s: Node %s[%u] - expected state is unchanged (%s)", source, node->
uname,
998 crm_update_peer_state_iter(
const char *source, crm_node_t * node,
const char *state,
int membership,
GHashTableIter *iter)
1003 crm_err(
"Could not set state for unknown host to %s"
1004 CRM_XS " source=%s", state, source);
1008 if (membership && is_member) {
1013 char *last = node->
state;
1017 node->
state = strdup(state);
1019 " nodeid=%u previous=%s source=%s", node->
uname, state,
1020 node->
id, (last? last :
"unknown"), source);
1032 crm_notice(
"Purged 1 peer with id=%u and/or uname=%s from the membership cache", node->
id, node->
uname);
1033 g_hash_table_iter_remove(iter);
1043 " nodeid=%u source=%s", node->
uname, state, node->
id, source);
1066 return crm_update_peer_state_iter(source, node, state, membership, NULL);
1079 crm_node_t *node = NULL;
1083 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&node)) {
1091 crm_update_peer_state_iter(__FUNCTION__, node,
CRM_NODE_LOST, membership, &iter);
1094 crm_info(
"State of node %s[%u] is still unknown",
#define CRM_CHECK(expr, failure_action)
void crm_remote_peer_cache_add(const char *node_name)
Add a node to the remote peer cache.
void crm_reap_unseen_nodes(uint64_t membership)
#define crm_notice(fmt, args...)
#define XPATH_REMOTE_NODE_STATUS
GHashTable * crm_peer_cache
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_peer_destroy(void)
gboolean is_heartbeat_cluster(void)
int stonith_api_kick(uint32_t nodeid, const char *uname, int timeout, bool off)
crm_node_t * crm_find_peer(unsigned int id, const char *uname)
int get_corosync_id(int id, const char *uuid)
crm_node_t * crm_find_peer_full(unsigned int id, const char *uname, int flags)
GHashTable * crm_remote_peer_cache
#define clear_bit(word, bit)
unsigned long long crm_peer_seq
char * get_node_name(uint32_t nodeid)
void crm_set_autoreap(gboolean autoreap)
Tell the library whether to automatically reap lost nodes.
void crm_remote_peer_cache_remove(const char *node_name)
gboolean crm_is_corosync_peer_active(const crm_node_t *node)
int crm_remote_peer_cache_size(void)
#define crm_warn(fmt, args...)
#define set_bit(word, bit)
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)
guint reap_crm_member(uint32_t id, const char *name)
Remove all peer cache entries matching a node ID and/or uname.
gboolean crm_is_peer_active(const crm_node_t *node)
guint crm_strcase_hash(gconstpointer v)
#define XPATH_GUEST_NODE_CONFIG
void crm_update_peer_expected(const char *source, crm_node_t *node, const char *expected)
#define crm_trace(fmt, args...)
#define do_crm_log(level, fmt, args...)
Log a message.
const char * crm_element_value(xmlNode *data, const char *name)
int corosync_cmap_has_config(const char *prefix)
void crm_update_peer_uname(crm_node_t *node, const char *uname)
void(* crm_status_callback)(enum crm_status_type, crm_node_t *, const void *)
gboolean crm_str_eq(const char *a, const char *b, gboolean use_case)
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.
const char * name_for_cluster_type(enum cluster_type_e type)
int crm_terminate_member(int nodeid, const char *uname, void *unused)
void crm_remote_peer_cache_refresh(xmlNode *cib)
Repopulate the remote peer cache based on CIB XML.
guint crm_active_peers(void)
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...)
int crm_terminate_member_no_mainloop(int nodeid, const char *uname, int *connection)
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.
crm_node_t * crm_update_peer_proc(const char *source, crm_node_t *node, uint32_t flag, const char *status)
#define XML_NODE_IN_CLUSTER
gboolean crm_is_true(const char *s)
#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)
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
#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)
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.