This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cluster: STABLE3 - cman: Add more node display options to 'cman_toolnodes'


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=c29c81ec4ed1399f5cdbcfb883bc315958865504
Commit:        c29c81ec4ed1399f5cdbcfb883bc315958865504
Parent:        2e4a105e554e4b162b4d5ee19efc9e09b07e7e8e
Author:        Christine Caulfield <ccaulfie@redhat.com>
AuthorDate:    Tue Jan 13 15:55:05 2009 +0000
Committer:     Christine Caulfield <ccaulfie@redhat.com>
CommitterDate: Tue Jan 13 15:55:05 2009 +0000

cman: Add more node display options to 'cman_tool nodes'

cman_tool nodes can now display votes, expecetd_votes and internal status for
a node. These are only available via -F at the moment as I don't want to
break anything that relies on the default printing format.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
---
 cman/cman_tool/cman_tool.h  |    3 +++
 cman/cman_tool/main.c       |   38 +++++++++++++++++++++++++++++++++++++-
 cman/daemon/cnxman-socket.h |   11 +++++++++++
 cman/daemon/commands.c      |   35 +++++++++++++++++++++++++++++++++++
 cman/lib/libcman.c          |   14 ++++++++++++++
 cman/lib/libcman.h          |   33 +++++++++++++++++++++++++++++++++
 6 files changed, 133 insertions(+), 1 deletions(-)

diff --git a/cman/cman_tool/cman_tool.h b/cman/cman_tool/cman_tool.h
index 7476e1f..78958b9 100644
--- a/cman/cman_tool/cman_tool.h
+++ b/cman/cman_tool/cman_tool.h
@@ -52,6 +52,9 @@ enum format_opt
 	FMT_NAME,
 	FMT_TYPE,
 	FMT_ADDR,
+	FMT_VOTES,
+	FMT_EXP,
+	FMT_STATE,
 };
 
 struct commandline
diff --git a/cman/cman_tool/main.c b/cman/cman_tool/main.c
index 2181dbd..4ed6d72 100644
--- a/cman/cman_tool/main.c
+++ b/cman/cman_tool/main.c
@@ -328,6 +328,12 @@ static int get_format_opt(const char *opt)
 		return FMT_TYPE;
 	if (!strcmp(opt, "addr"))
 		return FMT_ADDR;
+	if (!strcmp(opt, "votes"))
+		return FMT_VOTES;
+	if (!strcmp(opt, "exp"))
+		return FMT_EXP;
+	if (!strcmp(opt, "state"))
+		return FMT_STATE;
 
 	return FMT_NONE;
 }
