diff options
author | karthik-us <ksubrahm@redhat.com> | 2017-12-28 18:42:16 +0530 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2017-12-29 11:19:52 +0000 |
commit | cc425b0de57d574f6e68b6ef5edfdf99cd8353af (patch) | |
tree | a505876a90b0669999697ef4a25aa877dc20646c /xlators/mgmt | |
parent | e126368f6b5231fb2acf307fbd8e343e52d61885 (diff) |
mgmt/glusterd: Adding validation for setting quorum-count
In a replicated volume it was allowing to set the quorum-count value
between the range [1 - 2147483647]. This patch adds validation for
allowing only maximum of replica_count number of quorum-count value
to be set on a volume.
Change-Id: I13952f3c6cf498c9f2b91161503fc0fba9d94898
BUG: 1529515
Signed-off-by: karthik-us <ksubrahm@redhat.com>
Diffstat (limited to 'xlators/mgmt')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index 2e216159d03..4f8e1e3be0e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -847,6 +847,40 @@ out: } static int +validate_quorum_count (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, + char *value, char **op_errstr) +{ + int ret = 0; + xlator_t *this = NULL; + int q_count = 0; + + this = THIS; + GF_ASSERT (this); + + ret = gf_string2int (value, &q_count); + if (ret) { + gf_asprintf (op_errstr, "%s is not an integer. %s expects a " + "valid integer value.", value, key); + goto out; + } + + if (q_count < 1 || q_count > volinfo->replica_count) { + gf_asprintf (op_errstr, "%d in %s %d is out of range [1 - %d]", + q_count, key, q_count, volinfo->replica_count); + ret = -1; + } + +out: + if (ret) { + gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_INVALID_ENTRY, "%s", + *op_errstr); + } + gf_msg_debug (this->name, 0, "Returning %d", ret); + + return ret; +} + +static int validate_subvols_per_directory (glusterd_volinfo_t *volinfo, dict_t *dict, char *key, char *value, char **op_errstr) { @@ -1456,11 +1490,12 @@ struct volopt_map_entry glusterd_volopt_map[] = { .op_version = 1, .flags = VOLOPT_FLAG_CLIENT_OPT }, - { .key = "cluster.quorum-count", - .voltype = "cluster/replicate", - .option = "quorum-count", - .op_version = 1, - .flags = VOLOPT_FLAG_CLIENT_OPT + { .key = "cluster.quorum-count", + .voltype = "cluster/replicate", + .option = "quorum-count", + .op_version = 1, + .validate_fn = validate_quorum_count, + .flags = VOLOPT_FLAG_CLIENT_OPT }, { .key = "cluster.choose-local", .voltype = "cluster/replicate", |