From c9800f0986a10bbde9121239590e3cb25b94c5f8 Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Tue, 12 Feb 2013 17:26:35 +0530 Subject: glusterd: changes in 'volume create' behaviour This patch incorporates all the changes suggested on the behaviour of 'volume create' command in http://review.gluster.org/#change,4214 (comment #14, to be precise). Change-Id: Iaac524a59738b177415595b18aa8a136090d3d25 BUG: 948729 Signed-off-by: Krutika Dhananjay Reviewed-on: http://review.gluster.org/4740 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- cli/src/cli-cmd-parser.c | 40 ++++++++++++++++++++++++++++++++++++---- cli/src/cli-cmd-volume.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 7 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index c09aa626..484c4a34 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -175,6 +175,8 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options #ifdef HAVE_BD_XLATOR char *dev_type = NULL; #endif + gf_boolean_t is_force = _gf_false; + int wc = wordcount; GF_ASSERT (words); GF_ASSERT (options); @@ -351,7 +353,12 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options brick_index = index; - ret = cli_cmd_bricks_parse (words, wordcount, brick_index, &bricks, + if (strcmp (words[wordcount - 1], "force") == 0) { + is_force = _gf_true; + wc = wordcount - 1; + } + + ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks, &brick_count); if (ret) goto out; @@ -422,6 +429,10 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options if (ret) goto out; + ret = dict_set_int32 (dict, "force", is_force); + if (ret) + goto out; + *options = dict; out: @@ -910,6 +921,8 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, int count = 1; char *w = NULL; int index; + gf_boolean_t is_force = _gf_false; + int wc = wordcount; GF_ASSERT (words); GF_ASSERT (options); @@ -987,7 +1000,13 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, brick_index = index; parse_bricks: - ret = cli_cmd_bricks_parse (words, wordcount, brick_index, &bricks, + + if (strcmp (words[wordcount - 1], "force") == 0) { + is_force = _gf_true; + wc = wordcount - 1; + } + + ret = cli_cmd_bricks_parse (words, wc, brick_index, &bricks, &brick_count); if (ret) goto out; @@ -998,6 +1017,10 @@ parse_bricks: ret = dict_set_int32 (dict, "count", brick_count); + if (ret) + goto out; + + ret = dict_set_int32 (dict, "force", is_force); if (ret) goto out; @@ -1203,6 +1226,7 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, char *opwords[] = { "start", "commit", "pause", "abort", "status", NULL }; char *w = NULL; + gf_boolean_t is_force = _gf_false; GF_ASSERT (words); GF_ASSERT (options); @@ -1300,12 +1324,17 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, } if (wordcount == (op_index + 1)) { - if (replace_op != GF_REPLACE_OP_COMMIT) { + if ((replace_op != GF_REPLACE_OP_COMMIT) && + (replace_op != GF_REPLACE_OP_START)) { ret = -1; goto out; } if (!strcmp ("force", words[op_index])) { - replace_op = GF_REPLACE_OP_COMMIT_FORCE; + if (replace_op == GF_REPLACE_OP_COMMIT) + replace_op = GF_REPLACE_OP_COMMIT_FORCE; + + else if (replace_op == GF_REPLACE_OP_START) + is_force = _gf_true; } } @@ -1319,6 +1348,9 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, if (ret) goto out; + ret = dict_set_int32 (dict, "force", is_force); + if (ret) + goto out; *options = dict; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index de7adfe8..aa1c7755 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -392,6 +392,15 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, } } + if (state->mode & GLUSTER_MODE_SCRIPT) { + ret = dict_set_int32 (options, "force", _gf_true); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to set force " + "option"); + goto out; + } + } + CLI_LOCAL_INIT (local, words, frame, options); if (proc->fn) { @@ -963,6 +972,15 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, } } + if (state->mode & GLUSTER_MODE_SCRIPT) { + ret = dict_set_int32 (options, "force", _gf_true); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to set force " + "option"); + goto out; + } + } + proc = &cli_rpc_prog->proctable[GLUSTER_CLI_ADD_BRICK]; CLI_LOCAL_INIT (local, words, frame, options); @@ -1131,6 +1149,15 @@ cli_cmd_volume_replace_brick_cbk (struct cli_state *state, goto out; } + if (state->mode & GLUSTER_MODE_SCRIPT) { + ret = dict_set_int32 (options, "force", _gf_true); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to set force" + "option"); + goto out; + } + } + CLI_LOCAL_INIT (local, words, frame, options); if (proc->fn) { @@ -1799,7 +1826,7 @@ struct cli_cmd volume_cmds[] = { #ifdef HAVE_BD_XLATOR "[device vg] " #endif - "[transport ] ...", + "[transport ] ... [force]", cli_cmd_volume_create_cbk, "create a new volume of specified type with mentioned bricks"}, @@ -1819,7 +1846,7 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_rename_cbk, "rename volume to "},*/ - { "volume add-brick [ ] ...", + { "volume add-brick [ ] ... [force]", cli_cmd_volume_add_brick_cbk, "add brick to volume "}, @@ -1831,7 +1858,7 @@ struct cli_cmd volume_cmds[] = { cli_cmd_volume_defrag_cbk, "rebalance operations"}, - { "volume replace-brick {start|pause|abort|status|commit [force]}", + { "volume replace-brick {start [force]|pause|abort|status|commit [force]}", cli_cmd_volume_replace_brick_cbk, "replace-brick operations"}, -- cgit