[sheepdog] [PATCH v3 6/6] dog: add information of disks in cluster info

Robin Dong robin.k.dong at gmail.com
Mon May 19 09:11:15 CEST 2014


From: Robin Dong <sanbai at taobao.com>

Add number of disks for every node in cluster info and
also show vnode mode (disk or node) when using '-s' option.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 dog/cluster.c | 49 ++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index 7c5bc87..c2f430f 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -24,6 +24,7 @@ static struct sd_option cluster_options[] = {
 	{'t', "strict", false,
 	 "do not serve write request if number of nodes is not sufficient"},
 	{'s', "backend", false, "show backend store information"},
+	{'m', "mode", false, "show vnode mode"},
 	{ 0, NULL, false, NULL },
 };
 
@@ -32,6 +33,7 @@ static struct cluster_cmd_data {
 	uint8_t copy_policy;
 	bool force;
 	bool show_store;
+	bool show_vnodemode;
 	bool strict;
 	char name[STORE_LEN];
 } cluster_cmd_data;
@@ -143,6 +145,29 @@ static int cluster_format(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
+static void print_nodes(const struct epoch_log *logs, int epoch)
+{
+	int i, nr_disk;
+	const struct sd_node *entry;
+
+	for (i = 0; i < logs[epoch].nr_nodes; i++) {
+		entry = logs[epoch].nodes + i;
+		if (logs->flags & SD_CLUSTER_FLAG_DISKMODE) {
+			for (nr_disk = 0; nr_disk < DISK_MAX; nr_disk++) {
+				if (entry->disks[nr_disk].disk_id == 0)
+					break;
+			}
+			printf("%s%s(%d)",
+			       (i == 0) ? "" : ", ",
+			       addr_to_str(entry->nid.addr, entry->nid.port),
+			       nr_disk);
+		} else
+			printf("%s%s",
+			       (i == 0) ? "" : ", ",
+			       addr_to_str(entry->nid.addr, entry->nid.port));
+	}
+}
+
 static int cluster_info(int argc, char **argv)
 {
 	int i, ret;
@@ -195,6 +220,16 @@ static int cluster_info(int argc, char **argv)
 			printf("%s\n", sd_strerror(rsp->result));
 	}
 
+	/* show vnode mode (node or disk) for cluster */
+	if (cluster_cmd_data.show_vnodemode) {
+		if (!raw_output)
+			printf("Cluster vnode mode: ");
+		if (logs->flags & SD_CLUSTER_FLAG_DISKMODE)
+			printf("disk");
+		else
+			printf("node");
+	}
+
 	if (!raw_output && rsp->data_length > 0) {
 		ct = logs[0].ctime >> 32;
 		printf("\nCluster created at %s\n", ctime(&ct));
@@ -203,8 +238,6 @@ static int cluster_info(int argc, char **argv)
 
 	nr_logs = rsp->data_length / sizeof(struct epoch_log);
 	for (i = 0; i < nr_logs; i++) {
-		int j;
-		const struct sd_node *entry;
 
 		ti = logs[i].time;
 		if (raw_output) {
@@ -216,12 +249,7 @@ static int cluster_info(int argc, char **argv)
 
 		printf(raw_output ? "%s %d" : "%s %6d", time_str, logs[i].epoch);
 		printf(" [");
-		for (j = 0; j < logs[i].nr_nodes; j++) {
-			entry = logs[i].nodes + j;
-			printf("%s%s",
-			       (j == 0) ? "" : ", ",
-			       addr_to_str(entry->nid.addr, entry->nid.port));
-		}
+		print_nodes(logs, i);
 		printf("]\n");
 	}
 
@@ -550,7 +578,7 @@ static int cluster_check(int argc, char **argv)
 }
 
 static struct subcommand cluster_cmd[] = {
-	{"info", NULL, "aprhs", "show cluster information",
+	{"info", NULL, "aprhsm", "show cluster information",
 	 NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
 	{"format", NULL, "bctaph", "create a Sheepdog store",
 	 NULL, CMD_NEED_NODELIST, cluster_format, cluster_options},
@@ -597,6 +625,9 @@ static int cluster_parser(int ch, const char *opt)
 	case 's':
 		cluster_cmd_data.show_store = true;
 		break;
+	case 'm':
+		cluster_cmd_data.show_vnodemode = true;
+		break;
 	case 't':
 		cluster_cmd_data.strict = true;
 		break;
-- 
1.7.12.4




More information about the sheepdog mailing list