12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
23 #include <sys/utsname.h>
25 #include <qb/qbipcc.h>
26 #include <qb/qbutil.h>
28 #include <corosync/corodefs.h>
29 #include <corosync/corotypes.h>
30 #include <corosync/hdb.h>
31 #include <corosync/cfg.h>
32 #include <corosync/cmap.h>
33 #include <corosync/quorum.h>
50 crm_info(
"Node %s is not yet known by corosync", node->
uname);
64 cs_error_t
rc = CS_OK;
67 cmap_handle_t local_handle = 0;
78 if (cmap_handle == 0 && local_handle == 0) {
80 crm_trace(
"Initializing CMAP connection");
82 rc = cmap_initialize(&local_handle);
85 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(
rc),
90 }
while (retries < 5 &&
rc != CS_OK);
93 crm_warn(
"Could not connect to Cluster Configuration Database API, error %s",
99 if (cmap_handle == 0) {
100 cmap_handle = local_handle;
102 rc = cmap_fd_get(cmap_handle, &fd);
104 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
105 cs_strerror(
rc),
rc);
111 &found_uid, &found_gid))) {
112 crm_err(
"CMAP provider is not authentic:"
113 " process %lld (uid: %lld, gid: %lld)",
115 (
long long) found_uid, (
long long) found_gid);
118 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
124 while (
name == NULL && cmap_handle != 0) {
129 rc = cmap_get_uint32(cmap_handle, key, &
id);
130 crm_trace(
"Checking %u vs %u from %s", nodeid,
id, key);
138 crm_trace(
"Searching for node name for %u in nodelist.node.%d %s", nodeid, lpc,
name);
141 cmap_get_string(cmap_handle, key, &
name);
147 cmap_get_string(cmap_handle, key, &
name);
164 cmap_finalize(local_handle);
168 crm_info(
"Unable to get node name for nodeid %u", nodeid);
185 pcmk_quorum_dispatch(gpointer user_data)
191 crm_err(
"Connection to the Quorum API failed: %d",
rc);
200 pcmk_quorum_notification(quorum_handle_t handle,
202 uint64_t ring_id, uint32_t view_list_entries, uint32_t * view_list)
207 static gboolean init_phase = TRUE;
212 ring_id, (
long unsigned int)view_list_entries);
215 ring_id, (
long unsigned int)view_list_entries);
221 (quorate?
"retained" :
"still lost"), ring_id,
222 (
long unsigned int)view_list_entries);
225 if (view_list_entries == 0 && init_phase) {
226 crm_info(
"Corosync membership is still forming, ignoring");
235 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
240 for (i = 0; i < view_list_entries; i++) {
241 uint32_t
id = view_list[i];
247 if (node->uname == NULL) {
250 crm_info(
"Obtaining name for new node %u",
id);
268 .quorum_notify_fn = pcmk_quorum_notification,
273 void (*destroy) (gpointer))
278 uint32_t quorum_type = 0;
285 quorum_fd_callbacks.
dispatch = pcmk_quorum_dispatch;
288 crm_debug(
"Configuring Pacemaker to obtain quorum from Corosync");
292 crm_err(
"Could not connect to the Quorum API: %s (%d)",
293 cs_strerror(
rc),
rc);
296 }
else if (quorum_type != QUORUM_SET) {
297 crm_err(
"Corosync quorum is not configured");
303 crm_err(
"Could not obtain the Quorum API connection: %s (%d)",
310 &found_uid, &found_gid))) {
311 crm_err(
"Quorum provider is not authentic:"
312 " process %lld (uid: %lld, gid: %lld)",
314 (
long long) found_uid, (
long long) found_gid);
318 crm_err(
"Could not verify authenticity of Quorum provider: %s (%d)",
326 crm_err(
"Could not obtain the current Quorum API state: %d",
rc);
340 crm_err(
"Could not setup Quorum API notifications: %d",
rc);
361 while (retries < 5) {
370 case CS_ERR_TRY_AGAIN:
371 case CS_ERR_QUEUE_FULL:
379 crm_err(
"Could not connect to corosync after %d retries", retries);
403 if(cluster->
nodeid == 0) {
404 crm_err(
"Could not establish local nodeid");
409 if(cluster->
uname == NULL) {
410 crm_err(
"Could not establish local node name");
424 gboolean sane = TRUE;
428 if (sane && msg->header.
size == 0) {
433 if (sane && msg->header.error != CS_OK) {
434 crm_warn(
"Message header contains an error: %d", msg->header.error);
445 crm_warn(
"Message with no payload");
450 int str_size = strlen(
data) + 1;
455 crm_warn(
"Message payload is corrupted: expected %d bytes, got %d",
458 for (lpc = (str_size - 10); lpc < msg->
size; lpc++) {
468 crm_err(
"Invalid message %d: (dest=%s:%s, from=%s:%s.%u, compressed=%d, size=%d, total=%d)",
469 msg->
id, ais_dest(&(msg->
host)), msg_type2text(dest),
475 (
"Verified message %d: (dest=%s:%s, from=%s:%s.%u, compressed=%d, size=%d, total=%d)",
476 msg->
id, ais_dest(&(msg->
host)), msg_type2text(dest), ais_dest(&(msg->
sender)),
488 cmap_handle_t handle;
490 rc = cmap_initialize(&handle);
495 case CS_ERR_SECURITY:
496 crm_debug(
"Failed to initialize the cmap API: Permission denied (%d)",
rc);
503 crm_info(
"Failed to initialize the cmap API: %s (%d)",
504 ais_error2text(
rc),
rc);
508 cmap_finalize(handle);
534 cs_error_t
rc = CS_OK;
536 gboolean any = FALSE;
537 cmap_handle_t cmap_handle;
545 rc = cmap_initialize(&cmap_handle);
548 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(
rc),
553 }
while (retries < 5 &&
rc != CS_OK);
556 crm_warn(
"Could not connect to Cluster Configuration Database API, error %d",
rc);
560 rc = cmap_fd_get(cmap_handle, &fd);
562 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
563 cs_strerror(
rc),
rc);
569 &found_uid, &found_gid))) {
570 crm_err(
"CMAP provider is not authentic:"
571 " process %lld (uid: %lld, gid: %lld)",
573 (
long long) found_uid, (
long long) found_gid);
576 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
582 crm_trace(
"Initializing corosync nodelist");
583 for (lpc = 0; TRUE; lpc++) {
589 rc = cmap_get_uint32(cmap_handle, key, &nodeid);
602 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
603 if(node && node->uname && strcasecmp(node->uname,
name) == 0) {
604 if (node->id && node->id != nodeid) {
605 crm_crit(
"Nodes %u and %u share the same name '%s': shutting down", node->id,
613 if (nodeid > 0 ||
name != NULL) {
614 crm_trace(
"Initializing node[%d] %u = %s", lpc, nodeid,
name);
618 if (nodeid > 0 &&
name != NULL) {
635 cmap_finalize(cmap_handle);
642 cmap_handle_t handle;
643 char *cluster_name = NULL;
644 cs_error_t
rc = CS_OK;
651 rc = cmap_initialize(&handle);
653 crm_info(
"Failed to initialize the cmap API: %s (%d)",
654 cs_strerror(
rc),
rc);
658 rc = cmap_fd_get(handle, &fd);
660 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
661 cs_strerror(
rc),
rc);
667 &found_uid, &found_gid))) {
668 crm_err(
"CMAP provider is not authentic:"
669 " process %lld (uid: %lld, gid: %lld)",
671 (
long long) found_uid, (
long long) found_gid);
674 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
679 rc = cmap_get_string(handle,
"totem.cluster_name", &cluster_name);
681 crm_info(
"Cannot get totem.cluster_name: %s (%d)", cs_strerror(
rc),
rc);
684 crm_debug(
"cmap totem.cluster_name = '%s'", cluster_name);
688 cmap_finalize(handle);
695 cs_error_t
rc = CS_OK;
697 static int found = -1;
698 cmap_handle_t cmap_handle;
699 cmap_iter_handle_t iter_handle;
700 char key_name[CMAP_KEYNAME_MAXLEN + 1];
712 rc = cmap_initialize(&cmap_handle);
715 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(
rc),
720 }
while (retries < 5 &&
rc != CS_OK);
723 crm_warn(
"Could not connect to Cluster Configuration Database API: %s (rc=%d)",
724 cs_strerror(
rc),
rc);
728 rc = cmap_fd_get(cmap_handle, &fd);
730 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
731 cs_strerror(
rc),
rc);
737 &found_uid, &found_gid))) {
738 crm_err(
"CMAP provider is not authentic:"
739 " process %lld (uid: %lld, gid: %lld)",
741 (
long long) found_uid, (
long long) found_gid);
744 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
749 rc = cmap_iter_init(cmap_handle, prefix, &iter_handle);
751 crm_warn(
"Failed to initialize iteration for corosync cmap '%s': %s (rc=%d)",
752 prefix, cs_strerror(
rc),
rc);
757 while ((
rc = cmap_iter_next(cmap_handle, iter_handle, key_name, NULL, NULL)) == CS_OK) {
758 crm_trace(
"'%s' is configured in corosync cmap: %s", prefix, key_name);
762 cmap_iter_finalize(cmap_handle, iter_handle);
765 cmap_finalize(cmap_handle);