[sheepdog] [PATCH v2 1/5] collie: ranme SUBCMD_FLAG_XXX as CMD_XXX

Liu Yuan namei.unix at gmail.com
Sat Aug 10 17:30:31 CEST 2013


Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 collie/cluster.c |   12 ++++++------
 collie/collie.c  |    4 ++--
 collie/collie.h  |    4 ++--
 collie/common.c  |    5 ++---
 collie/node.c    |   16 ++++++++--------
 collie/trace.c   |    4 ++--
 collie/vdi.c     |   36 ++++++++++++++++++------------------
 7 files changed, 40 insertions(+), 41 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index 8826d15..7f07547 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -444,12 +444,12 @@ static int cluster_recover(int argc, char **argv)
 /* Subcommand list of snapshot */
 static struct subcommand cluster_snapshot_cmd[] = {
 	{"save", NULL, "h", "save snapshot to localpath",
-	 NULL, SUBCMD_FLAG_NEED_ARG|SUBCMD_FLAG_NEED_NODELIST,
+	 NULL, CMD_NEED_ARG|CMD_NEED_NODELIST,
 	 save_snapshot, NULL},
 	{"list", NULL, "h", "list snapshot of localpath",
-	 NULL, SUBCMD_FLAG_NEED_ARG, list_snapshot, NULL},
+	 NULL, CMD_NEED_ARG, list_snapshot, NULL},
 	{"load", NULL, "h", "load snapshot from localpath",
-	 NULL, SUBCMD_FLAG_NEED_ARG, load_snapshot, NULL},
+	 NULL, CMD_NEED_ARG, load_snapshot, NULL},
 	{NULL},
 };
 
@@ -472,17 +472,17 @@ static int cluster_reweight(int argc, char **argv)
 
 static struct subcommand cluster_cmd[] = {
 	{"info", NULL, "aprh", "show cluster information",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST, cluster_info, cluster_options},
+	 NULL, CMD_NEED_NODELIST, cluster_info, cluster_options},
 	{"format", NULL, "bcaph", "create a Sheepdog store",
 	 NULL, 0, cluster_format, cluster_options},
 	{"shutdown", NULL, "aph", "stop Sheepdog",
 	 NULL, 0, cluster_shutdown, cluster_options},
 	{"snapshot", "<tag|idx> <path>", "aph", "snapshot/restore the cluster",
-	 cluster_snapshot_cmd, SUBCMD_FLAG_NEED_ARG,
+	 cluster_snapshot_cmd, CMD_NEED_ARG,
 	 cluster_snapshot, cluster_options},
 	{"recover", NULL, "afph",
 	 "See 'collie cluster recover' for more information\n",
-	 cluster_recover_cmd, SUBCMD_FLAG_NEED_ARG,
+	 cluster_recover_cmd, CMD_NEED_ARG,
 	 cluster_recover, cluster_options},
 	{"reweight", NULL, "aph", "reweight the cluster", NULL, 0,
 	 cluster_reweight, cluster_options},
diff --git a/collie/collie.c b/collie/collie.c
index 7ea32ec..a60e5c1 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -400,7 +400,7 @@ int main(int argc, char **argv)
 	if (!is_stdout_console() || raw_output)
 		highlight = false;
 
