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

Hitoshi Mitake mitake.hitoshi at gmail.com
Mon Nov 11 14:16:57 CET 2013


From: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>

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>
---

v2: define do_generic_subcommand() as a macro for a common case (depth == 0)

 dog/common.c | 5 +++--
 dog/dog.h    | 5 ++++-
 dog/node.c   | 3 ++-
 3 files changed, 9 insertions(+), 4 deletions(-)

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..2137465 100644
--- a/dog/dog.h
+++ b/dog/dog.h
@@ -73,7 +73,10 @@ 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_with_depth(struct subcommand *sub, int depth,
+				     int argc, char **argv);
+#define do_generic_subcommand(sub, argc, argv)		\
+	do_generic_subcommand_with_depth(sub, 0, argc, 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..ff74749 100644
--- a/dog/node.c
+++ b/dog/node.c
@@ -516,7 +516,8 @@ 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_with_depth(node_log_level_cmd, 1,
+						argc, argv);
 }
 
 static struct subcommand node_log_cmd[] = {
-- 
1.8.1.2




More information about the sheepdog mailing list