diff options
author | karthik-us <ksubrahm@redhat.com> | 2018-09-10 15:07:43 +0530 |
---|---|---|
committer | Atin Mukherjee <amukherj@redhat.com> | 2018-09-11 02:35:35 +0000 |
commit | f0bacb2a51fbb3cd6645ee94d83e0a01549852dc (patch) | |
tree | 4498ea18ac5f4bfa7c157d730a9ec54e26d3696b /cli | |
parent | 23fa1feaf0a3ab482628ab5b7b950d27e57fb46d (diff) |
cli: Add warning message while converting to replica 2 configuration
Currently while creating replica 2 volume we display a warning message
of ending up in split-brain. But while converting an existing volume
from other configuration to replica 2 by add-brick or remove-brick
operations we do not show any such messages.
With this fix in add-brick and remove-brick cases also we will display
the same warning message and prompt for confirmation if the configuration
changes to replica 2.
Change-Id: Ifc4ed6994a087d2403894f4e743c4eb41633276b
fixes: bz#1627044
Signed-off-by: karthik-us <ksubrahm@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 51 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 12 | ||||
-rw-r--r-- | cli/src/cli.h | 11 |
3 files changed, 59 insertions, 15 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 9ec4d312e6f..48d6ebd64a7 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1709,8 +1709,8 @@ out: } int32_t -cli_cmd_volume_add_brick_parse (const char **words, int wordcount, - dict_t **options, int *ret_type) +cli_cmd_volume_add_brick_parse (struct cli_state *state, const char **words, + int wordcount, dict_t **options, int *ret_type) { dict_t *dict = NULL; char *volname = NULL; @@ -1725,6 +1725,8 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, int index; gf_boolean_t is_force = _gf_false; int wc = wordcount; + gf_answer_t answer = GF_ANSWER_NO; + const char *question = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -1789,6 +1791,24 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, goto out; index = 7; } + + if (count == 2) { + if (strcmp (words[wordcount - 1], "force")) { + question = "Replica 2 volumes are prone to " + "split-brain. Use Arbiter or " + "Replica 3 to avaoid this. See: " + "http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/." + "\nDo you still want to continue?\n"; + answer = cli_cmd_get_confirmation (state, + question); + if (GF_ANSWER_NO == answer) { + gf_log ("cli", GF_LOG_ERROR, "Add brick" + " cancelled, exiting"); + ret = -1; + goto out; + } + } + } } else if ((strcmp (w, "stripe")) == 0) { type = GF_CLUSTER_TYPE_STRIPE; count = strtol (words[4], NULL, 0); @@ -1992,9 +2012,10 @@ out: } int32_t -cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, - dict_t **options, int *question, - int *brick_count, int32_t *comm) +cli_cmd_volume_remove_brick_parse (struct cli_state *state, const char **words, + int wordcount, dict_t **options, + int *question, int *brick_count, + int32_t *comm) { dict_t *dict = NULL; char *volname = NULL; @@ -2012,6 +2033,8 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, char *w = NULL; int32_t command = GF_OP_CMD_NONE; long count = 0; + gf_answer_t answer = GF_ANSWER_NO; + const char *ques = NULL; GF_ASSERT (words); GF_ASSERT (options); @@ -2046,6 +2069,24 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, goto out; } + if (count == 2) { + if (strcmp (words[wordcount - 1], "force")) { + ques = "Replica 2 volumes are prone to " + "split-brain. Use Arbiter or Replica 3 " + "to avaoid this. See: " + "http://docs.gluster.org/en/latest/Administrator%20Guide/Split%20brain%20and%20ways%20to%20deal%20with%20it/." + "\nDo you still want to continue?\n"; + answer = cli_cmd_get_confirmation (state, + ques); + if (GF_ANSWER_NO == answer) { + gf_log ("cli", GF_LOG_ERROR, "Remove " + "brick cancelled, exiting"); + ret = -1; + goto out; + } + } + } + ret = dict_set_int32 (dict, "replica-count", count); if (ret) goto out; diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index d8b9e25f198..3d075a326bf 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -1023,7 +1023,8 @@ cli_cmd_volume_add_brick_cbk (struct cli_state *state, if (!frame) goto out; - ret = cli_cmd_volume_add_brick_parse (words, wordcount, &options, 0); + ret = cli_cmd_volume_add_brick_parse (state, words, wordcount, &options, + 0); if (ret) { cli_usage_out (word->pattern); parse_error = 1; @@ -1155,7 +1156,8 @@ do_cli_cmd_volume_attach_tier (struct cli_state *state, if (!frame) goto out; - ret = cli_cmd_volume_add_brick_parse (words, wordcount, &options, &type); + ret = cli_cmd_volume_add_brick_parse (state, words, wordcount, &options, + &type); if (ret) { cli_usage_out (word->pattern); parse_error = 1; @@ -2032,9 +2034,9 @@ cli_cmd_volume_remove_brick_cbk (struct cli_state *state, if (!frame) goto out; - ret = cli_cmd_volume_remove_brick_parse (words, wordcount, &options, - &need_question, &brick_count, - &command); + ret = cli_cmd_volume_remove_brick_parse (state, words, wordcount, + &options, &need_question, + &brick_count, &command); if (ret) { cli_usage_out (word->pattern); parse_error = 1; diff --git a/cli/src/cli.h b/cli/src/cli.h index 3421d6911fb..9a392e4ec1d 100644 --- a/cli/src/cli.h +++ b/cli/src/cli.h @@ -261,8 +261,8 @@ cli_cmd_get_state_parse (struct cli_state *state, const char **words, int wordcount, dict_t **options, char **op_errstr); int32_t -cli_cmd_volume_add_brick_parse (const char **words, int wordcount, - dict_t **options, int *type); +cli_cmd_volume_add_brick_parse (struct cli_state *state, const char **words, + int wordcount, dict_t **options, int *type); int32_t cli_cmd_volume_detach_tier_parse (const char **words, int wordcount, @@ -277,9 +277,10 @@ cli_cmd_volume_old_tier_parse (const char **words, int wordcount, dict_t **options); int32_t -cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, - dict_t **options, int *question, - int *brick_count, int32_t *command); +cli_cmd_volume_remove_brick_parse (struct cli_state *state, const char **words, + int wordcount, dict_t **options, + int *question, int *brick_count, + int32_t *command); int32_t cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, |