Re: [PATCH] corosync-quorumtool: sort nodes by nodeid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 15/08/14 12:42, Fabio M. Di Nitto wrote:
On 08/14/2014 03:47 PM, Christine Caulfield wrote:
This is a silly thing that's bugged me for a while. corosync-quorumtool
always prints nodes out in IP address order which is not necessarily
node ID order. This can make the output confusing.

This patch forces node ID order. I'm also considering making sort order
a command-line option with selections for IP address, node ID and name.
Thoughts?

No objections, but please make it an option right away. I prefer to see
IP vs nodeids (that's also probably why I wrote it that way :)

Fabio

OK, here's the patch for making it an option. I can use this for the sort by name bit that will come later :-) The default returns to ipaddr.

Chrissie


Signed-Off-By: Christine Caulfield <ccaulfie@xxxxxxxxxx>


diff --git a/tools/corosync-quorumtool.c b/tools/corosync-quorumtool.c
index a6d6e4a..c3e7be7 100644
--- a/tools/corosync-quorumtool.c
+++ b/tools/corosync-quorumtool.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2012 Red Hat, Inc.
+ * Copyright (c) 2009-2014 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -69,6 +69,11 @@ typedef enum {
 	CMD_UNREGISTER_QDEVICE
 } command_t;
 
+typedef enum {
+	SORT_ADDR,
+	SORT_NODEID
+} sorttype_t;
+
 /*
  * global vars
  */
@@ -142,6 +147,7 @@ static void show_usage(const char *name)
 	printf("  -e <expected>  change expected votes for the cluster (*)\n");
 	printf("  -H             show nodeids in hexadecimal rather than decimal\n");
 	printf("  -i             show node IP addresses instead of the resolved name\n");
+	printf("  -o <a|i>       order by [a] IP address (default), [i] nodeid,\n");
 	printf("  -f             forcefully unregister a quorum device *DANGEROUS* (*)\n");
 	printf("  -h             show this help text\n");
 	printf("  -V             show version and exit\n");
@@ -369,6 +375,7 @@ static void print_uint32_padded(uint32_t value)
 	print_string_padded(buf);
 }
 
+/* for qsort */
 static int compare_nodeids(const void *one, const void *two)
 {
       const struct votequorum_info *info1 = one;
@@ -383,7 +390,7 @@ static int compare_nodeids(const void *one, const void *two)
       return -1;
 }
 
-static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name_format)
+static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type)
 {
 	int i, display_qdevice = 0;
 	struct votequorum_info info[g_view_list_entries];
@@ -414,7 +421,10 @@ static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name
 	}
 	printf("Name\n");
 
