27 #include <sys/param.h>
28 #include <sys/types.h>
29 #include <sys/utsname.h>
40 void *hb_library = NULL;
44 get_heartbeat_uuid(
const char *
uname)
46 char *uuid_calc = NULL;
50 const char *unknown =
"00000000-0000-0000-0000-000000000000";
52 if (heartbeat_cluster == NULL) {
53 crm_warn(
"No connection to heartbeat, using uuid=uname");
55 }
else if(uname == NULL) {
59 if (heartbeat_cluster->llc_ops->get_uuid_by_name(heartbeat_cluster, uname, &uuid_raw) ==
61 crm_err(
"get_uuid_by_name() call failed for host %s", uname);
66 uuid_calc = calloc(1, 50);
67 cl_uuid_unparse(&uuid_raw, uuid_calc);
70 crm_warn(
"Could not calculate UUID for %s", uname);
81 static const char *uuid_pref = NULL;
83 if (uuid_pref == NULL) {
84 uuid_pref = getenv(
"PCMK_uname_is_uuid");
87 if (uuid_pref == NULL) {
116 buffer = calloc(1, (len + 1));
117 if (buffer != NULL) {
118 snprintf(buffer, len,
"%u", node->
id);
124 crm_info(
"Node %s is not yet known by corosync", node->
uname);
127 }
else if (node->
uname != NULL) {
128 return strdup(node->
uname);
144 }
else if (peer->
uuid) {
156 uuid = strdup(peer->
uname);
161 uuid = get_heartbeat_uuid(peer->
uname);
166 crm_err(
"Unsupported cluster type");
187 #if SUPPORT_HEARTBEAT
192 if (cluster->hb_conn == NULL) {
194 ll_cluster_t *(*new_cluster) (
const char *llctype) =
197 cluster->hb_conn = (*new_cluster) (
"heartbeat");
202 cluster->hb_conn->llc_ops->signoff(cluster->hb_conn, FALSE);
206 if (heartbeat_cluster && heartbeat_cluster != cluster->hb_conn) {
207 heartbeat_cluster->llc_ops->signoff(heartbeat_cluster, FALSE);
211 heartbeat_cluster = cluster->hb_conn;
213 rv = register_heartbeat_conn(cluster);
221 if (HA_OK != heartbeat_cluster->llc_ops->set_sendq_len(heartbeat_cluster, 1024)) {
222 crm_warn(
"Cannot set sendq length: %s",
223 heartbeat_cluster->llc_ops->errmsg(heartbeat_cluster));
229 crm_info(
"Unsupported cluster stack: %s", getenv(
"HA_cluster_type"));
239 crm_info(
"Disconnecting from cluster infrastructure: %s", type_str);
244 crm_info(
"Disconnected from %s", type_str);
249 #if SUPPORT_HEARTBEAT
251 if (cluster == NULL) {
255 }
else if (cluster->hb_conn) {
256 cluster->hb_conn->llc_ops->signoff(cluster->hb_conn, TRUE);
257 cluster->hb_conn = NULL;
258 crm_info(
"Disconnected from %s", type_str);
262 crm_info(
"No %s connection", type_str);
267 crm_info(
"Unsupported cluster stack: %s", getenv(
"HA_cluster_type"));
280 #if SUPPORT_HEARTBEAT
282 return send_ha_message(heartbeat_cluster, data, node ? node->
uname : NULL, ordered);
291 static char *name = NULL;
304 const char *isolation_host = NULL;
308 isolation_host = getenv(
"OCF_RESKEY_"CRM_META"_isolation_host");
309 if (isolation_host) {
310 return strdup(isolation_host);
321 name = classic_node_name(nodeid);
324 # if SUPPORT_COROSYNC
333 name = cman_node_name(nodeid);
341 if(name == NULL && nodeid == 0) {
343 int rc =
uname(&res);
346 crm_notice(
"Defaulting to uname -n for the local %s node name",
348 name = strdup(res.nodename);
358 crm_notice(
"Could not obtain a node name for %s nodeid %u",
389 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
390 if(node->
uuid && strcasecmp(node->
uuid, uuid) == 0) {
406 crm_err(
"Invalid node id: %s", uuid);
414 crm_info(
"Setting uuid for node %s[%u] to '%s'", node->
uname, node->
id, uuid);
415 node->
uuid = strdup(uuid);
424 #if SUPPORT_HEARTBEAT
426 if (heartbeat_cluster != NULL) {
428 char *uuid_copy = strdup(uuid);
431 cl_uuid_parse(uuid_copy, &uuid_raw);
433 if (heartbeat_cluster->llc_ops->get_name_by_uuid(heartbeat_cluster, &uuid_raw, uname,
435 crm_err(
"Could not calculate uname for %s", uuid);
445 crm_info(
"Setting uuid for node %s to '%s'", node->
uname, uuid);
446 node->
uuid = strdup(uuid);
472 return "classic openais (with plugin)";
484 crm_err(
"Invalid cluster type: %d", type);
500 }
else if (cluster_type == type) {
508 crm_err(
"Cluster type already set to %s, ignoring %s",
515 bool detected = FALSE;
516 const char *cluster = NULL;
523 cluster = getenv(
"HA_cluster_type");
525 #if SUPPORT_HEARTBEAT
527 if(cluster == NULL) {
530 &hb_library, HEARTBEAT_LIBRARY,
"ll_cluster_new", 1);
532 hb = (*new_cluster) (
"heartbeat");
545 if (hb->llc_ops->signon(hb, NULL) == HA_OK) {
546 hb->llc_ops->signoff(hb, FALSE);
557 if(cluster == NULL) {
568 crm_info(
"Verifying cluster type: '%s'", cluster?cluster:
"-unspecified-");
569 if (cluster == NULL) {
571 #if SUPPORT_HEARTBEAT
578 ||
safe_str_eq(cluster,
"classic openais (with plugin)")) {
597 crm_notice(
"Could not determine the current cluster type");
600 crm_notice(
"This installation does not support the '%s' cluster infrastructure: terminating.",
659 }
else if (sscanf(name,
"%d.%d.%d.%d", &octet, &octet, &octet, &octet) == 4) {
660 crm_trace(
"%s contains an ipv4 address, ignoring: %s", key, name);
663 }
else if (strstr(name,
":") != NULL) {
664 crm_trace(
"%s contains an ipv6 address, ignoring: %s", key, name);
void crm_peer_destroy(void)
#define CRM_CHECK(expr, failure_action)
void * find_library_function(void **handle, const char *lib, const char *fn, int fatal)
#define crm_notice(fmt, args...)
gboolean is_openais_cluster(void)
char * corosync_node_name(uint64_tcmap_handle, uint32_t nodeid)
gboolean is_heartbeat_cluster(void)
char * get_corosync_uuid(crm_node_t *peer)
void terminate_cs_connection(crm_cluster_t *cluster)
const char * get_local_node_name(void)
int get_corosync_id(int id, const char *uuid)
long long crm_int_helper(const char *text, char **end_text)
GHashTable * crm_remote_peer_cache
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
char * get_node_name(uint32_t nodeid)
void crm_cluster_disconnect(crm_cluster_t *cluster)
gboolean init_cs_connection(crm_cluster_t *cluster)
#define CRM_TRACE_INIT_DATA(name)
#define crm_warn(fmt, args...)
#define crm_atoi(text, default_text)
#define crm_debug(fmt, args...)
#define crm_trace(fmt, args...)
enum cluster_type_e find_corosync_variant(void)
gboolean is_cman_cluster(void)
const char * name_for_cluster_type(enum cluster_type_e type)
gboolean crm_cluster_connect(crm_cluster_t *cluster)
int set_cluster_type(enum cluster_type_e type)
#define DAEMON_RESPAWN_STOP
gboolean is_corosync_cluster(void)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
gboolean node_name_is_valid(const char *key, const char *name)
#define crm_err(fmt, args...)
const char * crm_peer_uname(const char *uuid)
Get the node name corresponding to a node UUID.
gboolean send_cluster_message_cs(xmlNode *msg, gboolean local, crm_node_t *node, enum crm_ais_msg_types dest)
Wrappers for and extensions to libqb IPC.
gboolean crm_is_true(const char *s)
void set_uuid(xmlNode *xml, const char *attr, crm_node_t *node)
#define safe_str_eq(a, b)
crm_node_t * crm_find_peer(unsigned int id, const char *uname)
gboolean send_cluster_message(crm_node_t *node, enum crm_ais_msg_types service, xmlNode *data, gboolean ordered)
GHashTable * crm_peer_cache
#define crm_info(fmt, args...)
const char * crm_peer_uuid(crm_node_t *node)
gboolean is_classic_ais_cluster(void)
enum crm_ais_msg_types type
enum cluster_type_e get_cluster_type(void)