cli: change volume create syntax of arbiter volume

fixes: bz#1596524
updates: gluster/glusterd2#515
Change-Id: I8a46fa2fd1fd2b0e9fbcecd3bb18d348aed9c6a9
Signed-off-by: Amar Tumballi <amarts@redhat.com>
This commit is contained in:
Amar Tumballi 2018-06-28 15:47:04 +05:30 committed by Atin Mukherjee
parent 451fd20fc8
commit a585425aad
2 changed files with 40 additions and 29 deletions

View File

@ -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:

View File

@ -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