12 #include <sys/socket.h> 13 #include <netinet/in.h> 14 #include <arpa/inet.h> 20 #include <sys/utsname.h> 22 #include <qb/qbipcc.h> 23 #include <qb/qbutil.h> 25 #include <corosync/corodefs.h> 26 #include <corosync/corotypes.h> 27 #include <corosync/hdb.h> 28 #include <corosync/cfg.h> 29 #include <corosync/cmap.h> 30 #include <corosync/quorum.h> 48 cs_error_t rc = CS_OK;
51 cmap_handle_t local_handle = 0;
63 if (cmap_handle == 0 && local_handle == 0) {
65 crm_trace(
"Initializing CMAP connection");
67 rc = cmap_initialize(&local_handle);
70 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(rc),
75 }
while (retries < 5 && rc != CS_OK);
78 crm_warn(
"Could not connect to Cluster Configuration Database API, error %s",
84 if (cmap_handle == 0) {
85 cmap_handle = local_handle;
87 rc = cmap_fd_get(cmap_handle, &fd);
89 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
96 &found_uid, &found_gid))) {
97 crm_err(
"CMAP provider is not authentic:" 98 " process %lld (uid: %lld, gid: %lld)",
100 (
long long) found_uid, (
long long) found_gid);
103 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
109 while (name == NULL && cmap_handle != 0) {
114 rc = cmap_get_uint32(cmap_handle, key, &
id);
115 crm_trace(
"Checking %u vs %u from %s", nodeid,
id, key);
123 crm_trace(
"Searching for node name for %u in nodelist.node.%d %s", nodeid, lpc, name);
126 cmap_get_string(cmap_handle, key, &name);
138 cmap_get_string(cmap_handle, key, &name);
150 cmap_finalize(local_handle);
154 crm_info(
"Unable to get node name for nodeid %u", nodeid);
181 pcmk_quorum_dispatch(gpointer user_data)
187 crm_err(
"Connection to the Quorum API failed: %d", rc);
195 pcmk_quorum_notification(quorum_handle_t handle,
202 static gboolean init_phase = TRUE;
206 quorate ?
"acquired" :
"lost", (
long unsigned int)view_list_entries);
210 crm_info(
"Membership " U64T ": quorum %s (%lu)", ring_id,
211 quorate ?
"retained" :
"still lost", (
long unsigned int)view_list_entries);
214 if (view_list_entries == 0 && init_phase) {
215 crm_info(
"Corosync membership is still forming, ignoring");
224 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
229 for (i = 0; i < view_list_entries; i++) {
236 if (node->
uname == NULL) {
239 crm_info(
"Obtaining name for new node %u",
id);
257 .quorum_notify_fn = pcmk_quorum_notification,
262 void (*destroy) (gpointer))
274 quorum_fd_callbacks.
dispatch = pcmk_quorum_dispatch;
277 crm_debug(
"Configuring Pacemaker to obtain quorum from Corosync");
281 crm_err(
"Could not connect to the Quorum API: %s (%d)",
282 cs_strerror(rc), rc);
285 }
else if (quorum_type != QUORUM_SET) {
286 crm_err(
"Corosync quorum is not configured\n");
292 crm_err(
"Could not obtain the Quorum API connection: %s (%d)\n",
299 &found_uid, &found_gid))) {
300 crm_err(
"Quorum provider is not authentic:" 301 " process %lld (uid: %lld, gid: %lld)",
303 (
long long) found_uid, (
long long) found_gid);
307 crm_err(
"Could not verify authenticity of Quorum provider: %s (%d)",
315 crm_err(
"Could not obtain the current Quorum API state: %d\n", rc);
319 crm_notice(
"Quorum %s", quorate ?
"acquired" :
"lost");
325 crm_err(
"Could not setup Quorum API notifications: %d\n", rc);
346 while (retries < 5) {
355 case CS_ERR_TRY_AGAIN:
356 case CS_ERR_QUEUE_FULL:
364 crm_err(
"Could not connect to corosync after %d retries", retries);
388 if(cluster->
nodeid == 0) {
389 crm_err(
"Could not establish local nodeid");
394 if(cluster->
uname == NULL) {
395 crm_err(
"Could not establish local node name");
409 gboolean sane = TRUE;
413 if (sane && msg->header.
size == 0) {
418 if (sane && msg->header.error != CS_OK) {
419 crm_warn(
"Message header contains an error: %d", msg->header.error);
430 crm_warn(
"Message with no payload");
435 int str_size = strlen(data) + 1;
440 crm_warn(
"Message payload is corrupted: expected %d bytes, got %d",
443 for (lpc = (str_size - 10); lpc < msg->
size; lpc++) {
447 crm_debug(
"bad_data[%d]: %d / '%c'", lpc, data[lpc], data[lpc]);
453 crm_err(
"Invalid message %d: (dest=%s:%s, from=%s:%s.%u, compressed=%d, size=%d, total=%d)",
454 msg->
id, ais_dest(&(msg->
host)), msg_type2text(dest),
460 (
"Verified message %d: (dest=%s:%s, from=%s:%s.%u, compressed=%d, size=%d, total=%d)",
461 msg->
id, ais_dest(&(msg->
host)), msg_type2text(dest), ais_dest(&(msg->
sender)),
473 cmap_handle_t handle;
475 rc = cmap_initialize(&handle);
480 case CS_ERR_SECURITY:
481 crm_debug(
"Failed to initialize the cmap API: Permission denied (%d)", rc);
488 crm_info(
"Failed to initialize the cmap API: %s (%d)",
489 ais_error2text(rc), rc);
493 cmap_finalize(handle);
519 cs_error_t rc = CS_OK;
521 gboolean any = FALSE;
522 cmap_handle_t cmap_handle;
530 rc = cmap_initialize(&cmap_handle);
533 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(rc),
538 }
while (retries < 5 && rc != CS_OK);
541 crm_warn(
"Could not connect to Cluster Configuration Database API, error %d", rc);
545 rc = cmap_fd_get(cmap_handle, &fd);
547 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
548 cs_strerror(rc), rc);
554 &found_uid, &found_gid))) {
555 crm_err(
"CMAP provider is not authentic:" 556 " process %lld (uid: %lld, gid: %lld)",
558 (
long long) found_uid, (
long long) found_gid);
561 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
567 crm_trace(
"Initializing corosync nodelist");
568 for (lpc = 0;; lpc++) {
574 rc = cmap_get_uint32(cmap_handle, key, &nodeid);
587 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
588 if(node && node->
uname && strcasecmp(node->
uname, name) == 0) {
589 if (node->
id && node->
id != nodeid) {
590 crm_crit(
"Nodes %u and %u share the same name '%s': shutting down", node->
id,
598 if (nodeid > 0 || name != NULL) {
599 crm_trace(
"Initializing node[%d] %u = %s", lpc, nodeid, name);
603 if (nodeid > 0 && name != NULL) {
610 if(snprintf(buffer, 63,
"%u", nodeid) > 0) {
623 cmap_finalize(cmap_handle);
630 cmap_handle_t handle;
631 char *cluster_name = NULL;
632 cs_error_t rc = CS_OK;
639 rc = cmap_initialize(&handle);
641 crm_info(
"Failed to initialize the cmap API: %s (%d)",
642 cs_strerror(rc), rc);
646 rc = cmap_fd_get(handle, &fd);
648 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
649 cs_strerror(rc), rc);
655 &found_uid, &found_gid))) {
656 crm_err(
"CMAP provider is not authentic:" 657 " process %lld (uid: %lld, gid: %lld)",
659 (
long long) found_uid, (
long long) found_gid);
662 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
667 rc = cmap_get_string(handle,
"totem.cluster_name", &cluster_name);
669 crm_info(
"Cannot get totem.cluster_name: %s (%d)", cs_strerror(rc), rc);
672 crm_debug(
"cmap totem.cluster_name = '%s'", cluster_name);
676 cmap_finalize(handle);
683 cs_error_t rc = CS_OK;
685 static int found = -1;
686 cmap_handle_t cmap_handle;
687 cmap_iter_handle_t iter_handle;
688 char key_name[CMAP_KEYNAME_MAXLEN + 1];
700 rc = cmap_initialize(&cmap_handle);
703 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(rc),
708 }
while (retries < 5 && rc != CS_OK);
711 crm_warn(
"Could not connect to Cluster Configuration Database API: %s (rc=%d)",
712 cs_strerror(rc), rc);
716 rc = cmap_fd_get(cmap_handle, &fd);
718 crm_err(
"Could not obtain the CMAP API connection: %s (%d)",
719 cs_strerror(rc), rc);
725 &found_uid, &found_gid))) {
726 crm_err(
"CMAP provider is not authentic:" 727 " process %lld (uid: %lld, gid: %lld)",
729 (
long long) found_uid, (
long long) found_gid);
732 crm_err(
"Could not verify authenticity of CMAP provider: %s (%d)",
737 rc = cmap_iter_init(cmap_handle, prefix, &iter_handle);
739 crm_warn(
"Failed to initialize iteration for corosync cmap '%s': %s (rc=%d)",
740 prefix, cs_strerror(rc), rc);
745 while ((rc = cmap_iter_next(cmap_handle, iter_handle, key_name, NULL, NULL)) == CS_OK) {
746 crm_trace(
"'%s' is configured in corosync cmap: %s", prefix, key_name);
750 cmap_iter_finalize(cmap_handle, iter_handle);
753 cmap_finalize(cmap_handle);
enum crm_ais_msg_types type
gboolean check_message_sanity(const AIS_Message *msg, const char *data)
#define crm_notice(fmt, args...)
#define crm_crit(fmt, args...)
gboolean safe_str_neq(const char *a, const char *b)
mainloop_io_t * mainloop_add_fd(const char *name, int priority, int fd, void *userdata, struct mainloop_fd_callbacks *callbacks)
quorum_callbacks_t quorum_callbacks
void crm_reap_unseen_nodes(uint64_t ring_id)
char * corosync_node_name(uint64_tcmap_handle, uint32_t nodeid)
quorum_handle_t pcmk_quorum_handle
void(* destroy)(gpointer userdata)
char * get_corosync_uuid(crm_node_t *peer)
void terminate_cs_connection(crm_cluster_t *cluster)
gboolean cluster_connect_quorum(gboolean(*dispatch)(unsigned long long, gboolean), void(*destroy)(gpointer))
#define PCMK__SPECIAL_PID_AS_0(p)
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
char * get_node_name(uint32_t nodeid)
char * strerror(int errnum)
Wrappers for and extensions to glib mainloop.
gboolean init_cs_connection(crm_cluster_t *cluster)
gboolean crm_is_corosync_peer_active(const crm_node_t *node)
void cluster_disconnect_cpg(crm_cluster_t *cluster)
int(* dispatch)(gpointer userdata)
#define crm_warn(fmt, args...)
char * corosync_cluster_name(void)
#define crm_debug(fmt, args...)
gboolean(* quorum_app_callback)(unsigned long long seq, gboolean quorate)
#define crm_trace(fmt, args...)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
struct crm_ais_msg_s AIS_Message
#define ais_data_len(msg)
int corosync_cmap_has_config(const char *prefix)
enum cluster_type_e find_corosync_variant(void)
gboolean ais_membership_force
const char * name_for_cluster_type(enum cluster_type_e type)
#define DAEMON_RESPAWN_STOP
gboolean init_cs_connection_once(crm_cluster_t *cluster)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
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.
uint32_t get_local_nodeid(cpg_handle_t handle)
gboolean node_name_is_valid(const char *key, const char *name)
#define crm_err(fmt, args...)
Wrappers for and extensions to libqb IPC.
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
GHashTable * crm_peer_cache
#define crm_info(fmt, args...)
gboolean corosync_initialize_nodelist(void *cluster, gboolean force_member, xmlNode *xml_parent)
gboolean cluster_connect_cpg(crm_cluster_t *cluster)
enum cluster_type_e get_cluster_type(void)
int crm_ipc_is_authentic_process(int sock, uid_t refuid, gid_t refgid, pid_t *gotpid, uid_t *gotuid, gid_t *gotgid)
Check the authenticity of the IPC socket peer process.