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;
267 data.has_state = TRUE;
269 remote_cache_refresh_helper, &data);
277 data.field =
"value";
278 data.has_state = FALSE;
280 remote_cache_refresh_helper, &data);
282 data.has_state = FALSE;
284 remote_cache_refresh_helper, &data);
307 #if SUPPORT_HEARTBEAT
309 return crm_is_heartbeat_peer_active(node);
317 crm_reap_dead_member(gpointer key, gpointer value, gpointer user_data)
322 if (search == NULL) {
325 }
else if (search->
id && node->
id != search->
id) {
332 crm_info(
"Removing node with name %s and id %u from membership cache",
354 crm_trace(
"Membership cache not initialized, ignoring purge request");
359 search.
uname = name ? strdup(name) : NULL;
360 matches = g_hash_table_foreach_remove(
crm_peer_cache, crm_reap_dead_member, &search);
362 crm_notice(
"Purged %d peers with id=%u%s%s from the membership cache",
364 (search.
uname?
" and/or uname=" :
""),
368 crm_info(
"No peers with id=%u%s%s to purge from the membership cache",
369 search.
id, (search.
uname?
" and/or uname=" :
""),
378 crm_count_peer(gpointer key, gpointer value, gpointer user_data)
380 guint *count = user_data;
400 destroy_crm_node(gpointer data)
474 crm_autoreap = autoreap;
477 static void crm_dump_peer_hash(
int level,
const char *caller)
480 const char *
id = NULL;
481 crm_node_t *node = NULL;
484 while (g_hash_table_iter_next(&iter, (gpointer *) &
id, (gpointer *) &node)) {
485 do_crm_log(level,
"%s: Node %u/%s = %p - %s", caller, node->
id, node->
uname, node,
id);
489 static gboolean crm_hash_find_by_data(gpointer key, gpointer value, gpointer user_data)
491 if(value == user_data) {
500 crm_node_t *node = NULL;
519 crm_node_t *node = NULL;
539 crm_node_t *node = NULL;
540 crm_node_t *by_id = NULL;
541 crm_node_t *by_name = NULL;
549 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
550 if(node->
uname && strcasecmp(node->
uname, uname) == 0) {
560 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
570 if(by_id == by_name) {
572 crm_trace(
"Consistent: %p for %u/%s", by_id,
id, uname);
574 }
else if(by_id == NULL && by_name) {
575 crm_trace(
"Only one: %p for %u/%s", by_name,
id, uname);
577 if(
id && by_name->
id) {
578 crm_dump_peer_hash(LOG_WARNING, __FUNCTION__);
579 crm_crit(
"Node %u and %u share the same name '%s'",
580 id, by_name->
id, uname);
587 }
else if(by_name == NULL && by_id) {
588 crm_trace(
"Only one: %p for %u/%s", by_id,
id, uname);
590 if(uname && by_id->
uname) {
591 crm_dump_peer_hash(LOG_WARNING, __FUNCTION__);
592 crm_crit(
"Node '%s' and '%s' share the same cluster nodeid %u: assuming '%s' is correct",
593 uname, by_id->
uname,
id, uname);
596 }
else if(uname && by_id->
uname) {
598 crm_notice(
"Node '%s' has changed its ID from %u to %u", by_id->
uname, by_name->
id, by_id->
id);
599 g_hash_table_foreach_remove(
crm_peer_cache, crm_hash_find_by_data, by_name);
602 crm_warn(
"Node '%s' and '%s' share the same cluster nodeid: %u %s", by_id->
uname, by_name->
uname,
id, uname);
603 crm_dump_peer_hash(LOG_INFO, __FUNCTION__);
604 crm_abort(__FILE__, __FUNCTION__, __LINE__,
"member weirdness", TRUE, TRUE);
607 }
else if(
id && by_name->
id) {
608 crm_warn(
"Node %u and %u share the same name: '%s'", by_id->
id, by_name->
id, uname);
620 crm_dump_peer_hash(LOG_DEBUG, __FUNCTION__);
622 crm_info(
"Merging %p into %p", by_name, by_id);
623 g_hash_table_foreach_remove(
crm_peer_cache, crm_hash_find_by_data, by_name);
631 crm_remove_conflicting_peer(crm_node_t *node)
635 crm_node_t *existing_node = NULL;
637 if (node->
id == 0 || node->
uname == NULL) {
648 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &existing_node)) {
649 if (existing_node->
id > 0
650 && existing_node->
id != node->
id
651 && existing_node->
uname != NULL
652 && strcasecmp(existing_node->
uname, node->
uname) == 0) {
658 crm_warn(
"Removing cached offline node %u/%s which has conflicting uname with %u",
659 existing_node->
id, existing_node->
uname, node->
id);
661 g_hash_table_iter_remove(&iter);
674 crm_node_t *node = NULL;
675 char *uname_lookup = NULL;
685 if ((node == NULL || node->
uname == NULL) && (uname == NULL)) {
690 uname = uname_lookup;
691 crm_trace(
"Inferred a name of '%s' for node %u", uname,
id);
703 node = calloc(1,
sizeof(crm_node_t));
706 crm_info(
"Created entry %s/%p for node %s/%u (%d total)",
707 uniqueid, node, uname,
id, 1 + g_hash_table_size(
crm_peer_cache));
711 if(
id > 0 && uname && (node->
id == 0 || node->
uname == NULL)) {
712 crm_info(
"Node %u is now known as %s",
id, uname);
715 if(
id > 0 && node->
id == 0) {
719 if (uname && (node->
uname == NULL)) {
723 if(node->
uuid == NULL) {
727 crm_info(
"Node %u has uuid %s",
id, uuid);
730 crm_info(
"Cannot obtain a UUID for node %u/%s",
id, node->
uname);
752 uint32_t children,
const char *uuid,
const char *
uname,
const char *addr,
756 gboolean addr_changed = FALSE;
757 gboolean votes_changed = FALSE;
759 crm_node_t *node = NULL;
766 if (node->
uuid == NULL) {
771 }
else if (uuid != NULL) {
772 node->
uuid = strdup(uuid);
787 #if SUPPORT_HEARTBEAT
799 if (votes > 0 && node->
votes != votes) {
800 votes_changed = TRUE;
808 node->
addr = strdup(addr);
811 if (addr_changed || votes_changed) {
812 crm_info(
"%s: Node %s: id=%u state=%s addr=%s%s votes=%d%s born=" U64T " seen=" U64T
813 " proc=%.32x", source, node->
uname, node->
id, node->
state,
814 node->
addr, addr_changed ?
" (new)" :
"", node->
votes,
836 int i, len = strlen(uname);
838 for (i = 0; i < len; i++) {
839 if (uname[i] >=
'A' && uname[i] <=
'Z') {
840 crm_warn(
"Node names with capitals are discouraged, consider changing '%s'",
847 node->
uname = strdup(uname);
854 crm_remove_conflicting_peer(node);
879 gboolean changed = FALSE;
882 source, peer2text(flag), status);
return NULL);
890 if (status == NULL) {
903 if (flag > 0 && node->
processes != flag) {
916 crm_info(
"%s: Node %s[%u] - all processes are now offline", source, node->
uname,
919 crm_info(
"%s: Node %s[%u] - %s is now %s", source, node->
uname, node->
id,
920 peer2text(flag), status);
939 is_set(node->
processes, crm_get_cluster_proc())?
943 crm_trace(
"%s: Node %s[%u] - %s is unchanged (%s)", source, node->
uname, node->
id,
944 peer2text(flag), status);
953 gboolean changed = FALSE;
955 CRM_CHECK(node != NULL,
crm_err(
"%s: Could not set 'expected' to %s", source, expected);
970 crm_info(
"%s: Node %s[%u] - expected state is now %s (was %s)", source, node->
uname, node->
id,
974 crm_trace(
"%s: Node %s[%u] - expected state is unchanged (%s)", source, node->
uname,
996 crm_update_peer_state_iter(
const char *source, crm_node_t * node,
const char *state,
int membership,
GHashTableIter *iter)
1001 crm_err(
"Could not set state for unknown host to %s"
1002 CRM_XS " source=%s", state, source);
1006 if (membership && is_member) {
1011 char *last = node->
state;
1015 node->
state = strdup(state);
1017 " nodeid=%u previous=%s source=%s", node->
uname, state,
1018 node->
id, (last? last :
"unknown"), source);
1030 crm_notice(
"Purged 1 peer with id=%u and/or uname=%s from the membership cache", node->
id, node->
uname);
1031 g_hash_table_iter_remove(iter);
1041 " nodeid=%u source=%s", node->
uname, state, node->
id, source);
1064 return crm_update_peer_state_iter(source, node, state, membership, NULL);
1077 crm_node_t *node = NULL;
1081 while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&node)) {
1089 crm_update_peer_state_iter(__FUNCTION__, node,
CRM_NODE_LOST, membership, &iter);
1092 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.