summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkarthik-us <ksubrahm@redhat.com>2017-12-28 18:42:16 +0530
committerPranith Kumar Karampuri <pkarampu@redhat.com>2017-12-29 11:19:52 +0000
commitcc425b0de57d574f6e68b6ef5edfdf99cd8353af (patch)
treea505876a90b0669999697ef4a25aa877dc20646c
parente126368f6b5231fb2acf307fbd8e343e52d61885 (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>
-rw-r--r--xlators/cluster/afr/src/afr.c3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volume-set.c45
2 files changed, 42 insertions, 6 deletions
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
index aee150123ba..10b6c2f9463 100644
--- a/xlators/cluster/afr/src/afr.c
+++ b/xlators/cluster/afr/src/afr.c
@@ -1035,8 +1035,9 @@ struct volume_options options[] = {
.flags = OPT_FLAG_CLIENT_OPT | OPT_FLAG_SETTABLE | OPT_FLAG_DOC,
.tags = {"replicate"},
/*.option = quorum-count*/
+ /*.validate_fn = validate_quorum_count*/
.description = "If quorum-type is \"fixed\" only allow writes if "
- "this many bricks or present. Other quorum types "
+ "this many bricks are present. Other quorum types "
"will OVERWRITE this value.",
},
{ .key = {"quorum-reads"},
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",