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

[Cluster-devel] cluster/cman/cman_tool cman_tool.h main.c



CVSROOT:	/cvs/cluster
Module name:	cluster
Branch: 	RHEL5
Changes by:	rohara sourceware org	2007-10-12 18:50:48

Modified files:
	cman/cman_tool : cman_tool.h main.c 

Log message:
	Add ability to format output and filter based on node name.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/cman_tool/cman_tool.h.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.12&r2=1.12.2.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/cman_tool/main.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.51.2.4&r2=1.51.2.5

--- cluster/cman/cman_tool/cman_tool.h	2006/05/10 14:20:06	1.12
+++ cluster/cman/cman_tool/cman_tool.h	2007/10/12 18:50:48	1.12.2.1
@@ -35,7 +35,6 @@
 #include <limits.h>
 #include <unistd.h>
 
-
 extern char *prog_name;
 
 #ifndef TRUE
@@ -50,13 +49,21 @@
 	exit(EXIT_FAILURE); \
 } while (0)
 
-
 #define DEFAULT_VOTES 1
 #define MAX_INTERFACES 10
+#define MAX_FORMAT_OPTS 10
 #define MAX_NODE_NAME_LEN 65
 #define MAX_MCAST_NAME_LEN 256
 #define MAX_PATH_LEN 256
 
+enum format_opt
+{
+	FMT_NONE,
+	FMT_ID,
+	FMT_NAME,
+	FMT_TYPE,
+	FMT_ADDR,
+};
 
 struct commandline
 {
@@ -67,6 +74,7 @@
         char *interfaces[MAX_INTERFACES];
 	char *override_nodename;
 	char *key_filename;
+	char *format_opts;
 	int votes;
 	int expected_votes;
 	int two_node;
--- cluster/cman/cman_tool/main.c	2007/09/28 13:26:14	1.51.2.4
+++ cluster/cman/cman_tool/main.c	2007/10/12 18:50:48	1.51.2.5
@@ -20,7 +20,7 @@
 #include "libcman.h"
 #include "cman_tool.h"
 
-#define OPTION_STRING		("m:n:v:e:2p:c:r:i:N:t:o:k:Vwfqah?d::")
+#define OPTION_STRING		("m:n:v:e:2p:c:r:i:N:t:o:k:F:Vwfqah?d::")
 #define OP_JOIN			1
 #define OP_LEAVE		2
 #define OP_EXPECTED		3
@@ -110,6 +110,8 @@
 		printf("nodes              Show local record of cluster nodes\n");
 		printf("  -f                 Also show when node was last fenced\n");
 		printf("  -a                 Also show node address(es)\n");
+		printf("  -n <nodename>      Only show information for specific node\n");
+		printf("  -F <format>        Specify output format (see man page)\n");
 		printf("\n");
 	}
 
@@ -300,13 +302,46 @@
 	return a->cn_nodeid - b->cn_nodeid;
 }
 
