From a585425aad5f07a406da26ba38c59fa0e5ad3036 Mon Sep 17 00:00:00 2001 From: Amar Tumballi Date: Thu, 28 Jun 2018 15:47:04 +0530 Subject: cli: change volume create syntax of arbiter volume fixes: bz#1596524 updates: gluster/glusterd2#515 Change-Id: I8a46fa2fd1fd2b0e9fbcecd3bb18d348aed9c6a9 Signed-off-by: Amar Tumballi --- cli/src/cli-cmd-parser.c | 56 +++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'cli/src/cli-cmd-parser.c') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 29043e09810..16b0cc81cd6 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -543,6 +543,7 @@ cli_cmd_volume_create_parse (struct cli_state *state, const char **words, ret = -1; goto out; } + replica_count = strtol (words[index+1], NULL, 0); if (replica_count < 2) { cli_err ("replica count should be greater" @@ -550,6 +551,36 @@ cli_cmd_volume_create_parse (struct cli_state *state, const char **words, ret = -1; goto out; } + + index += 2; + if (words[index]) { + if (!strcmp (words[index], "arbiter")) { + ret = gf_string2int (words[index+1], + &arbiter_count); + if ((ret == -1) || (arbiter_count != 1)) { + cli_err ("For arbiter " + "configuration, " + "replica count must be" + " 2 and arbiter count " + "must be 1. The 3rd " + "brick of the replica " + "will be the arbiter"); + ret = -1; + goto out; + } + ret = dict_set_int32 (dict, "arbiter-count", + arbiter_count); + if (ret) + goto out; + index += 2; + } + } + + /* Do this to keep glusterd happy with sending + "replica 3 arbiter 1" options to server */ + if ((arbiter_count == 1) && (replica_count == 2)) + replica_count += arbiter_count; + if (replica_count == 2) { if (strcmp (words[wordcount - 1], "force")) { question = "Replica 2 volumes are prone" @@ -574,31 +605,6 @@ cli_cmd_volume_create_parse (struct cli_state *state, const char **words, if (ret) goto out; - index += 2; - if (words[index]) { - if (!strcmp (words[index], "arbiter")) { - ret = gf_string2int (words[index+1], - &arbiter_count); - if (ret == -1 || arbiter_count != 1 || - replica_count != 3) { - cli_err ("For arbiter " - "configuration, " - "replica count must be" - " 3 and arbiter count " - "must be 1. The 3rd " - "brick of the replica " - "will be the arbiter"); - ret = -1; - goto out; - } - ret = dict_set_int32 (dict, "arbiter-count", - arbiter_count); - if (ret) - goto out; - index += 2; - } - } - } else if ((strcmp (w, "stripe")) == 0) { switch (type) { case GF_CLUSTER_TYPE_STRIPE_REPLICATE: -- cgit