From be4dee16c18e262b168c74face54cf17ca13e2f4 Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Thu, 22 Jul 2010 04:17:35 +0000 Subject: Changes for Dynamic Volume Management Signed-off-by: Amar Tumballi Signed-off-by: Vijay Bellur Signed-off-by: Anand V. Avati BUG: 1196 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1196 --- cli/src/cli-cmd-parser.c | 42 +++++++++++++++++++++++++++++++----------- cli/src/cli-cmd-volume.c | 13 ++++++++++++- cli/src/cli3_1-cops.c | 8 +------- 3 files changed, 44 insertions(+), 19 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index cffa22a7e70..6c96d0836c8 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -78,7 +78,10 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options ret = dict_set_int32 (dict, "replica-count", count); if (ret) goto out; - + if (count < 2) { + ret = -1; + goto out; + } brick_index = 5; } else if ((strcasecmp (words[3], "stripe")) == 0) { type = GF_CLUSTER_TYPE_STRIPE; @@ -91,6 +94,10 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options ret = dict_set_int32 (dict, "stripe-count", count); if (ret) goto out; + if (count < 2) { + ret = -1; + goto out; + } brick_index = 5; } else { type = GF_CLUSTER_TYPE_NONE; @@ -214,7 +221,7 @@ out: } int32_t -cli_cmd_volume_add_brick_parse (const char **words, int wordcount, +cli_cmd_volume_add_brick_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; @@ -222,9 +229,10 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, int ret = -1; gf1_cluster_type type = GF_CLUSTER_TYPE_NONE; int count = 0; - char key[50]; + //char key[50] = {0,}; int brick_count = 0, brick_index = 0; - + char brick_list[8192] = {0,}; + GF_ASSERT (words); GF_ASSERT (options); @@ -257,20 +265,32 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, brick_index = 3; } - ret = dict_set_int32 (dict, "type", type); - - if (ret) - goto out; - + strcpy (brick_list, " "); while (brick_index < wordcount) { GF_ASSERT (words[brick_index]); + if (!strchr (words[brick_index], ':')) { + gf_log ("cli", GF_LOG_ERROR, + "wrong brick type, use :"); + ret = -1; + goto out; + } + strcat (brick_list, words[brick_index]); + strcat (brick_list, " "); + ++brick_count; + ++brick_index; + /* + char key[50]; snprintf (key, 50, "brick%d", ++brick_count); ret = dict_set_str (dict, key, (char *)words[brick_index++]); if (ret) goto out; + */ } + ret = dict_set_str (dict, "bricks", brick_list); + if (ret) + goto out; ret = dict_set_int32 (dict, "count", brick_count); @@ -291,7 +311,7 @@ out: int32_t -cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, +cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, dict_t **options) { dict_t *dict = NULL; @@ -301,7 +321,7 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, int count = 0; char key[50]; int brick_count = 0, brick_index = 0; - + GF_ASSERT (words); GF_ASSERT (options); diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index d3960d06575..445432ecd03 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -36,6 +36,12 @@ extern struct rpc_clnt *global_rpc; extern rpc_clnt_prog_t *cli_rpc_prog; +void +cli_cmd_volume_start_usage () +{ + cli_out ("Usage: volume start "); +} + int cli_cmd_volume_info_cbk (struct cli_state *state, struct cli_cmd_word *word, const char **words, int wordcount) @@ -145,6 +151,11 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, goto out; //TODO: Build validation here + if (wordcount < 3) { + cli_cmd_volume_start_usage (); + goto out; + } + volname = (char *)words[2]; GF_ASSERT (volname); @@ -153,7 +164,7 @@ cli_cmd_volume_start_cbk (struct cli_state *state, struct cli_cmd_word *word, } out: - if (ret) + if (ret && volname) cli_out ("Starting Volume %s failed", volname); return ret; diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c index dc9241bc60a..444c0031d91 100644 --- a/cli/src/cli3_1-cops.c +++ b/cli/src/cli3_1-cops.c @@ -747,7 +747,6 @@ gf_cli3_1_create_volume (call_frame_t *frame, xlator_t *this, goto out; ret = dict_get_int32 (dict, "count", &req.count); - if (ret) goto out; @@ -974,19 +973,14 @@ gf_cli3_1_add_brick (call_frame_t *frame, xlator_t *this, ret = dict_get_str (dict, "volname", &req.volname); - if (ret) - goto out; - - ret = dict_get_int32 (dict, "type", (int32_t *)&req.type); - if (ret) goto out; ret = dict_get_int32 (dict, "count", &req.count); - if (ret) goto out; + ret = dict_allocate_and_serialize (dict, &req.bricks.bricks_val, (size_t *)&req.bricks.bricks_len); -- cgit