[sheepdog] [PATCH] dog: permit two or more depth of subcommands

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Mon Nov 11 11:48:11 CET 2013


Current dog command dies when user invokes "dog node log level set"
without any arguments because of its subcommand design. This patch
removes this limitation.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 dog/cluster.c |    4 ++--
 dog/common.c  |    5 +++--
 dog/dog.h     |    3 ++-
 dog/node.c    |    6 +++---
 dog/trace.c   |    2 +-
 dog/vdi.c     |    2 +-
 6 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/dog/cluster.c b/dog/cluster.c
index c2f97ad..c508f15 100644
--- a/dog/cluster.c
+++ b/dog/cluster.c
@@ -441,7 +441,7 @@ static struct subcommand cluster_recover_cmd[] = {
 
 static int cluster_recover(int argc, char **argv)
 {
-	return do_generic_subcommand(cluster_recover_cmd, argc, argv);
+	return do_generic_subcommand(cluster_recover_cmd, 0, argc, argv);
 }
 
 /* Subcommand list of snapshot */
@@ -458,7 +458,7 @@ static struct subcommand cluster_snapshot_cmd[] = {
 
 static int cluster_snapshot(int argc, char **argv)
 {
-	return do_generic_subcommand(cluster_snapshot_cmd, argc, argv);
+	return do_generic_subcommand(cluster_snapshot_cmd, 0, argc, argv);
 }
 
 static int cluster_reweight(int argc, char **argv)
diff --git a/dog/common.c b/dog/common.c
index 4480b99..90b43ad 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -224,7 +224,8 @@ int send_light_req(const struct node_id *nid, struct sd_req *hdr)
 	return 0;
 }
 
-int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
+int do_generic_subcommand(struct subcommand *sub, int depth,
+			  int argc, char **argv)
 {
 	int i, ret;
 
@@ -240,7 +241,7 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 				}
 			}
 
-			if (flags & CMD_NEED_ARG && argc < 5)
+			if (flags & CMD_NEED_ARG && argc < 5 + depth)
 				subcommand_usage(argv[1], argv[2], EXIT_USAGE);
 			optind++;
 			ret = sub[i].fn(argc, argv);
diff --git a/dog/dog.h b/dog/dog.h
index 28c36a1..5ed3657 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -73,7 +73,8 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
 		    uint8_t copies, uint8_t, bool create, bool direct);
 int dog_exec_req(const struct node_id *, struct sd_req *hdr, void *data);
 int send_light_req(const struct node_id *, struct sd_req *hdr);
-int do_generic_subcommand(struct subcommand *sub, int argc, char **argv);
+int do_generic_subcommand(struct subcommand *sub, int depth,
+			  int argc, char **argv);
 int update_node_list(int max_nodes);
 void confirm(const char *message);
 void work_queue_wait(struct work_queue *q);
diff --git a/dog/node.c b/dog/node.c
index f896078..abe80f5 100644
--- a/dog/node.c
+++ b/dog/node.c
@@ -417,7 +417,7 @@ static struct subcommand node_md_cmd[] = {
 
 static int node_md(int argc, char **argv)
 {
-	return do_generic_subcommand(node_md_cmd, argc, argv);
+	return do_generic_subcommand(node_md_cmd, 0, argc, argv);
 }
 
 static int node_parser(int ch, const char *opt)
@@ -516,7 +516,7 @@ static struct subcommand node_log_level_cmd[] = {
 
 static int node_log_level(int argc, char **argv)
 {
-	return do_generic_subcommand(node_log_level_cmd, argc, argv);
+	return do_generic_subcommand(node_log_level_cmd, 1, argc, argv);
 }
 
 static struct subcommand node_log_cmd[] = {
@@ -527,7 +527,7 @@ static struct subcommand node_log_cmd[] = {
 
 static int node_log(int argc, char **argv)
 {
-	return do_generic_subcommand(node_log_cmd, argc, argv);
+	return do_generic_subcommand(node_log_cmd, 0, argc, argv);
 }
 
 static struct subcommand node_cmd[] = {
diff --git a/dog/trace.c b/dog/trace.c
index 806a3dd..ef69adf 100644
--- a/dog/trace.c
+++ b/dog/trace.c
@@ -355,7 +355,7 @@ static struct subcommand graph_cmd[] = {
 
 static int trace_graph(int argc, char **argv)
 {
-	return do_generic_subcommand(graph_cmd, argc, argv);
+	return do_generic_subcommand(graph_cmd, 0, argc, argv);
 }
 
 /* Subcommand list of trace */
diff --git a/dog/vdi.c b/dog/vdi.c
index d9a9a0f..3164c0e 100644
--- a/dog/vdi.c
+++ b/dog/vdi.c
@@ -2214,7 +2214,7 @@ static struct subcommand vdi_cache_cmd[] = {
 
 static int vdi_cache(int argc, char **argv)
 {
-	return do_generic_subcommand(vdi_cache_cmd, argc, argv);
+	return do_generic_subcommand(vdi_cache_cmd, 0, argc, argv);
 }
 
 static struct subcommand vdi_cmd[] = {
-- 
1.7.10.4




More information about the sheepdog mailing list