+static int node_filter(commandline_t *comline, const char *node)
+{
+	int i;
+
+	for (i = 0; i < comline->num_nodenames; i++) {
+		if (strcmp(comline->nodenames[i], node) == 0) {
+			return TRUE;
+		}
+	}
+
+	return FALSE;
+}
+
+static int get_format_opt(const char *opt)
+{
+	if (!opt)
+		return FMT_NONE;
+
+	if (!strcmp(opt, "id"))
+		return FMT_ID;
+	if (!strcmp(opt, "name"))
+		return FMT_NAME;
+	if (!strcmp(opt, "type"))
+		return FMT_TYPE;
+	if (!strcmp(opt, "addr"))
+		return FMT_ADDR;
+
+	return FMT_NONE;
+}
+
 static void show_nodes(commandline_t *comline)
 {
 	cman_handle_t h;
 	int count;
 	int i;
+	int j;
+	int k;
 	int numnodes;
 	int dis_count;
+	int format[MAX_FORMAT_OPTS];
 	cman_node_t *dis_nodes;
 	cman_node_t *nodes;
 	struct tm *jtime;
@@ -325,6 +360,16 @@
 	if (!nodes)
 		die("cannot allocate memory for nodes list\n");
 
+	if (comline->format_opts != NULL) {
+		char *format_str = comline->format_opts;
+		char *format_tmp;
+		for (i = 0; i < MAX_FORMAT_OPTS; i++) {
+			format_tmp = strtok(format_str, ",");
+			format_str = NULL;
+			format[i] = get_format_opt(format_tmp);
+		}
+	}
+
 	if (cman_get_nodes(h, count, &numnodes, nodes) < 0)
 		die("cman_get_nodes failed: %s", cman_error(errno));
 
@@ -333,9 +378,8 @@
 	dis_nodes = malloc(sizeof(cman_node_t) * count);
 
 	if (cman_get_disallowed_nodes(h, count, &dis_count, dis_nodes) == 0) {
-		int i,j;
-		for (i=0; i<numnodes; i++) {
-			for (j=0; j<dis_count; j++) {
+		for (i = 0; i < numnodes; i++) {
+			for (j = 0; j < dis_count; j++) {
 				if (dis_nodes[j].cn_nodeid == nodes[i].cn_nodeid)
 					nodes[i].cn_member = 2;
 			}
@@ -350,10 +394,19 @@
 		printf("      members list may seem inconsistent across the cluster\n");
 	}
 
-	printf("Node  Sts   Inc   Joined               Name\n");
-	for (i=0; i<numnodes; i++) {
+	if (!comline->format_opts) {
+		printf("Node  Sts   Inc   Joined               Name\n");
+	}
+
+	for (i = 0; i < numnodes; i++) {
 		char member_type;
 
+		if (comline->num_nodenames > 0) {
+			if (node_filter(comline, nodes[i].cn_name) == 0) {
+				continue;
+			}
+		}
+
 		switch (nodes[i].cn_member) {
 		case 0:
 			member_type = 'X';
@@ -375,11 +428,13 @@
 		else
 			strcpy(jstring, "                   ");
 
-		printf("%4d   %c  %5d   %s  %s\n",
-		       nodes[i].cn_nodeid, member_type,
-		       nodes[i].cn_incarnation, jstring, nodes[i].cn_name);
+		if (!comline->format_opts) {
+			printf("%4d   %c  %5d   %s  %s\n",
+			       nodes[i].cn_nodeid, member_type,
+			       nodes[i].cn_incarnation, jstring, nodes[i].cn_name);
+		}
 
-		if (comline->fence_opt) {
+		if (comline->fence_opt && !comline->format_opts) {
 			char agent[255];
 			uint64_t fence_time;
 			int fenced;
@@ -397,24 +452,56 @@
 			}
 		}
 
-		if (comline->addresses_opt)
-		{
-			int numaddrs;
-			struct cman_node_address addrs[MAX_INTERFACES];
+		int numaddrs;
+		struct cman_node_address addrs[MAX_INTERFACES];
+
+		if (comline->addresses_opt || comline->format_opts) {
 			if (!cman_get_node_addrs(h, nodes[i].cn_nodeid, MAX_INTERFACES, &numaddrs, addrs) &&
 				numaddrs)
 			{
-				int i;
-				printf("       Addresses: ");
-				for (i=0; i<numaddrs; i++)
-				{
-					print_address(addrs[i].cna_address);
+				if (!comline->format_opts) {
+					printf("       Addresses: ");
+					for (i = 0; i < numaddrs; i++)
+					{
+						print_address(addrs[i].cna_address);
+						printf(" ");
+					}
+					printf("\n");
+				}
+			}
+		}
+
+		if (comline->format_opts) {
+			for (j = 0; j < MAX_FORMAT_OPTS; j++) {
+				switch (format[j]) {
+				case FMT_NONE:
+					break;
+				case FMT_ID:
+					printf("%d ", nodes[i].cn_nodeid);
+					break;
+				case FMT_NAME:
+					printf("%s ", nodes[i].cn_name);
+					break;
+				case FMT_TYPE:
+					printf("%c ", member_type);
+					break;
+				case FMT_ADDR:
+					for (k = 0; k < numaddrs; k++) {
+						print_address(addrs[k].cna_address);
+						if (k != (numaddrs - 1)) {
+							printf(",");
+						}
+					}
 					printf(" ");
+					break;
+				default:
+					break;
 				}
-				printf("\n");
 			}
+			printf("\n");
 		}
 	}
+
 	free(nodes);
 	free(dis_nodes);
 	cman_finish(h);
@@ -701,6 +788,10 @@
 			comline->clustername_opt = TRUE;
 			break;
 
+		case 'F':
+			comline->format_opts = strdup(optarg);
+			break;
+
 		case 'V':
 			printf("cman_tool %s (built %s %s)\n",
 				CMAN_RELEASE_NAME, __DATE__, __TIME__);


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