static int monitor_status(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type) { int err; int loop = 0; if (q_type == QUORUM_FREE) { printf("\nQuorum is not configured - cannot monitor\n"); return show_status(nodeid_format, name_format, sort_type); } err=quorum_trackstart(q_handle, CS_TRACK_CHANGES); if (err != CS_OK) { fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err)); goto quorum_err; } if (using_votequorum()) { if ( (err=votequorum_trackstart(v_handle, 0LL, CS_TRACK_CHANGES)) != CS_OK) { fprintf(stderr, "Unable to start votequorum status tracking: %s\n", cs_strerror(err)); goto quorum_err; } } while (1) { err = quorum_dispatch(q_handle, CS_DISPATCH_ONE); if (err != CS_OK) { fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err)); goto quorum_err; } if (using_votequorum()) { g_vq_called = 0; while (!g_vq_called) { err = votequorum_dispatch(v_handle, CS_DISPATCH_ONE); if (err != CS_OK) { fprintf(stderr, "Unable to dispatch votequorum status: %s\n", cs_strerror(err)); goto quorum_err; } } } err = display_quorum_data(g_quorate, nodeid_format, name_format, sort_type, loop); printf("\n"); loop = 1; if (err != CS_OK) { fprintf(stderr, "Unable to display quorum data: %s\n", cs_strerror(err)); goto quorum_err; } } quorum_err: return -1; }
/* * return 1 if quorate * 0 if not quorate * -1 on error */ static int show_status(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type) { int is_quorate; int err; err=quorum_getquorate(q_handle, &is_quorate); if (err != CS_OK) { fprintf(stderr, "Unable to get cluster quorate status: %s\n", cs_strerror(err)); goto quorum_err; } err=quorum_trackstart(q_handle, CS_TRACK_CURRENT); if (err != CS_OK) { fprintf(stderr, "Unable to start quorum status tracking: %s\n", cs_strerror(err)); goto quorum_err; } g_called = 0; while (g_called == 0 && err == CS_OK) { err = quorum_dispatch(q_handle, CS_DISPATCH_ONE); if (err != CS_OK) { fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err)); } } if (quorum_trackstop(q_handle) != CS_OK) { fprintf(stderr, "Unable to stop quorum status tracking: %s\n", cs_strerror(err)); } if (using_votequorum()) { if ( (err=votequorum_trackstart(v_handle, 0LL, CS_TRACK_CURRENT)) != CS_OK) { fprintf(stderr, "Unable to start votequorum status tracking: %s\n", cs_strerror(err)); goto quorum_err; } g_vq_called = 0; while (g_vq_called == 0 && err == CS_OK) { err = votequorum_dispatch(v_handle, CS_DISPATCH_ONE); if (err != CS_OK) { fprintf(stderr, "Unable to dispatch votequorum status: %s\n", cs_strerror(err)); } } } quorum_err: if (err != CS_OK) { return -1; } err = display_quorum_data(is_quorate, nodeid_format, name_format, sort_type, 0); if (err != CS_OK) { return -1; } return is_quorate; }
static int init_all(void) { cmap_handle = 0; q_handle = 0; v_handle = 0; c_handle = 0; if (cmap_initialize(&cmap_handle) != CS_OK) { fprintf(stderr, "Cannot initialize CMAP service\n"); cmap_handle = 0; goto out; } if (quorum_initialize(&q_handle, &q_callbacks, &q_type) != CS_OK) { fprintf(stderr, "Cannot initialize QUORUM service\n"); q_handle = 0; goto out; } if (corosync_cfg_initialize(&c_handle, &c_callbacks) != CS_OK) { fprintf(stderr, "Cannot initialise CFG service\n"); c_handle = 0; goto out; } if (using_votequorum() <= 0) { return 0; } if (votequorum_initialize(&v_handle, &v_callbacks) != CS_OK) { fprintf(stderr, "Cannot initialise VOTEQUORUM service\n"); v_handle = 0; goto out; } if (cmap_get_uint32(cmap_handle, "runtime.votequorum.this_node_id", &our_nodeid) != CS_OK) { fprintf(stderr, "Unable to retrieve this_node_id\n"); goto out; } return 0; out: return -1; }
int main (int argc, char *argv[]) { const char *options = "VHaslpmfe:v:hin:o:"; char *endptr; int opt; int votes = 0; int ret = 0; uint32_t nodeid = 0; uint32_t nodeid_set = 0; nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL; name_format_t address_format = ADDRESS_FORMAT_NAME; command_t command_opt = CMD_SHOWSTATUS; sorttype_t sort_opt = SORT_ADDR; char sortchar; long int l; if (init_all()) { close_all(); exit(1); } while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 'f': if (using_votequorum() > 0) { command_opt = CMD_UNREGISTER_QDEVICE; } else { fprintf(stderr, "You cannot unregister quorum device, corosync is not using votequorum\n"); exit(2); } break; case 's': command_opt = CMD_SHOWSTATUS; break; case 'a': g_show_all_addrs = 1; break; case 'm': command_opt = CMD_MONITOR; break; case 'i': address_format = ADDRESS_FORMAT_IP; break; case 'H': nodeid_format = NODEID_FORMAT_HEX; break; case 'l': command_opt = CMD_SHOWNODES; break; case 'p': machine_parsable = 1; break; case 'e': if (using_votequorum() > 0) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes <= 0) { fprintf(stderr, "New expected votes value was not valid, try a positive number\n"); } else { command_opt = CMD_SETEXPECTED; } } else { fprintf(stderr, "You cannot change expected votes, corosync is not using votequorum\n"); exit(2); } break; case 'n': l = strtol(optarg, &endptr, 0); if ((l == 0 && endptr == optarg) || l < 0) { fprintf(stderr, "The nodeid was not valid, try a positive number\n"); exit(2); } nodeid = l; nodeid_set = 1; break; case 'v': if (using_votequorum() > 0) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes < 0) { fprintf(stderr, "New votes value was not valid, try a positive number or zero\n"); exit(2); } else { command_opt = CMD_SETVOTES; } } else { fprintf(stderr, "You cannot change node votes, corosync is not using votequorum\n"); exit(2); } break; case 'o': sortchar = optarg[0]; switch (sortchar) { case 'a': sort_opt = SORT_ADDR; break; case 'i': sort_opt = SORT_NODEID; break; case 'n': sort_opt = SORT_NODENAME; break; default: fprintf(stderr, "Invalid ordering option. valid orders are a(address), i(node ID) or n(name)\n"); exit(2); break; } break; case 'V': printf("corosync-quorumtool version: %s\n", VERSION); exit(0); case ':': case 'h': case '?': default: command_opt = CMD_UNKNOWN; break; } } switch (command_opt) { case CMD_UNKNOWN: show_usage(argv[0]); ret = -1; break; case CMD_SHOWNODES: ret = show_nodes(nodeid_format, address_format, sort_opt); break; case CMD_SHOWSTATUS: ret = show_status(nodeid_format, address_format, sort_opt); break; case CMD_SETVOTES: if (!nodeid_set) { nodeid = our_nodeid; } ret = set_votes(nodeid, votes); break; case CMD_SETEXPECTED: ret = set_expected(votes); break; case CMD_MONITOR: ret = monitor_status(nodeid_format, address_format, sort_opt); break; case CMD_UNREGISTER_QDEVICE: ret = unregister_qdevice(); break; } close_all(); return (ret); }
int main (int argc, char *argv[]) { const char *options = "VHsle:v:hin:d:"; char *endptr; int opt; int votes = 0; int ret = 0; uint32_t nodeid = VOTEQUORUM_NODEID_US; nodeid_format_t nodeid_format = NODEID_FORMAT_DECIMAL; name_format_t address_format = ADDRESS_FORMAT_NAME; command_t command_opt = CMD_UNKNOWN; if (argc == 1) { show_usage (argv[0]); exit(0); } while ( (opt = getopt(argc, argv, options)) != -1 ) { switch (opt) { case 's': command_opt = CMD_SHOWSTATUS; break; case 'i': address_format = ADDRESS_FORMAT_IP; break; case 'h': nodeid_format = NODEID_FORMAT_HEX; break; case 'l': command_opt = CMD_SHOWNODES; break; case 'e': if (using_votequorum()) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes <= 0) { fprintf(stderr, "New expected votes value was not valid, try a positive number\n"); } else { command_opt = CMD_SETEXPECTED; } } else { fprintf(stderr, "You cannot change expected votes, corosync is not using votequorum\n"); exit(2); } break; case 'n': nodeid = strtol(optarg, &endptr, 0); if ((nodeid == 0 && endptr == optarg) || nodeid <= 0) { fprintf(stderr, "The nodeid was not valid, try a positive number\n"); } break; case 'v': if (using_votequorum()) { votes = strtol(optarg, &endptr, 0); if ((votes == 0 && endptr == optarg) || votes < 0) { fprintf(stderr, "New votes value was not valid, try a positive number or zero\n"); } else { command_opt = CMD_SETVOTES; } } else { fprintf(stderr, "You cannot change node votes, corosync is not using votequorum\n"); exit(2); } break; case 'H': case '?': default: break; } } switch (command_opt) { case CMD_UNKNOWN: show_usage(argv[0]); break; case CMD_SHOWNODES: ret = show_nodes(nodeid_format, address_format); break; case CMD_SHOWSTATUS: show_status(); break; case CMD_SETVOTES: ret = set_votes(nodeid, votes); break; case CMD_SETEXPECTED: ret = set_expected(votes); break; } 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; }
static void show_status(void) { quorum_handle_t q_handle; votequorum_handle_t v_handle; votequorum_callbacks_t v_callbacks; quorum_callbacks_t callbacks; struct votequorum_info info; int is_quorate; int err; callbacks.quorum_notify_fn = quorum_notification_fn; err=quorum_initialize(&q_handle, &callbacks); if (err != CS_OK) { fprintf(stderr, "Cannot connect to quorum service, is it loaded?\n"); return; } err=quorum_getquorate(q_handle, &is_quorate); if (err != CS_OK) { fprintf(stderr, "quorum_getquorate FAILED: %d\n", err); return; } err=quorum_trackstart(q_handle, CS_TRACK_CURRENT); if (err != CS_OK) { fprintf(stderr, "quorum_trackstart FAILED: %d\n", err); return; } g_called = 0; while (g_called == 0) quorum_dispatch(q_handle, CS_DISPATCH_ONE); quorum_finalize(q_handle); printf("Version: %s\n", VERSION); printf("Nodes: %d\n", g_view_list_entries); printf("Ring ID: %" PRIu64 "\n", g_ring_id); printf("Quorum type: %s\n", get_quorum_type()); printf("Quorate: %s\n", is_quorate?"Yes":"No"); if (using_votequorum()) { 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); goto err_exit; } if ( (err=votequorum_getinfo(v_handle, 0, &info)) != CS_OK) fprintf(stderr, "votequorum_getinfo FAILED: %d\n", err); else { printf("Node votes: %d\n", info.node_votes); printf("Expected votes: %d\n", info.node_expected_votes); printf("Highest expected: %d\n", info.highest_expected); printf("Total votes: %d\n", info.total_votes); printf("Quorum: %d %s\n", info.quorum, info.flags & VOTEQUORUM_INFO_FLAG_QUORATE?" ":"Activity blocked"); printf("Flags: "); if (info.flags & VOTEQUORUM_INFO_FLAG_HASSTATE) printf("HasState "); if (info.flags & VOTEQUORUM_INFO_FLAG_DISALLOWED) printf("DisallowedNodes "); if (info.flags & VOTEQUORUM_INFO_FLAG_TWONODE) printf("2Node "); if (info.flags & VOTEQUORUM_INFO_FLAG_QUORATE) printf("Quorate "); printf("\n"); } } err_exit: return; }