Просмотр исходного кода

make the output of "corosync-cfgtool -s" more readable (#269)

Bin Liu 8 лет назад
Родитель
Сommit
0b5ab1e1cd
2 измененных файлов с 52 добавлено и 12 удалено
  1. 21 4
      man/corosync-cfgtool.8
  2. 31 8
      tools/corosync-cfgtool.c

+ 21 - 4
man/corosync-cfgtool.8

@@ -35,7 +35,7 @@
 .SH "NAME"
 corosync-cfgtool \- An administrative tool for corosync.
 .SH "SYNOPSIS"
-.B corosync\-cfgtool [\-i IP_address] [\-s] [\-R] [\-k nodeid] [\-a nodeid] [\-h] [\-H]
+.B corosync\-cfgtool [\-i IP_address] [[\-b] \-s] [\-R] [\-k nodeid] [\-a nodeid] [\-h] [\-H]
 .SH "DESCRIPTION"
 .B corosync\-cfgtool
 A tool for displaying and configuring active parameters within corosync.
@@ -45,14 +45,31 @@ A tool for displaying and configuring active parameters within corosync.
 Finds only information about the specified interface IP address.
 .TP 
 .B -s
-Displays the status of the current links on this node.  If any interfaces are
-faulty, 1 is returned by the binary.  If all interfaces are active 0 is returned
-to the shell.
+Displays the status of the current links on this node for UDP/UDPU, while extended status
+for KNET. If any interfaces are faulty, 1 is returned by the binary. If all interfaces are
+active 0 is returned to the shell.
+After each link, the nodes on that link are displayed in order with their status,
+for example there are 3 nodes with KNET transportation:
+LINK ID 0:
+    id     = 192.168.100.80
+    status:
+        node 0: link enabled: 1     link connected: 1
+        node 1: link enabled: 1     link connected: 1
+        node 2: link enabled: 1     link connected: 1
+.TP
+.B -b
+Displays the brief status of the current links on this node (KNET only) when used
+with "-s". If any interfaces are faulty, 1 is returned by the binary. If all interfaces
+are active 0 is returned to the shell.
 After each link, the nodes on that link are displayed in order with their status
 encoded into a single digit. 1=link enabled, 2=link connected, So a 3 in
 a node position indicates that the link is both enabled and connected.
 The local link (which will only ever be enabled on link 0) shows as enabled but
 not connected for internal reasons.
+The output will be:
+LINK ID 0:
+    id     = 192.168.100.80
+    status = 333
 .TP 
 .B -R
 Tell all instances of corosync in this cluster to reload corosync.conf.

+ 31 - 8
tools/corosync-cfgtool.c

@@ -66,7 +66,7 @@
 	} while (0)
 
 static int
-linkstatusget_do (char *interface_name)
+linkstatusget_do (char *interface_name, int brief)
 {
 	cs_error_t result;
 	corosync_cfg_handle_t handle;
@@ -76,6 +76,7 @@ linkstatusget_do (char *interface_name)
 	unsigned int i;
 	unsigned int nodeid;
 	int rc = 0;
+	int len, s = 0, t;
 
 	printf ("Printing link status.\n");
 	result = corosync_cfg_initialize (&handle, NULL);
@@ -108,9 +109,21 @@ linkstatusget_do (char *interface_name)
 
 				printf ("LINK ID %d\n", i);
 				printf ("\tid\t= %s\n", interface_names[i]);
-				printf ("\tstatus\t= %s\n", interface_status[i]);
-				if (strstr(interface_status[i], "FAULTY")) {
-					rc = 1;
+				if((!brief) && (strcmp(interface_status[i], "OK") != 0) &&
+					(!strstr(interface_status[i], "FAULTY"))) {
+					len = strlen(interface_status[i]);
+					printf ("\tstatus:\n");
+					while(s < len) {
+						t = interface_status[i][s] - '0';
+						printf("\t\tnode %d:\n", s++);
+						printf("link enabled:%d\t", t&1? 1 : 0);
+						printf("link connected:%d\n", t&2? 1: 0);
+					}
+				} else {
+					printf ("\tstatus\t= %s\n", interface_status[i]);
+					if (strstr(interface_status[i], "FAULTY")) {
+						rc = 1;
+					}
 				}
 			}
 		}
@@ -243,11 +256,12 @@ static void killnode_do(unsigned int nodeid)
 
 static void usage_do (void)
 {
-	printf ("corosync-cfgtool [-i <interface ip>] [-s] [-R] [-k nodeid] [-a nodeid] [-h] [-H]\n\n");
+	printf ("corosync-cfgtool [-i <interface ip>] [[-b] -s] [-R] [-k nodeid] [-a nodeid] [-h] [-H]\n\n");
 	printf ("A tool for displaying and configuring active parameters within corosync.\n");
 	printf ("options:\n");
 	printf ("\t-i\tFinds only information about the specified interface IP address.\n");
-	printf ("\t-s\tDisplays the status of the current links on this node.\n");
+	printf ("\t-s\tDisplays the status of the current links on this node(UDP/UDPU), while extended status for KNET.\n");
+	printf ("\t-b\tDisplays the brief status of the current links on this node when used with -s.(KNET only)\n");
 	printf ("\t-R\tTell all instances of corosync in this cluster to reload corosync.conf.\n");
 	printf ("\t-k\tKill a node identified by node id.\n");
 	printf ("\t-a\tDisplay the IP address(es) of a node\n");
@@ -256,11 +270,12 @@ static void usage_do (void)
 }
 
 int main (int argc, char *argv[]) {
-	const char *options = "i:srRk:a:hH";
+	const char *options = "i:sbrRk:a:hH";
 	int opt;
 	unsigned int nodeid;
 	char interface_name[128] = "";
 	int rc=0;
+	int getstatus=0, brief=0;
 
 	if (argc == 1) {
 		usage_do ();
@@ -272,7 +287,10 @@ int main (int argc, char *argv[]) {
 			interface_name[sizeof(interface_name) - 1] = '\0';
 			break;
 		case 's':
-			rc = linkstatusget_do (interface_name);
+			getstatus=1;
+			break;
+		case 'b':
+			brief = 1;
 			break;
 		case 'R':
 			rc = reload_config_do ();
@@ -293,6 +311,11 @@ int main (int argc, char *argv[]) {
 			break;
 		}
 	}
+	if(getstatus) {
+		linkstatusget_do(interface_name, brief);
+	} else if (brief) {
+		usage_do();
+	}
 
 	return (rc);
 }