cs_error_t CorosyncCpg::init() { if (ready) { return CS_OK; } cpg_callbacks_t callbacks; ::memset(&callbacks, 0, sizeof(callbacks)); callbacks.cpg_deliver_fn = &globalDeliver; callbacks.cpg_confchg_fn = &globalConfigChange; // QPID_LOG(notice, "Initializing CPG"); cs_error_t err = cpg_initialize(&handle, &callbacks); int retries = 6; // @todo: make this configurable. while (err == CS_ERR_TRY_AGAIN && --retries) { LOG(WARNING)<< "cpg initialize retry " << retries; std::chrono::microseconds dura(5); std::this_thread::sleep_for(dura); err = cpg_initialize(&handle, &callbacks); } if (err != CS_OK) { LOG(ERROR)<< "cpg_initialize error, caused by " << error2str(err); return err; } if (CS_OK != cpg_context_set(handle, this)) { LOG(ERROR)<< "Cannot set CPG context"; return err; } ready = true; return CS_OK; }
static int _init_cluster(void) { SaAisErrorT err; SaVersionT ver = { 'B', 1, 1 }; int select_fd; node_hash = dm_hash_create(100); lock_hash = dm_hash_create(10); err = cpg_initialize(&cpg_handle, &openais_cpg_callbacks); if (err != SA_AIS_OK) { syslog(LOG_ERR, "Cannot initialise OpenAIS CPG service: %d", err); DEBUGLOG("Cannot initialise OpenAIS CPG service: %d", err); return ais_to_errno(err); } err = saLckInitialize(&lck_handle, NULL, &ver); if (err != SA_AIS_OK) { cpg_initialize(&cpg_handle, &openais_cpg_callbacks); syslog(LOG_ERR, "Cannot initialise OpenAIS lock service: %d", err); DEBUGLOG("Cannot initialise OpenAIS lock service: %d\n\n", err); return ais_to_errno(err); } /* Connect to the clvmd group */ strcpy((char *)cpg_group_name.value, "clvmd"); cpg_group_name.length = strlen((char *)cpg_group_name.value); err = cpg_join(cpg_handle, &cpg_group_name); if (err != SA_AIS_OK) { cpg_finalize(cpg_handle); saLckFinalize(lck_handle); syslog(LOG_ERR, "Cannot join clvmd process group"); DEBUGLOG("Cannot join clvmd process group: %d\n", err); return ais_to_errno(err); } err = cpg_local_get(cpg_handle, &our_nodeid); if (err != SA_AIS_OK) { cpg_finalize(cpg_handle); saLckFinalize(lck_handle); syslog(LOG_ERR, "Cannot get local node id\n"); return ais_to_errno(err); } DEBUGLOG("Our local node id is %d\n", our_nodeid); saLckSelectionObjectGet(lck_handle, (SaSelectionObjectT *)&select_fd); add_internal_client(select_fd, lck_dispatch); DEBUGLOG("Connected to OpenAIS\n"); return 0; }
uint32_t get_local_nodeid(cpg_handle_t handle) { int rc = CS_OK; int retries = 0; static uint32_t local_nodeid = 0; cpg_handle_t local_handle = handle; cpg_callbacks_t cb = { }; if(local_nodeid != 0) { return local_nodeid; } if(handle == 0) { crm_trace("Creating connection"); cs_repeat(retries, 5, rc = cpg_initialize(&local_handle, &cb)); } if (rc == CS_OK) { retries = 0; crm_trace("Performing lookup"); cs_repeat(retries, 5, rc = cpg_local_get(local_handle, &local_nodeid)); } if (rc != CS_OK) { crm_err("Could not get local node id from the CPG API: %s (%d)", ais_error2text(rc), rc); } if(handle == 0) { crm_trace("Closing connection"); cpg_finalize(local_handle); } crm_debug("Local nodeid is %u", local_nodeid); return local_nodeid; }
static PyObject * py_cpg_initialize(PyObject *self, PyObject *args) { int ret; cpg_handle_t handle; cpg_callbacks_t callbacks; PyObject *Phandle, *Pcallbacks; if (!PyArg_ParseTuple(args, "O", &Pcallbacks)) return NULL; callbacks.cpg_deliver_fn = py_cpg_deliver_fn; callbacks.cpg_confchg_fn = py_cpg_confchg_fn; callbacks.cpg_groups_get_fn = py_cpg_groups_get_fn; ret = cpg_initialize(&handle, &callbacks); RETURN_ON_ERROR(ret, "cpg_initialize"); ret = py_cpg_add_callbacks(handle, Pcallbacks); if (ret == -1) return NULL; Phandle = PyLong_FromLong(handle); return Phandle; }
int main (void) { cpg_handle_t handle; unsigned int size; int i; unsigned int res; size = 1000; signal (SIGALRM, sigalrm_handler); res = cpg_initialize (&handle, &callbacks); if (res != CS_OK) { printf ("cpg_initialize failed with result %d\n", res); exit (1); } res = cpg_join (handle, &group_name); if (res != CS_OK) { printf ("cpg_join failed with result %d\n", res); exit (1); } for (i = 0; i < 50; i++) { /* number of repetitions - up to 50k */ cpg_benchmark (handle, size); signal (SIGALRM, sigalrm_handler); size += 1000; } res = cpg_finalize (handle); if (res != CS_OK) { printf ("cpg_join failed with result %d\n", res); exit (1); } return (0); }
gboolean cluster_connect_cpg(void) { cs_error_t rc; unsigned int nodeid; int fd; int retries = 0; static struct mainloop_fd_callbacks cpg_fd_callbacks = { .dispatch = pcmk_cpg_dispatch, .destroy = cpg_connection_destroy, }; strcpy(cpg_group.value, "pcmk"); cpg_group.length = strlen(cpg_group.value) + 1; retries = 0; cs_repeat(retries, 30, rc = cpg_initialize(&cpg_handle, &cpg_callbacks)); if (rc != CS_OK) { crm_err("corosync cpg init error %d", rc); return FALSE; } rc = cpg_fd_get(cpg_handle, &fd); if (rc != CS_OK) { crm_err("corosync cpg fd_get error %d", rc); goto bail; } retries = 0; cs_repeat(retries, 30, rc = cpg_local_get(cpg_handle, &nodeid)); if (rc != CS_OK) { crm_err("corosync cpg local_get error %d", rc); goto bail; } crm_debug("Our nodeid: %d", nodeid); retries = 0; cs_repeat(retries, 30, rc = cpg_join(cpg_handle, &cpg_group)); if (rc != CS_OK) { crm_err("Could not join the CPG group '%s': %d", crm_system_name, rc); goto bail; } mainloop_add_fd("corosync-cpg", G_PRIORITY_DEFAULT, fd, &cpg_handle, &cpg_fd_callbacks); return TRUE; bail: cpg_finalize(cpg_handle); return FALSE; }
int main (void) { cs_error_t res; cpg_handle_t handle; size_t buffer_lens[ALLOCATIONS]; void *buffers[ALLOCATIONS]; int i, j; printf ("stress cpgzc running %d allocations for %d iterations\n", ALLOCATIONS, ITERATIONS); signal (SIGINT, sigintr_handler); res = cpg_initialize (&handle, &callbacks); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } for (j = 0; j < ITERATIONS; j++) { for (i = 0; i < ALLOCATIONS; i++) { buffer_lens[i] = (random() % MAX_SIZE) + 1; res = cpg_zcb_alloc ( handle, buffer_lens[i], &buffers[i]); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } for (i = 0; i < ALLOCATIONS; i++) { res = cpg_zcb_free ( handle, buffers[i]); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } if ((j != 0) && (j % 20) == 0) { printf ("iteration %d\n", j); } } cpg_finalize (handle); printf ("PASS\n"); exit (0); }
int main (void) { cpg_handle_t handle[INSTANCES]; cs_error_t res; void *context[INSTANCES]; int i, j; void *ctx; signal (SIGINT, sigintr_handler); for (i = 0; i < INSTANCES; i++) { res = cpg_initialize (&handle[i], &callbacks); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } for (j = 0; j < ITERATIONS; j++) { for (i = 0; i < INSTANCES; i++) { context[i] = malloc (20); res = cpg_context_set (handle[i], context[i]); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } } for (i = 0; i < INSTANCES; i++) { res = cpg_context_get (handle[i], &ctx); if (res != CS_OK) { printf ("FAIL %d\n", res); exit (-1); } if (ctx != context[i]) { printf ("FAIL\n"); exit (-1); } free (ctx); } } for (i = 0; i < INSTANCES; i++) { cpg_finalize (handle[i]); } printf ("PASS\n"); return (0); }
int main (void) { cpg_handle_t handle; cs_error_t result; unsigned int i = 0; struct iovec iov; int res; unsigned int msg_size; result = cpg_initialize (&handle, &callbacks); if (result != CS_OK) { printf ("Couldn't initialize CPG service %d\n", result); exit (0); } res = cpg_join (handle, &group_name); if (res != CS_OK) { printf ("cpg_join failed with result %d\n", res); exit (1); } iov.iov_base = (void *)buffer; /* * Demonstrate cpg_mcast_joined */ msg_size = 1025000; for (i = 0; i < 1000000000; i++) { iov.iov_len = msg_size; try_again_one: result = cpg_mcast_joined (handle, CPG_TYPE_AGREED, &iov, 1); if (result == CS_ERR_TRY_AGAIN) { goto try_again_one; } if (result == CS_ERR_INVALID_PARAM) { printf ("found boundary at %d\n", msg_size); exit (1); } msg_size += 1; printf ("msg size %d\n", msg_size); result = cpg_dispatch (handle, CS_DISPATCH_ALL); } cpg_finalize (handle); return (0); }
uint32_t get_local_nodeid(cpg_handle_t handle) { int rc = CS_OK; int retries = 0; static uint32_t local_nodeid = 0; cpg_handle_t local_handle = handle; cpg_callbacks_t cb = { }; if(local_nodeid != 0) { return local_nodeid; } #if 0 /* Should not be necessary */ if(get_cluster_type() == pcmk_cluster_classic_ais) { get_ais_details(&local_nodeid, NULL); goto done; } #endif if(handle == 0) { crm_trace("Creating connection"); cs_repeat(retries, 5, rc = cpg_initialize(&local_handle, &cb)); } if (rc == CS_OK) { retries = 0; crm_trace("Performing lookup"); cs_repeat(retries, 5, rc = cpg_local_get(local_handle, &local_nodeid)); } if (rc != CS_OK) { crm_err("Could not get local node id from the CPG API: %s (%d)", ais_error2text(rc), rc); } if(handle == 0) { crm_trace("Closing connection"); cpg_finalize(local_handle); } crm_debug("Local nodeid is %u", local_nodeid); return local_nodeid; }
int main (void) { unsigned int size; int i; unsigned int res; qb_util_set_log_function(libqb_log_writer); size = 64; signal (SIGALRM, sigalrm_handler); res = cpg_initialize (&handle, &callbacks); if (res != CS_OK) { printf ("cpg_initialize failed with result %d\n", res); exit (1); } pthread_create (&thread, NULL, dispatch_thread, NULL); res = cpg_join (handle, &group_name); if (res != CS_OK) { printf ("cpg_join failed with result %d\n", res); exit (1); } for (i = 0; i < 10; i++) { /* number of repetitions - up to 50k */ cpg_benchmark (handle, size); signal (SIGALRM, sigalrm_handler); size *= 8; if (size >= (ONE_MEG - 100)) { break; } } res = cpg_finalize (handle); if (res != CS_OK) { printf ("cpg_finalize failed with result %d\n", res); exit (1); } return (0); }
/* * CFG functionality stolen from node_name() in corosync-quorumtool.c * This resolves the first address assigned to a node and returns the name or IP address. */ char * corosync_node_name(uint64_t /*cmap_handle_t */ cmap_handle, uint32_t nodeid) { int lpc = 0; int rc = CS_OK; int retries = 0; char *name = NULL; cmap_handle_t local_handle = 0; /* nodeid == 0 == CMAN_NODEID_US */ if (nodeid == 0 && pcmk_nodeid) { nodeid = pcmk_nodeid; } else if (nodeid == 0) { /* Look it up */ int rc = -1; int retries = 0; cpg_handle_t handle = 0; cpg_callbacks_t cb = { }; cs_repeat(retries, 5, rc = cpg_initialize(&handle, &cb)); if (rc == CS_OK) { retries = 0; cs_repeat(retries, 5, rc = cpg_local_get(handle, &pcmk_nodeid)); } if (rc != CS_OK) { crm_err("Could not get local node id from the CPG API: %d", rc); } cpg_finalize(handle); } if (cmap_handle == 0 && local_handle == 0) { retries = 0; crm_trace("Initializing CMAP connection"); do { rc = cmap_initialize(&local_handle); if (rc != CS_OK) { retries++; crm_debug("API connection setup failed: %s. Retrying in %ds", cs_strerror(rc), retries); sleep(retries); } } while (retries < 5 && rc != CS_OK); if (rc != CS_OK) { crm_warn("Could not connect to Cluster Configuration Database API, error %s", cs_strerror(rc)); local_handle = 0; } } if (cmap_handle == 0) { cmap_handle = local_handle; } while (name == NULL && cmap_handle != 0) { uint32_t id = 0; char *key = NULL; key = g_strdup_printf("nodelist.node.%d.nodeid", lpc); rc = cmap_get_uint32(cmap_handle, key, &id); crm_trace("Checking %u vs %u from %s", nodeid, id, key); g_free(key); if (rc != CS_OK) { break; } if (nodeid == id) { crm_trace("Searching for node name for %u in nodelist.node.%d %s", nodeid, lpc, name); if (name == NULL) { key = g_strdup_printf("nodelist.node.%d.ring0_addr", lpc); rc = cmap_get_string(cmap_handle, key, &name); crm_trace("%s = %s", key, name); if (node_name_is_valid(key, name) == FALSE) { free(name); name = NULL; } g_free(key); } if (name == NULL) { key = g_strdup_printf("nodelist.node.%d.name", lpc); rc = cmap_get_string(cmap_handle, key, &name); crm_trace("%s = %s %d", key, name, rc); g_free(key); } break; } lpc++; } if(local_handle) { cmap_finalize(local_handle); } if (name == NULL) { crm_notice("Unable to get node name for nodeid %u", nodeid); } return name; }
gboolean cluster_connect_cpg(crm_cluster_t *cluster) { int rc = -1; int fd = 0; int retries = 0; uint32_t id = 0; crm_node_t *peer = NULL; cpg_handle_t handle = 0; struct mainloop_fd_callbacks cpg_fd_callbacks = { .dispatch = pcmk_cpg_dispatch, .destroy = cluster->destroy, }; cpg_callbacks_t cpg_callbacks = { .cpg_deliver_fn = cluster->cpg.cpg_deliver_fn, .cpg_confchg_fn = cluster->cpg.cpg_confchg_fn, /* .cpg_deliver_fn = pcmk_cpg_deliver, */ /* .cpg_confchg_fn = pcmk_cpg_membership, */ }; cpg_evicted = FALSE; cluster->group.length = 0; cluster->group.value[0] = 0; /* group.value is char[128] */ strncpy(cluster->group.value, crm_system_name?crm_system_name:"unknown", 127); cluster->group.value[127] = 0; cluster->group.length = 1 + QB_MIN(127, strlen(cluster->group.value)); cs_repeat(retries, 30, rc = cpg_initialize(&handle, &cpg_callbacks)); if (rc != CS_OK) { crm_err("Could not connect to the Cluster Process Group API: %d", rc); goto bail; } id = get_local_nodeid(handle); if (id == 0) { crm_err("Could not get local node id from the CPG API"); goto bail; } cluster->nodeid = id; retries = 0; cs_repeat(retries, 30, rc = cpg_join(handle, &cluster->group)); if (rc != CS_OK) { crm_err("Could not join the CPG group '%s': %d", crm_system_name, rc); goto bail; } rc = cpg_fd_get(handle, &fd); if (rc != CS_OK) { crm_err("Could not obtain the CPG API connection: %d", rc); goto bail; } pcmk_cpg_handle = handle; cluster->cpg_handle = handle; mainloop_add_fd("corosync-cpg", G_PRIORITY_MEDIUM, fd, cluster, &cpg_fd_callbacks); bail: if (rc != CS_OK) { cpg_finalize(handle); return FALSE; } peer = crm_get_peer(id, NULL); crm_update_peer_proc(__FUNCTION__, peer, crm_proc_cpg, ONLINESTATUS); return TRUE; } gboolean send_cluster_message_cs(xmlNode * msg, gboolean local, crm_node_t * node, enum crm_ais_msg_types dest) { gboolean rc = TRUE; char *data = NULL; data = dump_xml_unformatted(msg); rc = send_cluster_text(crm_class_cluster, data, local, node, dest); free(data); return rc; } gboolean send_cluster_text(int class, const char *data, gboolean local, crm_node_t * node, enum crm_ais_msg_types dest) { static int msg_id = 0; static int local_pid = 0; static int local_name_len = 0; static const char *local_name = NULL; char *target = NULL; struct iovec *iov; AIS_Message *msg = NULL; enum crm_ais_msg_types sender = text2msg_type(crm_system_name); /* There are only 6 handlers registered to crm_lib_service in plugin.c */ CRM_CHECK(class < 6, crm_err("Invalid message class: %d", class); return FALSE); #if !SUPPORT_PLUGIN CRM_CHECK(dest != crm_msg_ais, return FALSE); #endif if(local_name == NULL) { local_name = get_local_node_name(); } if(local_name_len == 0 && local_name) { local_name_len = strlen(local_name); } if (data == NULL) { data = ""; } if (local_pid == 0) { local_pid = getpid(); } if (sender == crm_msg_none) { sender = local_pid; } msg = calloc(1, sizeof(AIS_Message)); msg_id++; msg->id = msg_id; msg->header.id = class; msg->header.error = CS_OK; msg->host.type = dest; msg->host.local = local; if (node) { if (node->uname) { target = strdup(node->uname); msg->host.size = strlen(node->uname); memset(msg->host.uname, 0, MAX_NAME); memcpy(msg->host.uname, node->uname, msg->host.size); } else { target = crm_strdup_printf("%u", node->id); } msg->host.id = node->id; } else { target = strdup("all"); } msg->sender.id = 0; msg->sender.type = sender; msg->sender.pid = local_pid; msg->sender.size = local_name_len; memset(msg->sender.uname, 0, MAX_NAME); if(local_name && msg->sender.size) { memcpy(msg->sender.uname, local_name, msg->sender.size); } msg->size = 1 + strlen(data); msg->header.size = sizeof(AIS_Message) + msg->size; if (msg->size < CRM_BZ2_THRESHOLD) { msg = realloc_safe(msg, msg->header.size); memcpy(msg->data, data, msg->size); } else { char *compressed = NULL; unsigned int new_size = 0; char *uncompressed = strdup(data); if (crm_compress_string(uncompressed, msg->size, 0, &compressed, &new_size)) { msg->header.size = sizeof(AIS_Message) + new_size; msg = realloc_safe(msg, msg->header.size); memcpy(msg->data, compressed, new_size); msg->is_compressed = TRUE; msg->compressed_size = new_size; } else { msg = realloc_safe(msg, msg->header.size); memcpy(msg->data, data, msg->size); } free(uncompressed); free(compressed); } iov = calloc(1, sizeof(struct iovec)); iov->iov_base = msg; iov->iov_len = msg->header.size; if (msg->compressed_size) { crm_trace("Queueing CPG message %u to %s (%llu bytes, %d bytes compressed payload): %.200s", msg->id, target, (unsigned long long) iov->iov_len, msg->compressed_size, data); } else { crm_trace("Queueing CPG message %u to %s (%llu bytes, %d bytes payload): %.200s", msg->id, target, (unsigned long long) iov->iov_len, msg->size, data); } free(target); #if SUPPORT_PLUGIN /* The plugin is the only time we dont use CPG messaging */ if(get_cluster_type() == pcmk_cluster_classic_ais) { return send_plugin_text(class, iov); } #endif send_cpg_iov(iov); return TRUE; } enum crm_ais_msg_types text2msg_type(const char *text) { int type = crm_msg_none; CRM_CHECK(text != NULL, return type); if (safe_str_eq(text, "ais")) { type = crm_msg_ais; } else if (safe_str_eq(text, "crm_plugin")) { type = crm_msg_ais; } else if (safe_str_eq(text, CRM_SYSTEM_CIB)) { type = crm_msg_cib; } else if (safe_str_eq(text, CRM_SYSTEM_CRMD)) { type = crm_msg_crmd; } else if (safe_str_eq(text, CRM_SYSTEM_DC)) { type = crm_msg_crmd; } else if (safe_str_eq(text, CRM_SYSTEM_TENGINE)) { type = crm_msg_te; } else if (safe_str_eq(text, CRM_SYSTEM_PENGINE)) { type = crm_msg_pe; } else if (safe_str_eq(text, CRM_SYSTEM_LRMD)) { type = crm_msg_lrmd; } else if (safe_str_eq(text, CRM_SYSTEM_STONITHD)) { type = crm_msg_stonithd; } else if (safe_str_eq(text, "stonith-ng")) { type = crm_msg_stonith_ng; } else if (safe_str_eq(text, "attrd")) { type = crm_msg_attrd; } else { /* This will normally be a transient client rather than * a cluster daemon. Set the type to the pid of the client */ int scan_rc = sscanf(text, "%d", &type); if (scan_rc != 1 || type <= crm_msg_stonith_ng) { /* Ensure it's sane */ type = crm_msg_none; } } return type; }
int main (int argc, char *argv[]) { cpg_handle_t handle; fd_set read_fds; int select_fd; int result; const char *options = "i"; int opt; unsigned int nodeid; char *fgets_res; while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 'i': show_ip = 1; break; } } if (argc > optind) { strcpy(group_name.value, argv[optind]); group_name.length = strlen(argv[optind]); } else { strcpy(group_name.value, "GROUP"); group_name.length = 6; } result = cpg_initialize (&handle, &callbacks); if (result != CS_OK) { printf ("Could not initialize Cluster Process Group API instance error %d\n", result); exit (1); } result = cpg_local_get (handle, &nodeid); if (result != CS_OK) { printf ("Could not get local node id\n"); exit (1); } printf ("Local node id is %x\n", nodeid); result = cpg_join(handle, &group_name); if (result != CS_OK) { printf ("Could not join process group, error %d\n", result); exit (1); } FD_ZERO (&read_fds); cpg_fd_get(handle, &select_fd); printf ("Type EXIT to finish\n"); do { FD_SET (select_fd, &read_fds); FD_SET (STDIN_FILENO, &read_fds); result = select (select_fd + 1, &read_fds, 0, 0, 0); if (result == -1) { perror ("select\n"); } if (FD_ISSET (STDIN_FILENO, &read_fds)) { char inbuf[132]; struct iovec iov; fgets_res = fgets(inbuf, sizeof(inbuf), stdin); if (fgets_res == NULL) { cpg_leave(handle, &group_name); } if (strncmp(inbuf, "EXIT", 4) == 0) { cpg_leave(handle, &group_name); } else { iov.iov_base = inbuf; iov.iov_len = strlen(inbuf)+1; cpg_mcast_joined(handle, CPG_TYPE_AGREED, &iov, 1); } } if (FD_ISSET (select_fd, &read_fds)) { if (cpg_dispatch (handle, CS_DISPATCH_ALL) != CS_OK) exit(1); } } while (result && !quit); result = cpg_finalize (handle); printf ("Finalize result is %d (should be 1)\n", result); return (0); }
static void do_command (int sock, char* func, char*args[], int num_args) { int result; char response[100]; struct cpg_name group_name; ssize_t rc; size_t send_len; qb_log (LOG_TRACE, "RPC:%s() called.", func); if (strcmp ("cpg_mcast_joined",func) == 0) { struct iovec iov[5]; int a; for (a = 0; a < num_args; a++) { iov[a].iov_base = args[a]; iov[a].iov_len = strlen(args[a])+1; } cpg_mcast_joined (cpg_handle, CPG_TYPE_AGREED, iov, num_args); } else if (strcmp ("cpg_join",func) == 0) { if (strlen(args[0]) >= CPG_MAX_NAME_LENGTH) { qb_log (LOG_ERR, "Invalid group name"); exit (1); } strcpy (group_name.value, args[0]); group_name.length = strlen(args[0]); result = cpg_join (cpg_handle, &group_name); if (result != CS_OK) { qb_log (LOG_ERR, "Could not join process group, error %d", result); exit (1); } qb_log (LOG_INFO, "called cpg_join(%s)!", group_name.value); } else if (strcmp ("cpg_leave",func) == 0) { strcpy (group_name.value, args[0]); group_name.length = strlen(args[0]); result = cpg_leave (cpg_handle, &group_name); if (result != CS_OK) { qb_log (LOG_ERR, "Could not leave process group, error %d", result); exit (1); } qb_log (LOG_INFO, "called cpg_leave(%s)!", group_name.value); } else if (strcmp ("cpg_initialize",func) == 0) { int retry_count = 0; result = cpg_initialize (&cpg_handle, &callbacks); while (result != CS_OK) { qb_log (LOG_ERR, "cpg_initialize error %d (attempt %d)", result, retry_count); if (retry_count >= 3) { exit (1); } sleep(1); retry_count++; result = cpg_initialize (&cpg_handle, &callbacks); } cpg_fd_get (cpg_handle, &cpg_fd); qb_loop_poll_add (ta_poll_handle_get(), QB_LOOP_MED, cpg_fd, POLLIN|POLLNVAL, NULL, cpg_dispatch_wrapper_fn); } else if (strcmp ("cpg_local_get", func) == 0) { unsigned int local_nodeid; cpg_local_get (cpg_handle, &local_nodeid); snprintf (response, 100, "%u",local_nodeid); send_len = strlen (response); rc = send (sock, response, send_len, 0); assert(rc == send_len); } else if (strcmp ("cpg_finalize", func) == 0) { if (cpg_handle > 0) { cpg_finalize (cpg_handle); cpg_handle = 0; } } else if (strcmp ("record_config_events", func) == 0) { record_config_events (sock); } else if (strcmp ("record_messages", func) == 0) { record_messages (); } else if (strcmp ("read_config_event", func) == 0) { read_config_event (sock); } else if (strcmp ("read_messages", func) == 0) { read_messages (sock, args[0]); } else if (strcmp ("msg_blaster_zcb", func) == 0) { msg_blaster_zcb (sock, args[0]); } else if (strcmp ("pcmk_test", func) == 0) { pcmk_test = 1; } else if (strcmp ("msg_blaster", func) == 0) { msg_blaster (sock, args[0]); } else if (strcmp ("context_test", func) == 0) { context_test (sock); } else if (strcmp ("are_you_ok_dude", func) == 0) { snprintf (response, 100, "%s", OK_STR); send_len = strlen (response); rc = send (sock, response, strlen (response), 0); assert(rc == send_len); } else if (strcmp ("cfg_shutdown", func) == 0) { qb_log (LOG_INFO, "calling %s() called!", func); result = corosync_cfg_try_shutdown (cfg_handle, COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST); qb_log (LOG_INFO,"%s() returned %d!", func, result); } else if (strcmp ("cfg_initialize",func) == 0) { int retry_count = 0; qb_log (LOG_INFO,"%s() called!", func); result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks); while (result != CS_OK) { qb_log (LOG_ERR, "cfg_initialize error %d (attempt %d)", result, retry_count); if (retry_count >= 3) { exit (1); } sleep(1); retry_count++; result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks); } qb_log (LOG_INFO,"corosync_cfg_initialize() == %d", result); result = corosync_cfg_fd_get (cfg_handle, &cfg_fd); qb_log (LOG_INFO,"corosync_cfg_fd_get() == %d", result); qb_loop_poll_add (ta_poll_handle_get(), QB_LOOP_MED, cfg_fd, POLLIN|POLLNVAL, NULL, cfg_dispatch_wrapper_fn); } else { qb_log(LOG_ERR, "RPC:%s not supported!", func); } }
int main (int argc, char *argv[]) { int i; unsigned int res; uint32_t maxsize; int opt; int bs; int write_size = 4096; int delay_time = 1000; int repetitions = 100; int print_time = 10; int have_size = 0; int listen_only = 0; int flood = 0; int model = 1; int option_index = 0; struct option long_options[] = { {"flood-start", required_argument, 0, 0 }, {"flood-mult", required_argument, 0, 0 }, {"flood-max", required_argument, 0, 0 }, {"size-kb", required_argument, 0, 'w' }, {"size-bytes", required_argument, 0, 'W' }, {"name", required_argument, 0, 'n' }, {"rtt", no_argument, 0, 't' }, {"flood", no_argument, 0, 'f' }, {"quiet", no_argument, 0, 'q' }, {"listen", no_argument, 0, 'l' }, {"help", no_argument, 0, '?' }, {0, 0, 0, 0 } }; while ( (opt = getopt_long(argc, argv, "qlstafMEn:d:r:p:m:w:W:D:", long_options, &option_index)) != -1 ) { switch (opt) { case 0: // Long-only options if (strcmp(long_options[option_index].name, "flood-start") == 0) { flood_start = parse_bytes(optarg); if (flood_start == 0) { fprintf(stderr, "flood-start value invalid\n"); exit(1); } } if (strcmp(long_options[option_index].name, "flood-mult") == 0) { flood_multiplier = parse_bytes(optarg); if (flood_multiplier == 0) { fprintf(stderr, "flood-mult value invalid\n"); exit(1); } } if (strcmp(long_options[option_index].name, "flood-max") == 0) { flood_max = parse_bytes(optarg); if (flood_max == 0) { fprintf(stderr, "flood-max value invalid\n"); exit(1); } } break; case 'w': // Write size in K bs = atoi(optarg); if (bs > 0) { write_size = bs*1024; have_size = 1; } break; case 'W': // Write size in bytes (or with a suffix) bs = parse_bytes(optarg); if (bs > 0) { write_size = bs; have_size = 1; } break; case 'n': if (strlen(optarg) >= CPG_MAX_NAME_LENGTH) { fprintf(stderr, "CPG name too long\n"); exit(1); } strcpy(group_name.value, optarg); group_name.length = strlen(group_name.value); break; case 't': report_rtt = 1; break; case 'E': to_stderr = 1; break; case 'M': machine_readable = 1; break; case 'f': flood = 1; break; case 'a': abort_on_error = 1; break; case 'd': delay_time = atoi(optarg); break; case 'D': delimiter = optarg[0]; break; case 'r': repetitions = atoi(optarg); break; case 'p': print_time = atoi(optarg); break; case 'l': listen_only = 1; break; case 's': do_syslog = 1; break; case 'q': quiet++; break; case 'm': model = atoi(optarg); if (model < 0 || model > 1) { fprintf(stderr, "%s: Model must be 0-1\n", argv[0]); exit(1); } break; case '?': usage(basename(argv[0])); exit(1); } } if (!have_size && flood) { write_size = flood_start; } signal (SIGALRM, sigalrm_handler); signal (SIGINT, sigint_handler); switch (model) { case 0: res = cpg_initialize (&handle, &callbacks); break; case 1: res = cpg_model_initialize (&handle, CPG_MODEL_V1, (cpg_model_data_t *)&model1_data, NULL); break; default: res=999; // can't get here but it keeps the compiler happy break; } if (res != CS_OK) { cpgh_log_printf(CPGH_LOG_ERR, "cpg_initialize failed with result %d\n", res); exit (1); } res = cpg_local_get(handle, &g_our_nodeid); if (res != CS_OK) { cpgh_log_printf(CPGH_LOG_ERR, "cpg_local_get failed with result %d\n", res); exit (1); } pthread_create (&thread, NULL, dispatch_thread, NULL); res = cpg_join (handle, &group_name); if (res != CS_OK) { cpgh_log_printf(CPGH_LOG_ERR, "cpg_join failed with result %d\n", res); exit (1); } if (listen_only) { int secs = 0; while (!stopped) { sleep(1); if (++secs > print_time && !quiet) { int nodes_printed = 0; if (!machine_readable) { for (i=1; i<MAX_NODEID; i++) { if (g_recv_counter[i]) { cpgh_log_printf(CPGH_LOG_INFO, "%s: %5d message%s of %d bytes received from node %d\n", group_name.value, g_recv_counter[i] - g_recv_start[i], g_recv_counter[i]==1?"":"s", g_recv_size[i], i); nodes_printed++; } } } /* Separate list of nodes if more than one */ if (nodes_printed > 1) { cpgh_log_printf(CPGH_LOG_INFO, "\n"); } secs = 0; } } } else { cpg_max_atomic_msgsize_get (handle, &maxsize); if (write_size > maxsize) { fprintf(stderr, "INFO: packet size (%d) is larger than the maximum atomic size (%d), libcpg will fragment\n", write_size, maxsize); } /* The main job starts here */ if (flood) { for (i = 0; i < 10; i++) { /* number of repetitions - up to 50k */ cpg_flood (handle, write_size); signal (SIGALRM, sigalrm_handler); write_size *= flood_multiplier; if (write_size > flood_max) { break; } } } else { send_counter = -1; /* So we start from zero to allow listeners to sync */ for (i = 0; i < repetitions && !stopped; i++) { cpg_test (handle, write_size, delay_time, print_time); signal (SIGALRM, sigalrm_handler); } } } res = cpg_finalize (handle); if (res != CS_OK) { cpgh_log_printf(CPGH_LOG_ERR, "cpg_finalize failed with result %d\n", res); exit (1); } if (quiet < 2) { /* Don't print LONG_MAX for min_rtt if we don't have a value */ if (min_rtt == LONG_MAX) { min_rtt = 0L; } if (machine_readable) { cpgh_log_printf(CPGH_LOG_STATS, "%d%c%d%c%d%c%d%c%d%c%d%c%d%c%ld%c%ld%c%ld\n", packets_sent, delimiter, send_fails, delimiter, send_retries, delimiter, length_errors, delimiter, packets_recvd, delimiter, sequence_errors, delimiter, crc_errors, delimiter, min_rtt, delimiter, avg_rtt, delimiter, max_rtt); } else { cpgh_log_printf(CPGH_LOG_STATS, "\n"); cpgh_log_printf(CPGH_LOG_STATS, "Stats:\n"); if (!listen_only) { cpgh_log_printf(CPGH_LOG_STATS, " packets sent: %d\n", packets_sent); cpgh_log_printf(CPGH_LOG_STATS, " send failures: %d\n", send_fails); cpgh_log_printf(CPGH_LOG_STATS, " send retries: %d\n", send_retries); } cpgh_log_printf(CPGH_LOG_STATS, " length errors: %d\n", length_errors); cpgh_log_printf(CPGH_LOG_STATS, " packets recvd: %d\n", packets_recvd); cpgh_log_printf(CPGH_LOG_STATS, " sequence errors: %d\n", sequence_errors); cpgh_log_printf(CPGH_LOG_STATS, " crc errors: %d\n", crc_errors); if (!listen_only) { cpgh_log_printf(CPGH_LOG_STATS, " min RTT: %ld\n", min_rtt); cpgh_log_printf(CPGH_LOG_STATS, " max RTT: %ld\n", max_rtt); cpgh_log_printf(CPGH_LOG_STATS, " avg RTT: %ld\n", avg_rtt); } cpgh_log_printf(CPGH_LOG_STATS, "\n"); } } res = 0; if (send_fails > 0 || (have_size && length_errors > 0) || sequence_errors > 0 || crc_errors > 0) { res = 2; } return (res); }
int main (int argc, char *argv[]) { const char *options = "hd:ne"; int opt; const char *prog_name = basename(argv[0]); char delimiter = 0; int escape = 1; operation_t operation = OPER_FULL_OUTPUT; int result; while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 'd': if (strlen (optarg) > 0) { delimiter = optarg[0]; } break; case 'n': operation = OPER_NAMES_ONLY; break; case 'e': escape = 0; break; case 'h': usage_do (prog_name); return (EXIT_SUCCESS); break; case '?': case ':': return (EXIT_FAILURE); break; } } result = cpg_initialize (&cpg_handle, NULL); if (result != CS_OK) { fprintf (stderr, "Could not initialize corosync cpg API error %d\n", result); return (EXIT_FAILURE); } result = corosync_cfg_initialize (&cfg_handle, NULL); if (result != CS_OK) { fprintf (stderr, "Could not initialize corosync configuration API error %d\n", result); return (EXIT_FAILURE); } switch (operation) { case OPER_NAMES_ONLY: result = display_groups (delimiter, escape); break; case OPER_FULL_OUTPUT: result = display_groups_with_members (delimiter, escape); break; } cpg_finalize (cpg_handle); corosync_cfg_finalize (cfg_handle); return (result ? EXIT_SUCCESS : EXIT_FAILURE); }
static int _init_cluster(void) { cs_error_t err; node_hash = dm_hash_create(100); err = cpg_initialize(&cpg_handle, &corosync_cpg_callbacks); if (err != CS_OK) { syslog(LOG_ERR, "Cannot initialise Corosync CPG service: %d", err); DEBUGLOG("Cannot initialise Corosync CPG service: %d", err); return cs_to_errno(err); } err = quorum_initialize(&quorum_handle, &quorum_callbacks); if (err != CS_OK) { syslog(LOG_ERR, "Cannot initialise Corosync quorum service: %d", err); DEBUGLOG("Cannot initialise Corosync quorum service: %d", err); return cs_to_errno(err); } /* Create a lockspace for LV & VG locks to live in */ lockspace = dlm_create_lockspace(LOCKSPACE_NAME, 0600); if (!lockspace) { if (errno == EEXIST) { lockspace = dlm_open_lockspace(LOCKSPACE_NAME); } if (!lockspace) { syslog(LOG_ERR, "Unable to create lockspace for CLVM: %m"); quorum_finalize(quorum_handle); return -1; } } dlm_ls_pthread_init(lockspace); DEBUGLOG("DLM initialisation complete\n"); /* Connect to the clvmd group */ strcpy((char *)cpg_group_name.value, "clvmd"); cpg_group_name.length = strlen((char *)cpg_group_name.value); err = cpg_join(cpg_handle, &cpg_group_name); if (err != CS_OK) { cpg_finalize(cpg_handle); quorum_finalize(quorum_handle); dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1); syslog(LOG_ERR, "Cannot join clvmd process group"); DEBUGLOG("Cannot join clvmd process group: %d\n", err); return cs_to_errno(err); } err = cpg_local_get(cpg_handle, &our_nodeid); if (err != CS_OK) { cpg_finalize(cpg_handle); quorum_finalize(quorum_handle); dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1); syslog(LOG_ERR, "Cannot get local node id\n"); return cs_to_errno(err); } DEBUGLOG("Our local node id is %d\n", our_nodeid); DEBUGLOG("Connected to Corosync\n"); return 0; }
int main (int argc, char *argv[]) { cpg_handle_t handle; cs_error_t result; int i = 0; int j; struct my_msg msg; struct iovec iov[2]; const char *options = "i:"; int iter = 1000; int opt; int run_forever = 1; unsigned int sha1_len; while ((opt = getopt(argc, argv, options)) != -1) { switch (opt) { case 'i': run_forever = 0; iter = atoi(optarg); break; } } result = cpg_initialize (&handle, &callbacks); if (result != CS_OK) { printf ("Couldn't initialize CPG service %d\n", result); exit (0); } if (NSS_NoDB_Init(".") != SECSuccess) { printf ("Couldn't initialize nss\n"); exit (0); } if ((sha1_context = PK11_CreateDigestContext(SEC_OID_SHA1)) == NULL) { printf ("Couldn't initialize nss\n"); exit (0); } result = cpg_join (handle, &group_name); if (result != CS_OK) { printf ("cpg_join failed with result %d\n", result); exit (1); } iov[0].iov_base = (void *)&msg; iov[0].iov_len = sizeof (struct my_msg); iov[1].iov_base = (void *)buffer; /* * Demonstrate cpg_mcast_joined */ i = 0; do { msg.msg_size = 100 + rand() % 100000; iov[1].iov_len = msg.msg_size; for (j = 0; j < msg.msg_size; j++) { buffer[j] = j; } sprintf ((char *)buffer, "cpg_mcast_joined: This is message %12d", i); PK11_DigestBegin(sha1_context); PK11_DigestOp(sha1_context, buffer, msg.msg_size); PK11_DigestFinal(sha1_context, msg.sha1, &sha1_len, sizeof(msg.sha1)); try_again_one: result = cpg_mcast_joined (handle, CPG_TYPE_AGREED, iov, 2); if (result == CS_ERR_TRY_AGAIN) { goto try_again_one; } result = cpg_dispatch (handle, CS_DISPATCH_ALL); i++; } while (run_forever || i < iter); PK11_DestroyContext(sha1_context, PR_TRUE); cpg_finalize (handle); return (0); }
int main (int argc, char *argv[]) { int i; unsigned int res; uint32_t maxsize; int opt; int bs; int write_size = 4096; int delay_time = 1000; int repetitions = 100; int print_time = 10; int have_size = 0; int listen_only = 0; int model = 1; while ( (opt = getopt(argc, argv, "qlsn:d:r:p:m:w:W:")) != -1 ) { switch (opt) { case 'w': // Write size in K bs = atoi(optarg); if (bs > 0) { write_size = bs*1024; have_size = 1; } break; case 'W': // Write size in bytes bs = atoi(optarg); if (bs > 0) { write_size = bs; have_size = 1; } break; case 'n': strcpy(group_name.value, optarg); group_name.length = strlen(group_name.value); break; case 'd': delay_time = atoi(optarg); break; case 'r': repetitions = atoi(optarg); break; case 'p': print_time = atoi(optarg); break; case 'l': listen_only = 1; break; case 's': do_syslog = 1; break; case 'q': quiet = 1; break; case 'm': model = atoi(optarg); if (model < 0 || model > 1) { fprintf(stderr, "%s: Model must be 0-1\n", argv[0]); exit(1); } break; case '?': usage(basename(argv[0])); exit(0); } } qb_log_init("cpghum", LOG_USER, LOG_EMERG); qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD, QB_LOG_FILTER_FILE, "*", LOG_DEBUG); qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE); g_write_size = write_size; signal (SIGALRM, sigalrm_handler); signal (SIGINT, sigint_handler); switch (model) { case 0: res = cpg_initialize (&handle, &callbacks); break; case 1: res = cpg_model_initialize (&handle, CPG_MODEL_V1, (cpg_model_data_t *)&model1_data, NULL); break; default: res=999; // can't get here but it keeps the compiler happy break; } if (res != CS_OK) { printf ("cpg_initialize failed with result %d\n", res); exit (1); } pthread_create (&thread, NULL, dispatch_thread, NULL); res = cpg_join (handle, &group_name); if (res != CS_OK) { printf ("cpg_join failed with result %d\n", res); exit (1); } if (listen_only) { int secs; if (!quiet) { printf("-- Listening on CPG %s\n", group_name.value); printf("-- Ignore any starting \"counters don't match\" error while we catch up\n"); } /* Only check packet size if specified on the command-line */ if (!have_size) { g_write_size = 0; } while (!stopped) { sleep(1); if (++secs > print_time && !quiet) { printf ("%s: %5d message%s received. %d bytes\n", group_name.value, g_recv_count, g_recv_count==1?"":"s", g_recv_length); secs = 0; g_recv_count = 0; } } } else { cpg_max_atomic_msgsize_get (handle, &maxsize); if ( write_size > maxsize) { fprintf(stderr, "INFO: packet size (%d) is larger than the maximum atomic size (%d), libcpg will fragment\n", write_size, maxsize); } for (i = 0; i < repetitions && !stopped; i++) { cpg_test (handle, write_size, delay_time, print_time); signal (SIGALRM, sigalrm_handler); } } res = cpg_finalize (handle); if (res != CS_OK) { printf ("cpg_finalize failed with result %d\n", res); exit (1); } printf("\n"); printf("Stats:\n"); if (!listen_only) { printf(" packets sent: %d\n", packets_sent); printf(" send failures: %d\n", send_fails); printf(" send retries: %d\n", send_retries); } if (have_size) { printf(" length errors: %d\n", length_errors); } printf(" packets recvd: %d\n", packets_recvd); printf(" sequence errors: %d\n", sequence_errors); printf(" crc errors: %d\n", crc_errors); printf("\n"); return (0); }
static int _init_cluster(void) { cs_error_t err; #ifdef QUORUM_SET /* corosync/quorum.h */ uint32_t quorum_type; #endif node_hash = dm_hash_create(100); err = cpg_initialize(&cpg_handle, &corosync_cpg_callbacks); if (err != CS_OK) { syslog(LOG_ERR, "Cannot initialise Corosync CPG service: %d", err); DEBUGLOG("Cannot initialise Corosync CPG service: %d", err); return cs_to_errno(err); } #ifdef QUORUM_SET err = quorum_initialize(&quorum_handle, &quorum_callbacks, &quorum_type); if (quorum_type != QUORUM_SET) { syslog(LOG_ERR, "Corosync quorum service is not configured"); DEBUGLOG("Corosync quorum service is not configured"); return EINVAL; } #else err = quorum_initialize(&quorum_handle, &quorum_callbacks); #endif if (err != CS_OK) { syslog(LOG_ERR, "Cannot initialise Corosync quorum service: %d", err); DEBUGLOG("Cannot initialise Corosync quorum service: %d", err); return cs_to_errno(err); } /* Create a lockspace for LV & VG locks to live in */ lockspace = dlm_open_lockspace(LOCKSPACE_NAME); if (!lockspace) { lockspace = dlm_create_lockspace(LOCKSPACE_NAME, 0600); if (!lockspace) { syslog(LOG_ERR, "Unable to create DLM lockspace for CLVM: %m"); return -1; } DEBUGLOG("Created DLM lockspace for CLVMD.\n"); } else DEBUGLOG("Opened existing DLM lockspace for CLVMD.\n"); dlm_ls_pthread_init(lockspace); DEBUGLOG("DLM initialisation complete\n"); /* Connect to the clvmd group */ strcpy((char *)cpg_group_name.value, "clvmd"); cpg_group_name.length = strlen((char *)cpg_group_name.value); err = cpg_join(cpg_handle, &cpg_group_name); if (err != CS_OK) { cpg_finalize(cpg_handle); quorum_finalize(quorum_handle); dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1); syslog(LOG_ERR, "Cannot join clvmd process group"); DEBUGLOG("Cannot join clvmd process group: %d\n", err); return cs_to_errno(err); } err = cpg_local_get(cpg_handle, &our_nodeid); if (err != CS_OK) { cpg_finalize(cpg_handle); quorum_finalize(quorum_handle); dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1); syslog(LOG_ERR, "Cannot get local node id\n"); return cs_to_errno(err); } DEBUGLOG("Our local node id is %d\n", our_nodeid); DEBUGLOG("Connected to Corosync\n"); return 0; }
static void do_command (int sock, char* func, char*args[], int num_args) { int result; char response[100]; struct cpg_name group_name; if (parse_debug) syslog (LOG_DEBUG,"RPC:%s() called.", func); if (strcmp ("cpg_mcast_joined",func) == 0) { struct iovec iov[5]; int a; for (a = 0; a < num_args; a++) { iov[a].iov_base = args[a]; iov[a].iov_len = strlen(args[a])+1; } cpg_mcast_joined (cpg_handle, CPG_TYPE_AGREED, iov, num_args); } else if (strcmp ("cpg_join",func) == 0) { strcpy (group_name.value, args[0]); group_name.length = strlen(args[0]); result = cpg_join (cpg_handle, &group_name); if (result != CS_OK) { syslog (LOG_ERR, "Could not join process group, error %d\n", result); exit (1); } syslog (LOG_INFO, "called cpg_join()!"); } else if (strcmp ("cpg_leave",func) == 0) { strcpy (group_name.value, args[0]); group_name.length = strlen(args[0]); result = cpg_leave (cpg_handle, &group_name); if (result != CS_OK) { syslog (LOG_ERR, "Could not leave process group, error %d\n", result); exit (1); } syslog (LOG_INFO, "called cpg_leave()!"); } else if (strcmp ("cpg_initialize",func) == 0) { int retry_count = 0; result = cpg_initialize (&cpg_handle, &callbacks); while (result != CS_OK) { syslog (LOG_ERR, "cpg_initialize error %d (attempt %d)\n", result, retry_count); if (retry_count >= 3) { exit (1); } sleep(1); retry_count++; result = cpg_initialize (&cpg_handle, &callbacks); } cpg_fd_get (cpg_handle, &cpg_fd); poll_dispatch_add (ta_poll_handle_get(), cpg_fd, POLLIN|POLLNVAL, NULL, cpg_dispatch_wrapper_fn); } else if (strcmp ("cpg_local_get", func) == 0) { unsigned int local_nodeid; cpg_local_get (cpg_handle, &local_nodeid); snprintf (response, 100, "%u",local_nodeid); send (sock, response, strlen (response), 0); } else if (strcmp ("cpg_finalize", func) == 0) { cpg_finalize (cpg_handle); poll_dispatch_delete (ta_poll_handle_get(), cpg_fd); cpg_fd = -1; } else if (strcmp ("record_config_events", func) == 0) { record_config_events (sock); } else if (strcmp ("record_messages", func) == 0) { record_messages (); } else if (strcmp ("read_config_event", func) == 0) { read_config_event (sock); } else if (strcmp ("read_messages", func) == 0) { read_messages (sock, args[0]); } else if (strcmp ("msg_blaster_zcb", func) == 0) { msg_blaster_zcb (sock, args[0]); } else if (strcmp ("pcmk_test", func) == 0) { pcmk_test = 1; } else if (strcmp ("msg_blaster", func) == 0) { msg_blaster (sock, args[0]); } else if (strcmp ("context_test", func) == 0) { context_test (sock); } else if (strcmp ("are_you_ok_dude", func) == 0) { snprintf (response, 100, "%s", OK_STR); send (sock, response, strlen (response), 0); } else if (strcmp ("cfg_shutdown", func) == 0) { corosync_cfg_try_shutdown (cfg_handle, COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST); } else if (strcmp ("cfg_initialize",func) == 0) { int retry_count = 0; syslog (LOG_INFO,"%s %s() called!", __func__, func); result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks); while (result != CS_OK) { syslog (LOG_ERR, "cfg_initialize error %d (attempt %d)\n", result, retry_count); if (retry_count >= 3) { exit (1); } sleep(1); retry_count++; result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks); } corosync_cfg_fd_get (cfg_handle, &cfg_fd); corosync_cfg_state_track (cfg_handle, 0, ¬ification_buffer); poll_dispatch_add (ta_poll_handle_get(), cfg_fd, POLLIN|POLLNVAL, NULL, cfg_dispatch_wrapper_fn); } else { syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func); } }