summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-cmd-parser.c56
-rw-r--r--tests/basic/afr/arbiter-cli.t13
2 files changed, 40 insertions, 29 deletions
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:
diff --git a/tests/basic/afr/arbiter-cli.t b/tests/basic/afr/arbiter-cli.t
index 2806b5a376b..ad79de79d02 100644
--- a/tests/basic/afr/arbiter-cli.t
+++ b/tests/basic/afr/arbiter-cli.t
@@ -16,10 +16,15 @@ TEST ! $CLI volume create $V0 arbiter 3 $H0:$B0/${V0}{0,1,2}
# replica count given after arbiter count.
TEST ! $CLI volume create $V0 arbiter 1 replica 3 $H0:$B0/${V0}{0,1,2}
-#Incorrect values for replica and arbiter count.
-TEST ! $CLI volume create $V0 replica 2 arbiter 1 $H0:$B0/${V0}{0,1,2}
+# Incorrect values for replica and arbiter count.
TEST ! $CLI volume create $V0 replica 3 arbiter 2 $H0:$B0/${V0}{0,1,2}
-# Only permissible value is replica=3 and arbiter=1.
-TEST $CLI volume create $V0 replica 3 arbiter 1 $H0:$B0/${V0}{0,1,2}
+# Correct setup
+# Only documented value is replica=2 and arbiter=1.
+TEST $CLI volume create $V0 replica 2 arbiter 1 $H0:$B0/${V0}{0,1,2}
+
+# Earlier documents mentioned 'replica 3 arbiter 1' as the valid option
+# Preserve backward compatibility till Oct, 2019.
+TEST $CLI volume create ${V0}-old replica 3 arbiter 1 $H0:$B0/${V0}-old{0,1,2}
+
cleanup