21 #include <sys/socket.h> 22 #include <netinet/in.h> 23 #include <arpa/inet.h> 32 #include <sys/utsname.h> 34 #include <qb/qbipcc.h> 35 #include <qb/qbutil.h> 37 #include <corosync/corodefs.h> 38 #include <corosync/corotypes.h> 39 #include <corosync/hdb.h> 40 #include <corosync/cfg.h> 41 #include <corosync/cmap.h> 42 #include <corosync/quorum.h> 57 crm_info(
"Node %s is not yet known by corosync", node->
uname);
74 cmap_handle_t local_handle = 0;
80 if (cmap_handle == 0 && local_handle == 0) {
82 crm_trace(
"Initializing CMAP connection");
84 rc = cmap_initialize(&local_handle);
87 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(rc),
92 }
while (retries < 5 && rc != CS_OK);
95 crm_warn(
"Could not connect to Cluster Configuration Database API, error %s",
101 if (cmap_handle == 0) {
102 cmap_handle = local_handle;
105 while (name == NULL && cmap_handle != 0) {
110 rc = cmap_get_uint32(cmap_handle, key, &
id);
111 crm_trace(
"Checking %u vs %u from %s", nodeid,
id, key);
119 crm_trace(
"Searching for node name for %u in nodelist.node.%d %s", nodeid, lpc, name);
122 cmap_get_string(cmap_handle, key, &name);
128 cmap_get_string(cmap_handle, key, &name);
144 cmap_finalize(local_handle);
148 crm_info(
"Unable to get node name for nodeid %u", nodeid);
165 pcmk_quorum_dispatch(gpointer user_data)
171 crm_err(
"Connection to the Quorum API failed: %d", rc);
179 pcmk_quorum_notification(quorum_handle_t handle,
186 static gboolean init_phase = TRUE;
191 ring_id, (
long unsigned int)view_list_entries);
194 ring_id, (
long unsigned int)view_list_entries);
200 (quorate?
"retained" :
"still lost"), ring_id,
201 (
long unsigned int)view_list_entries);
204 if (view_list_entries == 0 && init_phase) {
205 crm_info(
"Corosync membership is still forming, ignoring");
214 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
219 for (i = 0; i < view_list_entries; i++) {
226 if (node->uname == NULL) {
229 crm_info(
"Obtaining name for new node %u",
id);
247 .quorum_notify_fn = pcmk_quorum_notification,
252 void (*destroy) (gpointer))
260 quorum_fd_callbacks.
dispatch = pcmk_quorum_dispatch;
263 crm_debug(
"Configuring Pacemaker to obtain quorum from Corosync");
267 crm_err(
"Could not connect to the Quorum API: %d", rc);
270 }
else if (quorum_type != QUORUM_SET) {
271 crm_err(
"Corosync quorum is not configured");
277 crm_err(
"Could not obtain the current Quorum API state: %d", rc);
291 crm_err(
"Could not setup Quorum API notifications: %d", rc);
297 crm_err(
"Could not obtain the Quorum API connection: %d", rc);
318 while (retries < 5) {
327 case CS_ERR_TRY_AGAIN:
328 case CS_ERR_QUEUE_FULL:
336 crm_err(
"Could not connect to corosync after %d retries", retries);
360 if(cluster->
nodeid == 0) {
361 crm_err(
"Could not establish local nodeid");
366 if(cluster->
uname == NULL) {
367 crm_err(
"Could not establish local node name");
381 gboolean sane = TRUE;
385 if (sane && msg->header.
size == 0) {
390 if (sane && msg->header.error != CS_OK) {
391 crm_warn(
"Message header contains an error: %d", msg->header.error);
402 crm_warn(
"Message with no payload");
407 int str_size = strlen(data) + 1;
412 crm_warn(
"Message payload is corrupted: expected %d bytes, got %d",
415 for (lpc = (str_size - 10); lpc < msg->
size; lpc++) {
419 crm_debug(
"bad_data[%d]: %d / '%c'", lpc, data[lpc], data[lpc]);
425 crm_err(
"Invalid message %d: (dest=%s:%s, from=%s:%s.%u, compressed=%d, size=%d, total=%d)",
426 msg->
id, ais_dest(&(msg->
host)), msg_type2text(dest),
432 (
"Verified message %d: (dest=%s:%s, from=%s:%s.%u, compressed=%d, size=%d, total=%d)",
433 msg->
id, ais_dest(&(msg->
host)), msg_type2text(dest), ais_dest(&(msg->
sender)),
445 cmap_handle_t handle;
447 rc = cmap_initialize(&handle);
452 case CS_ERR_SECURITY:
453 crm_debug(
"Failed to initialize the cmap API: Permission denied (%d)", rc);
460 crm_info(
"Failed to initialize the cmap API: %s (%d)",
461 ais_error2text(rc), rc);
465 cmap_finalize(handle);
493 gboolean any = FALSE;
494 cmap_handle_t cmap_handle;
497 rc = cmap_initialize(&cmap_handle);
500 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(rc),
505 }
while (retries < 5 && rc != CS_OK);
508 crm_warn(
"Could not connect to Cluster Configuration Database API, error %d", rc);
513 crm_trace(
"Initializing corosync nodelist");
514 for (lpc = 0; TRUE; lpc++) {
520 rc = cmap_get_uint32(cmap_handle, key, &nodeid);
533 while (g_hash_table_iter_next(&iter, NULL, (gpointer *) &node)) {
534 if(node && node->uname && strcasecmp(node->uname, name) == 0) {
535 if (node->id && node->id != nodeid) {
536 crm_crit(
"Nodes %u and %u share the same name '%s': shutting down", node->id,
544 if (nodeid > 0 || name != NULL) {
545 crm_trace(
"Initializing node[%d] %u = %s", lpc, nodeid, name);
549 if (nodeid > 0 && name != NULL) {
565 cmap_finalize(cmap_handle);
572 cmap_handle_t handle;
573 char *cluster_name = NULL;
576 rc = cmap_initialize(&handle);
578 crm_info(
"Failed to initialize the cmap API: %s (%d)", ais_error2text(rc), rc);
582 rc = cmap_get_string(handle,
"totem.cluster_name", &cluster_name);
584 crm_info(
"Cannot get totem.cluster_name: %s (%d)", ais_error2text(rc), rc);
587 crm_debug(
"cmap totem.cluster_name = '%s'", cluster_name);
590 cmap_finalize(handle);
600 static int found = -1;
601 cmap_handle_t cmap_handle;
602 cmap_iter_handle_t iter_handle;
603 char key_name[CMAP_KEYNAME_MAXLEN + 1];
610 rc = cmap_initialize(&cmap_handle);
613 crm_debug(
"API connection setup failed: %s. Retrying in %ds", cs_strerror(rc),
618 }
while (retries < 5 && rc != CS_OK);
621 crm_warn(
"Could not connect to Cluster Configuration Database API: %s (rc=%d)",
622 cs_strerror(rc), rc);
626 rc = cmap_iter_init(cmap_handle, prefix, &iter_handle);
628 crm_warn(
"Failed to initialize iteration for corosync cmap '%s': %s (rc=%d)",
629 prefix, cs_strerror(rc), rc);
634 while ((rc = cmap_iter_next(cmap_handle, iter_handle, key_name, NULL, NULL)) == CS_OK) {
635 crm_trace(
"'%s' is configured in corosync cmap: %s", prefix, key_name);
639 cmap_iter_finalize(cmap_handle, iter_handle);
642 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)
quorum_handle_t pcmk_quorum_handle
void(* destroy)(gpointer userdata)
void terminate_cs_connection(crm_cluster_t *cluster)
gboolean cluster_connect_quorum(gboolean(*dispatch)(unsigned long long, gboolean), void(*destroy)(gpointer))
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
crm_node_t * crm_get_peer(unsigned int id, const char *uname)
char * get_node_name(uint32_t nodeid)
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
char * corosync_node_name(uint64_t cmap_handle, uint32_t nodeid)
#define ais_data_len(msg)
int corosync_cmap_has_config(const char *prefix)
enum cluster_type_e find_corosync_variant(void)
crm_exit_t crm_exit(crm_exit_t rc)
const char * name_for_cluster_type(enum cluster_type_e type)
gboolean init_cs_connection_once(crm_cluster_t *cluster)
gboolean is_corosync_cluster(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.
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...)
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
char * get_corosync_uuid(crm_node_t *node)
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)