-	if (flags & SUBCMD_FLAG_NEED_NODELIST) {
+	if (flags & CMD_NEED_NODELIST) {
 		ret = update_node_list(SD_MAX_NODES);
 		if (ret < 0) {
 			sd_err("Failed to get node list");
@@ -408,7 +408,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (flags & SUBCMD_FLAG_NEED_ARG && argc == optind)
+	if (flags & CMD_NEED_ARG && argc == optind)
 		subcommand_usage(argv[1], argv[2], EXIT_USAGE);
 
 	if (init_event(EPOLL_SIZE) < 0)
diff --git a/collie/collie.h b/collie/collie.h
index fc06ab8..6f73ec8 100644
--- a/collie/collie.h
+++ b/collie/collie.h
@@ -26,8 +26,8 @@
 #include "event.h"
 #include "config.h"
 
-#define SUBCMD_FLAG_NEED_NODELIST (1 << 0)
-#define SUBCMD_FLAG_NEED_ARG (1 << 1)
+#define CMD_NEED_NODELIST (1 << 0)
+#define CMD_NEED_ARG (1 << 1)
 
 #define UINT64_DECIMAL_SIZE 21
 
diff --git a/collie/common.c b/collie/common.c
index 9d0147c..d324ce4 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -217,7 +217,7 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 		if (!strcmp(sub[i].name, argv[optind])) {
 			unsigned long flags = sub[i].flags;
 
-			if (flags & SUBCMD_FLAG_NEED_NODELIST) {
+			if (flags & CMD_NEED_NODELIST) {
 				ret = update_node_list(SD_MAX_NODES);
 				if (ret < 0) {
 					sd_err("Failed to get node list");
@@ -225,8 +225,7 @@ int do_generic_subcommand(struct subcommand *sub, int argc, char **argv)
 				}
 			}
 
-			if (flags & SUBCMD_FLAG_NEED_ARG
-			    && argc < 5)
+			if (flags & CMD_NEED_ARG && argc < 5)
 				subcommand_usage(argv[1], argv[2], EXIT_USAGE);
 			optind++;
 			ret = sub[i].fn(argc, argv);
diff --git a/collie/node.c b/collie/node.c
index 9307b7f..830e629 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -383,11 +383,11 @@ static int md_unplug(int argc, char **argv)
 
 static struct subcommand node_md_cmd[] = {
 	{"info", NULL, NULL, "show multi-disk information",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST, md_info},
+	 NULL, CMD_NEED_NODELIST, md_info},
 	{"plug", NULL, NULL, "plug more disk(s) into node",
-	 NULL, SUBCMD_FLAG_NEED_ARG, md_plug},
+	 NULL, CMD_NEED_ARG, md_plug},
 	{"unplug", NULL, NULL, "unplug disk(s) from node",
-	 NULL, SUBCMD_FLAG_NEED_ARG, md_unplug},
+	 NULL, CMD_NEED_ARG, md_unplug},
 	{NULL},
 };
 
@@ -420,15 +420,15 @@ static struct sd_option node_options[] = {
 
 static struct subcommand node_cmd[] = {
 	{"kill", "<node id>", "aprh", "kill node", NULL,
-	 SUBCMD_FLAG_NEED_ARG | SUBCMD_FLAG_NEED_NODELIST, node_kill},
+	 CMD_NEED_ARG | CMD_NEED_NODELIST, node_kill},
 	{"list", NULL, "aprh", "list nodes", NULL,
-	 SUBCMD_FLAG_NEED_NODELIST, node_list},
+	 CMD_NEED_NODELIST, node_list},
 	{"info", NULL, "aprh", "show information about each node", NULL,
-	 SUBCMD_FLAG_NEED_NODELIST, node_info},
+	 CMD_NEED_NODELIST, node_info},
 	{"recovery", NULL, "aphPr", "show recovery information of nodes", NULL,
-	 SUBCMD_FLAG_NEED_NODELIST, node_recovery, node_options},
+	 CMD_NEED_NODELIST, node_recovery, node_options},
 	{"md", "[disks]", "apAh", "See 'collie node md' for more information",
-	 node_md_cmd, SUBCMD_FLAG_NEED_ARG, node_md, node_options},
+	 node_md_cmd, CMD_NEED_ARG, node_md, node_options},
 	{NULL,},
 };
 
