Пример #1
0
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);
}
Пример #2
0
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);
}