@@ -340,6 +346,7 @@ static void print_node(commandline_t *comline, cman_handle_t h, int *format, str
 	struct tm *jtime;
 	char jstring[1024];
 	int i,j,k;
+	cman_node_extra_t enode;
 
 	if (comline->num_nodenames > 0) {
 		if (node_filter(comline, node->cn_name) == 0) {
@@ -411,7 +418,7 @@ static void print_node(commandline_t *comline, cman_handle_t h, int *format, str
 		}
 	}
 
-	if (comline->format_opts) {
+	if (comline->format_opts && (cman_get_node_extra(h, node->cn_nodeid, &enode) == 0)) {
 		for (j = 0; j < MAX_FORMAT_OPTS; j++) {
 			switch (format[j]) {
 			case FMT_NONE:
@@ -425,6 +432,35 @@ static void print_node(commandline_t *comline, cman_handle_t h, int *format, str
 			case FMT_TYPE:
 				printf("%c ", member_type);
 				break;
+			case FMT_VOTES:
+				printf("%d ", enode.cnx_votes);
+				break;
+			case FMT_EXP:
+				printf("%d ", enode.cnx_expected_votes);
+				break;
+			case FMT_STATE:
+				switch (enode.cnx_state)
+				{
+				case CLUSTER_NODESTATE_JOINING:
+					printf("Joining ");
+					break;
+				case CLUSTER_NODESTATE_MEMBER:
+					printf("Member ");
+					break;
+				case CLUSTER_NODESTATE_DEAD:
+					printf("Dead ");
+					break;
+				case CLUSTER_NODESTATE_LEAVING:
+					printf("Leaving ");
+					break;
+				case CLUSTER_NODESTATE_DISALLOWED:
+					printf("Disallowed ");
+					break;
+				default:
+					printf("Unknown ");
+					break;
+				}
+				break;
 			case FMT_ADDR:
 				for (k = 0; k < numaddrs; k++) {
 					print_address(addrs[k].cna_address);
diff --git a/cman/daemon/cnxman-socket.h b/cman/daemon/cnxman-socket.h
index 798fa02..49e3bc4 100644
--- a/cman/daemon/cnxman-socket.h
+++ b/cman/daemon/cnxman-socket.h
@@ -42,6 +42,7 @@
 #define CMAN_CMD_SET_DIRTY          0x800000c2
 #define CMAN_CMD_SET_DEBUGLOG       0x800000c3
 #define CMAN_CMD_DUMP_OBJDB         0x800000c4
+#define CMAN_CMD_GETNODE_EXTRA      0x000000c5
 
 #define CMAN_CMD_DATA               0x00000100
 #define CMAN_CMD_BIND               0x00000101
@@ -193,6 +194,16 @@ struct cl_cluster_node {
 	unsigned char votes;
 };
 
+struct cl_node_extra
+{
+	int nodeid;
+	int state;
+	int votes;
+	int expected_votes;
+	int leave_reason;
+};
+
+
 /* Structure passed to CMAN_CMD_ISLISTENING */
 struct cl_listen_request {
 	unsigned char port;
diff --git a/cman/daemon/commands.c b/cman/daemon/commands.c
index 13e6ca2..a43909e 100644
--- a/cman/daemon/commands.c
+++ b/cman/daemon/commands.c
@@ -693,6 +693,37 @@ static int do_cmd_get_node(char *cmdbuf, char *retbuf, int *retlen)
 	return 0;
 }
 
+static int do_cmd_get_node_extra(char *cmdbuf, char *retbuf, int *retlen)
+{
+	struct cluster_node *node;
+	struct cl_node_extra *r_node = (struct cl_node_extra *)retbuf;
+	int nodeid;
+
+	if (!we_are_a_cluster_member)
+		return -ENOENT;
+
+	memcpy(&nodeid, cmdbuf, sizeof(int));
+
+	if (nodeid == CLUSTER_GETNODE_QUORUMDEV) {
+		return -EINVAL;
+	}
+	node = find_node_by_nodeid(nodeid);
+	if (nodeid == 0)
+		node = us;
+	if (!node)
+		return -EINVAL;
+
+	r_node->votes = node->votes;
+	r_node->expected_votes = node->expected_votes;
+	r_node->state = node->state;
+	r_node->leave_reason = node->leave_reason;
+	r_node->nodeid = nodeid;
+
+	*retlen = sizeof(struct cl_node_extra);
+
+	return 0;
+}
+
 static int do_cmd_set_expected(char *cmdbuf, int *retlen)
 {
 	unsigned int total_votes;
@@ -1371,6 +1402,10 @@ int process_command(struct connection *con, int cmd, char *cmdbuf,
 		err = do_cmd_get_node(cmdbuf, outbuf+offset, retlen);
 		break;
 
+	case CMAN_CMD_GETNODE_EXTRA:
+		err = do_cmd_get_node_extra(cmdbuf, outbuf+offset, retlen);
+		break;
+
 	case CMAN_CMD_GETCLUSTER:
 		err = do_cmd_get_cluster(cmdbuf, outbuf+offset, retlen);
 		break;
diff --git a/cman/lib/libcman.c b/cman/lib/libcman.c
index 21f9763..8737d44 100644
--- a/cman/lib/libcman.c
+++ b/cman/lib/libcman.c
@@ -687,6 +687,20 @@ int cman_get_node(cman_handle_t handle, int nodeid, cman_node_t *node)
 	return 0;
 }
 
+int cman_get_node_extra(cman_handle_t handle, int nodeid, cman_node_extra_t *node)
+{
+	struct cman_handle *h = (struct cman_handle *)handle;
+	int status;
+	VALIDATE_HANDLE(h);
+
+	status = info_call(h, CMAN_CMD_GETNODE_EXTRA, &nodeid, sizeof(int),
+			   node, sizeof(cman_node_extra_t));
+	if (status < 0)
+		return -1;
+
+	return 0;
+}
+
 int cman_get_subsys_count(cman_handle_t handle)
 {
 	struct cman_handle *h = (struct cman_handle *)handle;
diff --git a/cman/lib/libcman.h b/cman/lib/libcman.h
index 7557cb9..0d7816b 100644
--- a/cman/lib/libcman.h
+++ b/cman/lib/libcman.h
@@ -114,6 +114,34 @@ typedef struct cman_node
 } cman_node_t;
 
 /*
+ * Return from cman_get_node_extra()
+ */
+typedef struct cman_node_extra
+{
+	int cnx_nodeid;
+	int cnx_state;
+	int cnx_votes;
+	int cnx_expected_votes;
+	int cnx_leave_reason;
+} cman_node_extra_t;
+
+#define CLUSTER_LEAVEREASON_DOWN         0   /* Normal shutdown */
+#define CLUSTER_LEAVEREASON_KILLED       1   /* probably buy cman_tool */
+#define CLUSTER_LEAVEREASON_PANIC        2   /* Just disappeared */
+#define CLUSTER_LEAVEREASON_REMOVED      3   /* This one can reduce quorum */
+#define CLUSTER_LEAVEREASON_REJECTED     4   /* Not allowed into the cluster in the first place */
+#define CLUSTER_LEAVEREASON_INCONSISTENT 5   /* Our view of the cluster is in a minority */
+#define CLUSTER_LEAVEREASON_DEAD         6   /* Discovered to be dead */
+#define CLUSTER_LEAVEREASON_NORESPONSE   7   /* Didn't ACK message */
+
+#define CLUSTER_NODESTATE_JOINING    1
+#define CLUSTER_NODESTATE_MEMBER     2
+#define CLUSTER_NODESTATE_DEAD       3
+#define CLUSTER_NODESTATE_LEAVING    4
+#define CLUSTER_NODESTATE_DISALLOWED 5
+
+
+/*
  * Returned from cman_get_version(),
  * input to cman_set_version(), though only cv_config can be changed
  */
@@ -279,6 +307,11 @@ int cman_get_disallowed_nodes(cman_handle_t handle, int maxnodes, int *retnodes,
  */
 int cman_get_node(cman_handle_t handle, int nodeid, cman_node_t *node);
 
+/*
+ * This always gets info by nodeid.
+ */
+int cman_get_node_extra(cman_handle_t handle, int nodeid, cman_node_extra_t *node);
+
 /* cman_get_node() only returns the first address of a node (whatever /that/
  * may mean). If you want to know all of them you need to call this.
  * max_addrs is the size of the 'addrs' array. num_addrs will be filled in by 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]