summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2011-09-08 00:34:32 +0530
committerVijay Bellur <vijay@gluster.com>2011-09-09 01:51:06 -0700
commit77eb7bdfd02f2ba61847fb9c35e9e19e3da4fcc4 (patch)
tree136086f7cbb1d9742b4182cbb6cea9f71b0e43bf /cli/src
parent0a2de8337e7111d9cb860329d83b5aae3ecacd2f (diff)
cli: 'gluster create volume' - improve option parsing
now 'replica' 'stripe' and 'transport' options can be given in any order Change-Id: Ied992ae55e86028bd4f2d662ebd246db138d4548 BUG: 3521 Reviewed-on: http://review.gluster.com/370 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vijay@gluster.com>
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-parser.c219
1 files changed, 93 insertions, 126 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index af78a7c5b1d..3e68b2cce8e 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -170,9 +170,11 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
int32_t index = 0;
char *bricks = NULL;
int32_t brick_count = 0;
- char *opwords_cl[] = { "replica", "stripe", NULL };
- char *opwords_tr[] = { "transport", NULL };
+ char *opwords[] = { "replica", "stripe", "transport", NULL };
char *w = NULL;
+ int op_count = 0;
+ int32_t replica_count = 1;
+ int32_t stripe_count = 1;
GF_ASSERT (words);
GF_ASSERT (options);
@@ -215,146 +217,111 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
goto out;
}
- if (wordcount < 6) {
- /* seems no options are given, go directly to the parse_brick */
- brick_index = 3;
- type = GF_CLUSTER_TYPE_NONE;
- trans_type = gf_strdup ("tcp");
- goto parse_bricks;
- }
+ type = GF_CLUSTER_TYPE_NONE;
+ index = 3;
- w = str_getunamb (words[3], opwords_cl);
- if (!w) {
- type = GF_CLUSTER_TYPE_NONE;
- index = 3;
- } else if ((strcmp (w, "replica")) == 0) {
- type = GF_CLUSTER_TYPE_REPLICATE;
- if (wordcount < 5) {
- ret = -1;
- goto out;
- }
- count = strtol (words[4], NULL, 0);
- if (!count || (count < 2)) {
- cli_out ("replica count should be greater than 1");
- ret = -1;
- goto out;
- }
- ret = dict_set_int32 (dict, "replica-count", count);
- if (ret)
- goto out;
- index = 5;
- } else if ((strcmp (w, "stripe")) == 0) {
- type = GF_CLUSTER_TYPE_STRIPE;
- if (wordcount < 5) {
- ret = -1;
- goto out;
- }
- count = strtol (words[4], NULL, 0);
- if (!count || (count < 2)) {
- cli_out ("stripe count should be greater than 1");
- ret = -1;
- goto out;
- }
- ret = dict_set_int32 (dict, "stripe-count", count);
- if (ret)
- goto out;
- index = 5;
- } else {
- GF_ASSERT (!"opword mismatch");
+ while (op_count < 3) {
ret = -1;
- goto out;
- }
-
- /* Ie, how many bricks together forms a subvolume of distribute */
- sub_count = count;
- /* reset the count value now */
- count = 1;
+ w = str_getunamb (words[index], opwords);
+ if (!w) {
+ break;
+ } else if ((strcmp (w, "replica")) == 0) {
+ switch (type) {
+ case GF_CLUSTER_TYPE_STRIPE_REPLICATE:
+ case GF_CLUSTER_TYPE_REPLICATE:
+ cli_out ("replica option given twice");
+ goto out;
+ case GF_CLUSTER_TYPE_NONE:
+ type = GF_CLUSTER_TYPE_REPLICATE;
+ break;
+ case GF_CLUSTER_TYPE_STRIPE:
+ type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
+ break;
+ }
- /* It can be a 'stripe x replicate' (ie, RAID01) type of volume */
- w = str_getunamb (words[5], opwords_cl);
- if (w && ((strcmp (w, "replica")) == 0)) {
- if (type == GF_CLUSTER_TYPE_REPLICATE) {
- cli_out ("'replica' option is already given");
- ret = -1;
- goto out;
- }
- /* The previous one should have been 'stripe' option */
- type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
+ if (wordcount < (index+2)) {
+ ret = -1;
+ goto out;
+ }
+ replica_count = strtol (words[index+1], NULL, 0);
+ if (replica_count < 2) {
+ cli_out ("replica count should be greater than 1");
+ ret = -1;
+ goto out;
+ }
+ ret = dict_set_int32 (dict, "replica-count", replica_count);
+ if (ret)
+ goto out;
- if (wordcount < 7) {
- ret = -1;
- goto out;
- }
- count = strtol (words[6], NULL, 0);
- if (!count || (count < 2)) {
- cli_out ("replica count should be greater than 1");
- ret = -1;
- goto out;
- }
+ index += 2;
- ret = dict_set_int32 (dict, "replica-count", count);
- if (ret)
- goto out;
- index = 7;
- } else if (w && ((strcmp (w, "stripe")) == 0)) {
- if (type == GF_CLUSTER_TYPE_STRIPE) {
- cli_out ("'stripe' option is already given");
- ret = -1;
- goto out;
- }
+ } else if ((strcmp (w, "stripe")) == 0) {
+ switch (type) {
+ case GF_CLUSTER_TYPE_STRIPE_REPLICATE:
+ case GF_CLUSTER_TYPE_STRIPE:
+ cli_out ("stripe option given twice");
+ goto out;
+ case GF_CLUSTER_TYPE_NONE:
+ type = GF_CLUSTER_TYPE_STRIPE;
+ break;
+ case GF_CLUSTER_TYPE_REPLICATE:
+ type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
+ break;
+ }
+ if (wordcount < (index + 2)) {
+ ret = -1;
+ goto out;
+ }
+ stripe_count = strtol (words[index+1], NULL, 0);
+ if (stripe_count < 2) {
+ cli_out ("stripe count should be greater than 1");
+ ret = -1;
+ goto out;
+ }
+ ret = dict_set_int32 (dict, "stripe-count", stripe_count);
+ if (ret)
+ goto out;
- /* The previous one should have been 'replica' option */
- type = GF_CLUSTER_TYPE_STRIPE_REPLICATE;
+ index += 2;
- if (wordcount < 7) {
- ret = -1;
- goto out;
- }
- count = strtol (words[6], NULL, 0);
- if (!count || (count < 2)) {
- cli_out ("stripe count should be greater than 1");
+ } else if ((strcmp (w, "transport")) == 0) {
+ if (trans_type) {
+ cli_out ("'transport' option given more"
+ " than one time");
+ goto out;
+ }
+ if ((strcasecmp (words[index+1], "tcp") == 0)) {
+ trans_type = gf_strdup ("tcp");
+ } else if ((strcasecmp (words[index+1], "rdma") == 0)) {
+ trans_type = gf_strdup ("rdma");
+ } else if ((strcasecmp (words[index+1], "tcp,rdma") == 0) ||
+ (strcasecmp (words[index+1], "rdma,tcp") == 0)) {
+ trans_type = gf_strdup ("tcp,rdma");
+ } else {
+ gf_log ("", GF_LOG_ERROR, "incorrect transport"
+ " protocol specified");
+ ret = -1;
+ goto out;
+ }
+ index += 2;
+ } else {
+ GF_ASSERT (!"opword mismatch");
ret = -1;
goto out;
}
- ret = dict_set_int32 (dict, "stripe-count", count);
- if (ret)
- goto out;
- index = 7;
- } else if (w) {
- GF_ASSERT (!"opword mismatch");
- ret = -1;
- goto out;
+ op_count++;
}
- sub_count *= count;
+ if (!trans_type)
+ trans_type = gf_strdup ("tcp");
- brick_index = index;
+ sub_count = stripe_count * replica_count;
- if (str_getunamb (words[index], opwords_tr)) {
- brick_index = index+2;
- if (wordcount < (index + 2)) {
- ret = -1;
- goto out;
- }
+ /* reset the count value now */
+ count = 1;
- if ((strcasecmp (words[index+1], "tcp") == 0)) {
- trans_type = gf_strdup ("tcp");
- } else if ((strcasecmp (words[index+1], "rdma") == 0)) {
- trans_type = gf_strdup ("rdma");
- } else if ((strcasecmp (words[index+1], "tcp,rdma") == 0) ||
- (strcasecmp (words[index+1], "rdma,tcp") == 0)) {
- trans_type = gf_strdup ("tcp,rdma");
- } else {
- gf_log ("", GF_LOG_ERROR, "incorrect transport"
- " protocol specified");
- ret = -1;
- goto out;
- }
- } else {
- trans_type = gf_strdup ("tcp");
- }
+ brick_index = index;
-parse_bricks:
ret = cli_cmd_bricks_parse (words, wordcount, brick_index, &bricks,
&brick_count);
if (ret)