[sheepdog] [PATCH 1/2] dog: add argument for cluster info to display backend store type

Robin Dong robin.k.dong at gmail.com
Wed Dec 4 10:21:25 CET 2013


From: Robin Dong <sanbai at taobao.com>

'dog cluster info' does not show backend store information, so we
add argument '-s' to display it.

Now, when using 'dog cluster info -s', it will display:

	Cluster status: running, auto-recovery enabled
	Cluster store: plain with 8:15 redundancy policy

	Cluster created at Wed Dec  4 16:39:21 2013

	Epoch Time           Version
	......

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 dog/cluster.c            | 28 ++++++++++++++++++++++++++--
 include/internal_proto.h |  5 ++++-
 sheep/ops.c              | 13 +++++++++++--
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index f44791c..05e98d2 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -21,7 +21,7 @@ static struct sd_option cluster_options[] = {
 	{'b', "store", true, "specify backend store"},
 	{'c', "copies", true, "specify the default data redundancy (number of copies)"},
 	{'f', "force", false, "do not prompt for confirmation"},
-
+	{'s', "backend", false, "show backend store information"},
 	{ 0, NULL, false, NULL },
 };
 
@@ -29,6 +29,7 @@ static struct cluster_cmd_data {
 	uint8_t copies;
 	uint8_t copy_policy;
 	bool force;
+	bool show_store;
 	char name[STORE_LEN];
 } cluster_cmd_data;
 
@@ -145,6 +146,7 @@ static int cluster_info(int argc, char **argv)
 	if (ret < 0)
 		goto error;
 
+	/* show cluster status */
 	if (!raw_output)
 		printf("Cluster status: ");
 	if (rsp->result == SD_RES_SUCCESS)
@@ -153,6 +155,25 @@ static int cluster_info(int argc, char **argv)
 	else
 		printf("%s\n", sd_strerror(rsp->result));
 
+	/* show cluster backend store */
+	if (cluster_cmd_data.show_store) {
+		if (!raw_output)
+			printf("Cluster store: ");
+		if (rsp->result == SD_RES_SUCCESS) {
+			char copy[10];
+			if (!logs->copy_policy)
+				snprintf(copy, sizeof(copy), "%d",
+					 logs->nr_copies);
+			else
+				snprintf(copy, sizeof(copy), "%d:%d",
+					 (logs->copy_policy >> 4) * 2,
+					 logs->copy_policy & 0x0f);
+			printf("%s with %s redundancy policy\n",
+			       logs->drv_name, copy);
+		} else
+			printf("%s\n", sd_strerror(rsp->result));
+	}
+
 	if (!raw_output && rsp->data_length > 0) {
 		ct = logs[0].ctime >> 32;
 		printf("\nCluster created at %s\n", ctime(&ct));
@@ -517,7 +538,7 @@ static int cluster_check(int argc, char **argv)
 }
 
 static struct subcommand cluster_cmd[] = {
-	{"info", NULL, "aprh", "show cluster information",
+	{"info", NULL, "aprhs", "show cluster information",
 	 NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
 	{"format", NULL, "bcaph", "create a Sheepdog store",
 	 NULL, 0, cluster_format, cluster_options},
@@ -561,6 +582,9 @@ static int cluster_parser(int ch, const char *opt)
 	case 'f':
 		cluster_cmd_data.force = true;
 		break;
+	case 's':
+		cluster_cmd_data.show_store = true;
+		break;
 	}
 
 	return 0;
diff --git a/include/internal_proto.h b/include/internal_proto.h
index 70a7b5d..b224c49 100644
--- a/include/internal_proto.h
+++ b/include/internal_proto.h
@@ -178,7 +178,10 @@ struct epoch_log {
 	uint32_t epoch;
 	uint32_t nr_nodes;
 	uint8_t  disable_recovery;
-	uint8_t  __pad[3];
+	uint8_t  nr_copies;
+	uint8_t  copy_policy;
+	uint8_t  __pad[1];
+	char drv_name[STORE_LEN];
 	struct sd_node nodes[SD_MAX_NODES];
 };
 
diff --git a/sheep/ops.c b/sheep/ops.c
index 4dffa86..75a2565 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -445,8 +445,18 @@ static int local_stat_cluster(struct request *req)
 
 		elog = (struct epoch_log *)req->data + i;
 		memset(elog, 0, sizeof(*elog));
+
+		/* some filed only need to store in first elog */
+		if (i == 0) {
+			elog->ctime = sys->cinfo.ctime;
+			elog->disable_recovery = sys->cinfo.disable_recovery;
+			elog->nr_copies = sys->cinfo.nr_copies;
+			elog->copy_policy = sys->cinfo.copy_policy;
+			strncpy(elog->drv_name, (char *)sys->cinfo.store,
+				STORE_LEN);
+		}
+
 		elog->epoch = epoch;
-		elog->ctime = sys->cinfo.ctime;
 		nr_nodes = epoch_log_read_with_timestamp(epoch, elog->nodes,
 							 sizeof(elog->nodes),
 							 (time_t *)&elog->time);
@@ -459,7 +469,6 @@ static int local_stat_cluster(struct request *req)
 		assert(nr_nodes <= SD_MAX_NODES);
 		elog->nr_nodes = nr_nodes;
 
-		elog->disable_recovery = sys->cinfo.disable_recovery;
 
 		rsp->data_length += sizeof(*elog);
 		epoch--;
-- 
1.7.12.4




More information about the sheepdog mailing list