static void my_pre_exit(void) { qb_log (LOG_INFO, "PRE EXIT"); if (vq_handle) { votequorum_finalize(vq_handle); vq_handle = 0; } if (q_handle) { quorum_finalize(q_handle); q_handle = 0; } }
int main(int argc, char *argv[]) { int ret = 0; #ifdef EXPERIMENTAL_QUORUM_DEVICE_API int pollcount=0, polltime=1; int err; if ( (err=votequorum_initialize(&handle, NULL)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d\n", err); return -1; } print_info(1); if (argc >= 2 && atoi(argv[1])) { pollcount = atoi(argv[1]); } if (argc >= 3 && atoi(argv[2])) { polltime = atoi(argv[2]); } if (argc >= 2) { if ( (err=votequorum_qdevice_register(handle, "QDEVICE")) != CS_OK) { fprintf(stderr, "qdevice_register FAILED: %d\n", err); ret = -1; goto out; } while (pollcount--) { print_info(0); if ((err=votequorum_qdevice_poll(handle, "QDEVICE", 1)) != CS_OK) { fprintf(stderr, "qdevice poll FAILED: %d\n", err); ret = -1; goto out; } print_info(0); sleep(polltime); } if ((err= votequorum_qdevice_unregister(handle, "QDEVICE")) != CS_OK) { fprintf(stderr, "qdevice unregister FAILED: %d\n", err); ret = -1; goto out; } } print_info(1); out: votequorum_finalize(handle); #else fprintf(stderr, "qdevice support is not built in corosync/votequorum\n"); #endif return ret; }
static void close_all(void) { if (cmap_handle) { cmap_finalize(cmap_handle); } if (q_handle) { quorum_finalize(q_handle); } if (c_handle) { corosync_cfg_finalize(c_handle); } if (v_handle) { votequorum_finalize(v_handle); } }
static int vq_dispatch_wrapper_fn ( int fd, int revents, void *data) { cs_error_t error = votequorum_dispatch (vq_handle, CS_DISPATCH_ALL); if (error != CS_OK) { qb_log (LOG_ERR, "got %s error, disconnecting.", cs_strerror(error)); votequorum_finalize(vq_handle); vq_handle = 0; return -1; } return 0; }
static int set_expected(int expected_votes) { votequorum_handle_t v_handle; votequorum_callbacks_t v_callbacks; int err; v_callbacks.votequorum_notify_fn = NULL; v_callbacks.votequorum_expectedvotes_notify_fn = NULL; if ( (err=votequorum_initialize(&v_handle, &v_callbacks)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d, this is probably a configuration error\n", err); return err; } if ( (err=votequorum_setexpected(v_handle, expected_votes)) != CS_OK) fprintf(stderr, "set expected votes FAILED: %d\n", err); votequorum_finalize(v_handle); return err==CS_OK?0:err; }
int main(int argc, char *argv[]) { int ret = 0; int cast_vote = 1, master_wins = 0; int pollcount=0, polltime=1, quiet=0, once=0; int err; int opt; const char *devicename = "QDEVICE"; const char *options = "n:p:t:cmq1h"; while ((opt = getopt(argc, argv, options)) != -1) { switch (opt) { case 'm': master_wins = 1; break; case 'c': cast_vote = 1; break; case '1': once = 1; break; case 'q': quiet = 1; break; case 'p': pollcount = atoi(optarg)+1; break; case 'n': devicename = strdup(optarg); break; case 't': polltime = atoi(optarg); break; case 'h': usage(argv[0]); exit(0); } } if ( (err=votequorum_initialize(&handle, NULL)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d\n", err); return -1; } if (quiet && once) { fprintf(stderr, "setting both -q (quet) and -1 (once) makes no sense\n"); usage(argv[0]); exit(1); } if (!quiet) { print_info(1); } if (once) { exit(0); } if (argc >= 2) { if ( (err=votequorum_qdevice_register(handle, devicename)) != CS_OK) { fprintf(stderr, "qdevice_register FAILED: %d\n", err); ret = -1; goto out; } if ( (err=votequorum_qdevice_master_wins(handle, devicename, master_wins)) != CS_OK) { fprintf(stderr, "qdevice_master_wins FAILED: %d\n", err); ret = -1; goto out; } while (--pollcount) { if (!quiet) print_info(0); if ((err=votequorum_qdevice_poll(handle, devicename, cast_vote)) != CS_OK) { fprintf(stderr, "qdevice poll FAILED: %d\n", err); ret = -1; goto out; } if (!quiet) print_info(0); sleep(polltime); } if ((err= votequorum_qdevice_unregister(handle, devicename)) != CS_OK) { fprintf(stderr, "qdevice unregister FAILED: %d\n", err); ret = -1; goto out; } } if (!quiet) print_info(1); out: votequorum_finalize(handle); return ret; }
static int show_nodes(nodeid_format_t nodeid_format, name_format_t name_format) { quorum_handle_t q_handle = 0; votequorum_handle_t v_handle = 0; corosync_cfg_handle_t c_handle = 0; corosync_cfg_callbacks_t c_callbacks; int i; int using_vq = 0; quorum_callbacks_t q_callbacks; votequorum_callbacks_t v_callbacks; int err; int result = EXIT_FAILURE; q_callbacks.quorum_notify_fn = quorum_notification_fn; err=quorum_initialize(&q_handle, &q_callbacks); if (err != CS_OK) { fprintf(stderr, "Cannot connect to quorum service, is it loaded?\n"); return result; } v_callbacks.votequorum_notify_fn = NULL; v_callbacks.votequorum_expectedvotes_notify_fn = NULL; using_vq = using_votequorum(); if (using_vq) { if ( (err=votequorum_initialize(&v_handle, &v_callbacks)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d, this is probably a configuration error\n", err); v_handle = 0; goto err_exit; } } err = quorum_trackstart(q_handle, CS_TRACK_CURRENT); if (err != CS_OK) { fprintf(stderr, "quorum_trackstart FAILED: %d\n", err); goto err_exit; } g_called = 0; while (g_called == 0) quorum_dispatch(q_handle, CS_DISPATCH_ONE); quorum_finalize(q_handle); q_handle = 0; err = corosync_cfg_initialize(&c_handle, &c_callbacks); if (err != CS_OK) { fprintf(stderr, "Cannot initialise CFG service\n"); c_handle = 0; goto err_exit; } if (using_vq) printf("Nodeid Votes Name\n"); else printf("Nodeid Name\n"); for (i=0; i < g_view_list_entries; i++) { if (nodeid_format == NODEID_FORMAT_DECIMAL) { printf("%4u ", g_view_list[i]); } else { printf("0x%04x ", g_view_list[i]); } if (using_vq) { printf("%3d %s\n", get_votes(v_handle, g_view_list[i]), node_name(c_handle, g_view_list[i], name_format)); } else { printf("%s\n", node_name(c_handle, g_view_list[i], name_format)); } } result = EXIT_SUCCESS; err_exit: if (q_handle != 0) { quorum_finalize (q_handle); } if (using_vq && v_handle != 0) { votequorum_finalize (v_handle); } if (c_handle != 0) { corosync_cfg_finalize (c_handle); } return result; }
int main(int argc, char *argv[]) { int ret = 0; int cast_vote = 1, master_wins = 0; int pollcount=0, polltime=1, quiet=0, once=0; int send_old_ringid = 0; int err; int opt; votequorum_callbacks_t callbacks; const char *devicename = "QDEVICE"; const char *options = "F:n:p:t:cmq1h"; memset(&callbacks, 0, sizeof(callbacks)); callbacks.votequorum_notify_fn = votequorum_notification_fn; while ((opt = getopt(argc, argv, options)) != -1) { switch (opt) { case 'm': master_wins = 1; break; case 'c': cast_vote = 1; break; case '1': once = 1; break; case 'q': quiet = 1; break; case 'F': send_old_ringid = atoi(optarg)+1; break; case 'p': pollcount = atoi(optarg)+1; break; case 'n': devicename = strdup(optarg); break; case 't': polltime = atoi(optarg); break; case 'h': usage(argv[0]); exit(0); } } if ( (err=votequorum_initialize(&handle, &callbacks)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d\n", err); return -1; } if (quiet && once) { fprintf(stderr, "setting both -q (quet) and -1 (once) makes no sense\n"); usage(argv[0]); exit(1); } if (!quiet) { print_info(1); } if (once) { exit(0); } if (argc >= 2) { if ( (err = votequorum_trackstart(handle, handle, CS_TRACK_CHANGES)) != CS_OK) { fprintf(stderr, "votequorum_trackstart FAILED: %d\n", err); ret = -1; goto out; } if ( (err=votequorum_qdevice_register(handle, devicename)) != CS_OK) { fprintf(stderr, "qdevice_register FAILED: %d\n", err); ret = -1; goto out; } if ( (err=votequorum_qdevice_master_wins(handle, devicename, master_wins)) != CS_OK) { fprintf(stderr, "qdevice_master_wins FAILED: %d\n", err); ret = -1; goto out; } while (--pollcount) { if (votequorum_dispatch(handle, CS_DISPATCH_ALL) != CS_OK) { fprintf(stderr, "votequorum_dispatch error\n"); ret = -1; goto out; } if (!quiet) print_info(0); if (no_sent_old_ringid + 1 >= send_old_ringid) { /* * Finally send correct ringid */ memcpy(&ring_id_to_send, &last_received_ring_id, sizeof(ring_id_to_send)); } else { no_sent_old_ringid++; } if ((err=votequorum_qdevice_poll(handle, devicename, cast_vote, ring_id_to_send)) != CS_OK && err != CS_ERR_MESSAGE_ERROR) { fprintf(stderr, "qdevice poll FAILED: %d\n", err); ret = -1; goto out; } if (err == CS_ERR_MESSAGE_ERROR) { fprintf(stderr, "qdevice poll passed OLD ring_id\n"); } if (!quiet) print_info(0); sleep(polltime); } if ((err= votequorum_qdevice_unregister(handle, devicename)) != CS_OK) { fprintf(stderr, "qdevice unregister FAILED: %d\n", err); ret = -1; goto out; } } if (!quiet) print_info(1); out: votequorum_finalize(handle); return ret; }
int main(int argc, char *argv[]) { int ret = 0; int cast_vote = 1, master_wins = 1; int pollcount=0, polltime=1; int err; if ( (err=votequorum_initialize(&handle, NULL)) != CS_OK) { fprintf(stderr, "votequorum_initialize FAILED: %d\n", err); return -1; } print_info(1); if (argc >= 2 && atoi(argv[1])) { pollcount = atoi(argv[1]); } if (argc >= 3 && atoi(argv[2])) { polltime = atoi(argv[2]); } if (argc >= 4) { cast_vote = atoi(argv[3]); } if (argc >= 5) { master_wins = atoi(argv[4]); } if (argc >= 2) { if ( (err=votequorum_qdevice_register(handle, "QDEVICE")) != CS_OK) { fprintf(stderr, "qdevice_register FAILED: %d\n", err); ret = -1; goto out; } if ( (err=votequorum_qdevice_master_wins(handle, "QDEVICE", master_wins)) != CS_OK) { fprintf(stderr, "qdevice_master_wins FAILED: %d\n", err); ret = -1; goto out; } while (pollcount--) { print_info(0); if ((err=votequorum_qdevice_poll(handle, "QDEVICE", cast_vote)) != CS_OK) { fprintf(stderr, "qdevice poll FAILED: %d\n", err); ret = -1; goto out; } print_info(0); sleep(polltime); } if ((err= votequorum_qdevice_unregister(handle, "QDEVICE")) != CS_OK) { fprintf(stderr, "qdevice unregister FAILED: %d\n", err); ret = -1; goto out; } } print_info(1); out: votequorum_finalize(handle); return ret; }