diff --git a/collie/trace.c b/collie/trace.c
index 30764ce..0e42776 100644
--- a/collie/trace.c
+++ b/collie/trace.c
@@ -234,9 +234,9 @@ static int trace_parser(int ch, char *opt)
 /* Subcommand list of trace */
 static struct subcommand trace_cmd[] = {
 	{"enable", "<tracer>", "aph", "enable tracer", NULL,
-	 SUBCMD_FLAG_NEED_ARG, trace_enable},
+	 CMD_NEED_ARG, trace_enable},
 	{"disable", "<tracer>", "aph", "disable tracer", NULL,
-	 SUBCMD_FLAG_NEED_ARG, trace_disable},
+	 CMD_NEED_ARG, trace_disable},
 	{"status", NULL, "aph", "show tracer statuses", NULL,
 	 0, trace_status},
 	{"cat", NULL, "aph", "cat the output of tracers if any", NULL,
diff --git a/collie/vdi.c b/collie/vdi.c
index b09734c..bf80b2e 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -2028,9 +2028,9 @@ static int vdi_cache_info(int argc, char **argv)
 
 static struct subcommand vdi_cache_cmd[] = {
 	{"flush", NULL, NULL, "flush the cache of the vdi specified.",
-	 NULL, SUBCMD_FLAG_NEED_ARG, vdi_cache_flush},
+	 NULL, CMD_NEED_ARG, vdi_cache_flush},
 	{"delete", NULL, NULL, "delete the cache of the vdi specified in all nodes.",
-	 NULL, SUBCMD_FLAG_NEED_ARG, vdi_cache_delete},
+	 NULL, CMD_NEED_ARG, vdi_cache_delete},
 	{"info", NULL, NULL, "show usage of the cache",
 	 NULL, 0, vdi_cache_info},
 	{NULL,},
@@ -2043,22 +2043,22 @@ static int vdi_cache(int argc, char **argv)
 
 static struct subcommand vdi_cmd[] = {
 	{"check", "<vdiname>", "saph", "check and repair image's consistency",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_check, vdi_options},
 	{"create", "<vdiname> <size>", "Pcaphrv", "create an image",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_create, vdi_options},
 	{"snapshot", "<vdiname>", "saphrv", "create a snapshot",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_snapshot, vdi_options},
 	{"clone", "<src vdi> <dst vdi>", "sPcaphrv", "clone an image",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_clone, vdi_options},
 	{"delete", "<vdiname>", "saph", "delete an image",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_delete, vdi_options},
 	{"rollback", "<vdiname>", "saphfrv", "rollback to a snapshot",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_rollback, vdi_options},
 	{"list", "[vdiname]", "aprh", "list images",
 	 NULL, 0, vdi_list, vdi_options},
@@ -2067,34 +2067,34 @@ static struct subcommand vdi_cmd[] = {
 	{"graph", NULL, "aph", "show images in Graphviz dot format",
 	 NULL, 0, vdi_graph, vdi_options},
 	{"object", "<vdiname>", "isaph", "show object information in the image",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_object, vdi_options},
 	{"track", "<vdiname>", "isaph", "show the object epoch trace in the image",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_track, vdi_options},
 	{"setattr", "<vdiname> <key> [value]", "dxaph", "set a VDI attribute",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_setattr, vdi_options},
 	{"getattr", "<vdiname> <key>", "aph", "get a VDI attribute",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_getattr, vdi_options},
 	{"resize", "<vdiname> <new size>", "aph", "resize an image",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_resize, vdi_options},
 	{"read", "<vdiname> [<offset> [<len>]]", "saph", "read data from an image",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_read, vdi_options},
 	{"write", "<vdiname> [<offset> [<len>]]", "apwh", "write data to an image",
-	 NULL, SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_ARG,
 	 vdi_write, vdi_options},
 	{"backup", "<vdiname> <backup>", "sFaph", "create an incremental backup between two snapshots",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_backup, vdi_options},
 	{"restore", "<vdiname> <backup>", "saph", "restore snapshot images from a backup",
-	 NULL, SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_ARG,
+	 NULL, CMD_NEED_NODELIST|CMD_NEED_ARG,
 	 vdi_restore, vdi_options},
 	{"cache", "<vdiname>", "saph", "Run 'collie vdi cache' for more information\n",
-	 vdi_cache_cmd, SUBCMD_FLAG_NEED_ARG,
+	 vdi_cache_cmd, CMD_NEED_ARG,
 	 vdi_cache, vdi_options},
 	{NULL,},
 };
-- 
1.7.9.5




More information about the sheepdog mailing list