Пример #1
0
static void
_cs_local_node_info_get(char **nodename, uint32_t *nodeid)
{
	cs_error_t rc;
	corosync_cfg_handle_t cfg_handle;

	if (local_nodeid == 0) {
		rc = corosync_cfg_initialize(&cfg_handle, NULL);
		if (rc != CS_OK) {
			syslog (LOG_ERR, "Failed to initialize the cfg API. Error %d\n", rc);
			exit (EXIT_FAILURE);
		}

		rc = corosync_cfg_local_get (cfg_handle, &local_nodeid);
		corosync_cfg_finalize(cfg_handle);
		if (rc != CS_OK) {
			local_nodeid = 0;
			strncpy(local_nodename, "localhost", sizeof (local_nodename));
			local_nodename[sizeof (local_nodename) - 1] = '\0';
		} else {
			gethostname(local_nodename, CS_MAX_NAME_LENGTH);
		}
	}
	*nodeid = local_nodeid;
	*nodename = local_nodename;
}
Пример #2
0
int setup_cluster_cfg(void)
{
	cs_error_t err;
	unsigned int nodeid;
	int fd;

	err = corosync_cfg_initialize(&ch, &cfg_callbacks);
	if (err != CS_OK) {
		log_error("corosync cfg init error %d", err);
		return -1;
	}

	err = corosync_cfg_fd_get(ch, &fd);
	if (err != CS_OK) {
		log_error("corosync cfg fd_get error %d", err);
		corosync_cfg_finalize(ch);
		return -1;
	}

	err = corosync_cfg_local_get(ch, &nodeid);
	if (err != CS_OK) {
		log_error("corosync cfg local_get error %d", err);
		corosync_cfg_finalize(ch);
		return -1;
	}
	our_nodeid = nodeid;
	log_debug("our_nodeid %d", our_nodeid);

	return fd;
}
Пример #3
0
static int ringstatusget_do (char *interface_name)
{
	cs_error_t result;
	corosync_cfg_handle_t handle;
	unsigned int interface_count;
	char **interface_names;
	char **interface_status;
	unsigned int i;
	unsigned int nodeid;
	int rc = 0;

	printf ("Printing ring status.\n");
	result = corosync_cfg_initialize (&handle, NULL);
	
	printf ("xxx 47500: tools/corosync-cfgtool.c After corosync_cfg_initialize...\n");
	
	if (result != CS_OK) {
		printf ("Could not initialize corosync configuration API error %d\n", result);
		exit (1);
	}

	result = corosync_cfg_local_get(handle, &nodeid);
	if (result != CS_OK) {
		printf ("Could not get the local node id, the error is: %d\n", result);
	}
	else {
		printf ("Local node ID %d\n", nodeid);
	}

	result = corosync_cfg_ring_status_get (handle,
				&interface_names,
				&interface_status,
				&interface_count);
	if (result != CS_OK) {
		printf ("Could not get the ring status, the error is: %d\n", result);
	} else {
		for (i = 0; i < interface_count; i++) {
			if ( (interface_name && 
			     	(interface_name[0]=='\0' || 
				strcasecmp (interface_name, interface_names[i]) == 0)) ||
				!interface_name ) {

				printf ("RING ID %d\n", i);
				printf ("\tid\t= %s\n", interface_names[i]);
				printf ("\tstatus\t= %s\n", interface_status[i]);
				if (strstr(interface_status[i], "FAULTY")) {
					rc = 1;
				}
			}
		}
	}
	(void)corosync_cfg_finalize (handle);
	return rc;
}
Пример #4
0
gboolean
cluster_connect_cfg(uint32_t * nodeid)
{
    cs_error_t rc;
    int fd = 0, retries = 0;
    static struct mainloop_fd_callbacks cfg_fd_callbacks = 
        {
            .dispatch = pcmk_cfg_dispatch,
            .destroy = cfg_connection_destroy,
        };

    cs_repeat(retries, 30, rc = corosync_cfg_initialize(&cfg_handle, &cfg_callbacks));

    if (rc != CS_OK) {
        crm_err("corosync cfg init error %d", rc);
        return FALSE;
    }

    rc = corosync_cfg_fd_get(cfg_handle, &fd);
    if (rc != CS_OK) {
        crm_err("corosync cfg fd_get error %d", rc);
        goto bail;
    }

    retries = 0;
    cs_repeat(retries, 30, rc = corosync_cfg_local_get(cfg_handle, nodeid));

    if (rc != CS_OK) {
        crm_err("corosync cfg local_get error %d", rc);
        goto bail;
    }

    crm_debug("Our nodeid: %d", *nodeid);
    mainloop_add_fd("corosync-cfg", G_PRIORITY_DEFAULT, fd, &cfg_handle, &cfg_fd_callbacks);

    return TRUE;

  bail:
    corosync_cfg_finalize(cfg_handle);
    return FALSE;
}
Пример #5
0
static void ringstatusget_do (void)
{
	cs_error_t result;
	corosync_cfg_handle_t handle;
	unsigned int interface_count;
	char **interface_names;
	char **interface_status;
	unsigned int i;
	unsigned int nodeid;

	printf ("Printing ring status.\n");
	result = corosync_cfg_initialize (&handle, NULL);
	if (result != CS_OK) {
		printf ("Could not initialize corosync configuration API error %d\n", result);
		exit (1);
	}

	result = corosync_cfg_local_get(handle, &nodeid);
	if (result != CS_OK) {
		printf ("Could not get the local node id, the error is: %d\n", result);
	}
	else {
		printf ("Local node ID %d\n", nodeid);
	}

	result = corosync_cfg_ring_status_get (handle,
				&interface_names,
				&interface_status,
				&interface_count);
	if (result != CS_OK) {
		printf ("Could not get the ring status, the error is: %d\n", result);
	} else {
		for (i = 0; i < interface_count; i++) {
			printf ("RING ID %d\n", i);
			printf ("\tid\t= %s\n", interface_names[i]);
			printf ("\tstatus\t= %s\n", interface_status[i]);
		}
	}
	(void)corosync_cfg_finalize (handle);
}
Пример #6
0
gboolean
cluster_connect_cfg(uint32_t * nodeid)
{
    cs_error_t rc;
    int fd = 0, retries = 0;

    cs_repeat(retries, 30, rc = corosync_cfg_initialize(&cfg_handle, &cfg_callbacks));

    if (rc != CS_OK) {
        crm_err("corosync cfg init error %d", rc);
        return FALSE;
    }

    rc = corosync_cfg_fd_get(cfg_handle, &fd);
    if (rc != CS_OK) {
        crm_err("corosync cfg fd_get error %d", rc);
        goto bail;
    }

    retries = 0;
    cs_repeat(retries, 30, rc = corosync_cfg_local_get(cfg_handle, nodeid));

    if (rc != CS_OK) {
        crm_err("corosync cfg local_get error %d", rc);
        goto bail;
    }

    crm_debug("Our nodeid: %d", *nodeid);

    crm_debug("Adding fd=%d to mainloop", fd);
    G_main_add_fd(G_PRIORITY_HIGH, fd, FALSE, pcmk_cfg_dispatch, &cfg_handle,
                  cfg_connection_destroy);

    return TRUE;

  bail:
    corosync_cfg_finalize(cfg_handle);
    return FALSE;
}
Пример #7
0
/*! \brief Informs the cluster of our EID and our IP addresses */
static void send_cluster_notify(void)
{
	struct ast_event *event;
	unsigned int node_id;
	cs_error_t cs_err;
	corosync_cfg_node_address_t corosync_addr;
	int num_addrs = 0;
	struct sockaddr *sa;
	size_t sa_len;
	char buf[128];
	int res;

	if ((cs_err = corosync_cfg_local_get(cfg_handle, &node_id)) != CS_OK) {
		ast_log(LOG_WARNING, "Failed to extract Corosync node ID for this node. Not informing cluster of existance.\n");
		return;
	}

	if (((cs_err = corosync_cfg_get_node_addrs(cfg_handle, node_id, 1, &num_addrs, &corosync_addr)) != CS_OK) || (num_addrs < 1)) {
		ast_log(LOG_WARNING, "Failed to get local Corosync address. Not informing cluster of existance.\n");
		return;
	}

	sa = (struct sockaddr *)corosync_addr.address;
	sa_len = (size_t)corosync_addr.address_length;
	if ((res = getnameinfo(sa, sa_len, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST))) {
		ast_log(LOG_WARNING, "Failed to determine name of local Corosync address: %s (%d). Not informing cluster of existance.\n",
			gai_strerror(res), res);
		return;
	}

	event = ast_event_new(AST_EVENT_CLUSTER_DISCOVERY,
				    AST_EVENT_IE_NODE_ID, AST_EVENT_IE_PLTYPE_UINT, node_id,
				    AST_EVENT_IE_LOCAL_ADDR, AST_EVENT_IE_PLTYPE_STR, buf,
				    AST_EVENT_IE_END);
	publish_event_to_corosync(event);
	ast_free(event);
}
Пример #8
0
static int
linkstatusget_do (char *interface_name, int brief)
{
	cs_error_t result;
	corosync_cfg_handle_t handle;
	unsigned int interface_count;
	char **interface_names;
	char **interface_status;
	unsigned int i;
	unsigned int nodeid;
	int rc = 0;
	int len, s = 0, t;

	printf ("Printing link status.\n");
	result = corosync_cfg_initialize (&handle, NULL);
	if (result != CS_OK) {
		printf ("Could not initialize corosync configuration API error %d\n", result);
		exit (1);
	}

	result = corosync_cfg_local_get(handle, &nodeid);
	if (result != CS_OK) {
		printf ("Could not get the local node id, the error is: %d\n", result);
	}
	else {
		printf ("Local node ID %u\n", nodeid);
	}

	result = corosync_cfg_ring_status_get (handle,
				&interface_names,
				&interface_status,
				&interface_count);
	if (result != CS_OK) {
		printf ("Could not get the link status, the error is: %d\n", result);
	} else {
		for (i = 0; i < interface_count; i++) {
			s = 0;
			if ( (interface_name &&
			      interface_names[i][0] != '\0' &&
			      (interface_name[0]=='\0' ||
				strcasecmp (interface_name, interface_names[i]) == 0)) ||
				!interface_name ) {

				/*
				 * Interface_name is "<linkid> <IP address>"
				 * separate them out
				 */
				char *space = strchr(interface_names[i], ' ');
				if (!space) {
					continue;
				}
				*space = '\0';

				printf ("LINK ID %s\n", interface_names[i]);
				printf ("\taddr\t= %s\n", space+1);
				if((!brief) && (strcmp(interface_status[i], "OK") != 0) &&
					(!strstr(interface_status[i], "FAULTY"))) {
					len = strlen(interface_status[i]);
					printf ("\tstatus:\n");
					while(s < len) {
						t = interface_status[i][s] - '0';
						printf("\t\tnode %d:\t", s++);
						printf("link enabled:%d\t", t&1? 1 : 0);
						printf("link connected:%d\n", t&2? 1: 0);
					}
				} else {
					printf ("\tstatus\t= %s\n", interface_status[i]);
					if (strstr(interface_status[i], "FAULTY")) {
						rc = 1;
					}
				}
			}
		}

		for (i = 0; i < interface_count; i++) {
			free(interface_status[i]);
			free(interface_names[i]);
		}
		free(interface_status);
		free(interface_names);
	}

	(void)corosync_cfg_finalize (handle);
	return rc;
}