-	qsort(info, g_view_list_entries, sizeof(struct votequorum_info), compare_nodeids);
+	/* corosync sends them already sorted by address */
+	if (sort_type == SORT_NODEID) {
+		qsort(info, g_view_list_entries, sizeof(struct votequorum_info), compare_nodeids);
+	}
 	for (i=0; i < g_view_list_entries; i++) {
 		if (nodeid_format == NODEID_FORMAT_DECIMAL) {
 			print_uint32_padded(info[i].node_id);
@@ -467,7 +477,7 @@ static void display_nodes_data(nodeid_format_t nodeid_format, name_format_t name
 }
 
 static int display_quorum_data(int is_quorate,
-			       nodeid_format_t nodeid_format, name_format_t name_format,
+			       nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type,
 			       int loop)
 {
 	struct votequorum_info info;
@@ -520,7 +530,7 @@ static int display_quorum_data(int is_quorate,
 		fprintf(stderr, "Unable to get node info: %s\n", cs_strerror(err));
 	}
 
-	display_nodes_data(nodeid_format, name_format);
+	display_nodes_data(nodeid_format, name_format, sort_type);
 
 	return err;
 }
@@ -530,7 +540,7 @@ static int display_quorum_data(int is_quorate,
  *         0 if not quorate
  *        -1 on error
  */
-static int show_status(nodeid_format_t nodeid_format, name_format_t name_format)
+static int show_status(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type)
 {
 	int is_quorate;
 	int err;
@@ -564,7 +574,7 @@ quorum_err:
 		return -1;
 	}
 
-	err = display_quorum_data(is_quorate, nodeid_format, name_format, 0);
+	err = display_quorum_data(is_quorate, nodeid_format, name_format, sort_type, 0);
 	if (err != CS_OK) {
 		return -1;
 	}
@@ -572,13 +582,13 @@ quorum_err:
 	return is_quorate;
 }
 
-static int monitor_status(nodeid_format_t nodeid_format, name_format_t name_format) {
+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);
+		return show_status(nodeid_format, name_format, sort_type);
 	}
 
 	err=quorum_trackstart(q_handle, CS_TRACK_CHANGES);
@@ -593,7 +603,7 @@ static int monitor_status(nodeid_format_t nodeid_format, name_format_t name_form
 			fprintf(stderr, "Unable to dispatch quorum status: %s\n", cs_strerror(err));
 			goto quorum_err;
 		}
-		err = display_quorum_data(g_quorate, nodeid_format, name_format, loop);
+		err = display_quorum_data(g_quorate, nodeid_format, name_format, sort_type, loop);
 		printf("\n");
 		loop = 1;
 		if (err != CS_OK) {
@@ -606,7 +616,7 @@ quorum_err:
 	return -1;
 }
 
-static int show_nodes(nodeid_format_t nodeid_format, name_format_t name_format)
+static int show_nodes(nodeid_format_t nodeid_format, name_format_t name_format, sorttype_t sort_type)
 {
 	int err;
 	int result = EXIT_FAILURE;
@@ -626,7 +636,7 @@ static int show_nodes(nodeid_format_t nodeid_format, name_format_t name_format)
 		}
 	}
 
-	display_nodes_data(nodeid_format, name_format);
+	display_nodes_data(nodeid_format, name_format, sort_type);
 
 	result = EXIT_SUCCESS;
 err_exit:
@@ -721,7 +731,7 @@ static void close_all(void) {
 }
 
 int main (int argc, char *argv[]) {
-	const char *options = "VHslpmfe:v:hin:";
+	const char *options = "VHslpmfe:v:hin:o:";
 	char *endptr;
 	int opt;
 	int votes = 0;
@@ -731,6 +741,8 @@ int main (int argc, char *argv[]) {
 	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()) {
@@ -803,6 +815,19 @@ int main (int argc, char *argv[]) {
 				exit(2);
 			}
 			break;
+		case 'o':
+			sortchar = optarg[0];
+			switch (sortchar) {
+			        case 'a': sort_opt = SORT_ADDR;
+					break;
+			        case 'i': sort_opt = SORT_NODEID;
+					break;
+			        default:
+					fprintf(stderr, "Invalid ordering option. valid orders are a(address), i(node ID)\n");
+					exit(2);
+					break;
+			}
+			break;
 		case 'V':
 			printf("corosync-quorumtool version: %s\n", VERSION);
 			exit(0);
@@ -821,10 +846,10 @@ int main (int argc, char *argv[]) {
 		ret = -1;
 		break;
 	case CMD_SHOWNODES:
-		ret = show_nodes(nodeid_format, address_format);
+		ret = show_nodes(nodeid_format, address_format, sort_opt);
 		break;
 	case CMD_SHOWSTATUS:
-		ret = show_status(nodeid_format, address_format);
+		ret = show_status(nodeid_format, address_format, sort_opt);
 		break;
 	case CMD_SETVOTES:
 		if (!nodeid_set) {
@@ -836,7 +861,7 @@ int main (int argc, char *argv[]) {
 		ret = set_expected(votes);
 		break;
 	case CMD_MONITOR:
-		ret = monitor_status(nodeid_format, address_format);
+		ret = monitor_status(nodeid_format, address_format, sort_opt);
 		break;
 	case CMD_UNREGISTER_QDEVICE:
 		ret = unregister_qdevice();
_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss

[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux