d1681e
From 45481e3e7ca074eb405b0db5521d4ca08bb20641 Mon Sep 17 00:00:00 2001
d1681e
From: karthik-us <ksubrahm@redhat.com>
d1681e
Date: Fri, 9 Mar 2018 14:45:07 +0530
d1681e
Subject: [PATCH 203/212] mgmt/glusterd: Adding validation for setting
d1681e
 quorum-count
d1681e
d1681e
In a replicated volume it was allowing to set the quorum-count value
d1681e
between the range [1 - 2147483647]. This patch adds validation for
d1681e
allowing only maximum of replica_count number of quorum-count value
d1681e
to be set on a volume.
d1681e
d1681e
Upstream patch: https://review.gluster.org/#/c/19104/
d1681e
d1681e
> Change-Id: I13952f3c6cf498c9f2b91161503fc0fba9d94898
d1681e
> BUG: 1529515
d1681e
> Signed-off-by: karthik-us <ksubrahm@redhat.com>
d1681e
d1681e
Change-Id: Ie4a74184ae640703524f371f4a0de6d70a6e9abb
d1681e
BUG: 1186664
d1681e
Signed-off-by: karthik-us <ksubrahm@redhat.com>
d1681e
Reviewed-on: https://code.engineering.redhat.com/gerrit/132255
d1681e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
d1681e
Tested-by: RHGS Build Bot <nigelb@redhat.com>
d1681e
---
d1681e
 xlators/cluster/afr/src/afr.c                   |  2 +-
d1681e
 xlators/mgmt/glusterd/src/glusterd-volume-set.c | 45 ++++++++++++++++++++++---
d1681e
 2 files changed, 41 insertions(+), 6 deletions(-)
d1681e
d1681e
diff --git a/xlators/cluster/afr/src/afr.c b/xlators/cluster/afr/src/afr.c
d1681e
index dec6e60..0122b7f 100644
d1681e
--- a/xlators/cluster/afr/src/afr.c
d1681e
+++ b/xlators/cluster/afr/src/afr.c
d1681e
@@ -959,7 +959,7 @@ struct volume_options options[] = {
d1681e
           .max = INT_MAX,
d1681e
           .default_value = 0,
d1681e
           .description = "If quorum-type is \"fixed\" only allow writes if "
d1681e
-                         "this many bricks or present.  Other quorum types "
d1681e
+                         "this many bricks are present.  Other quorum types "
d1681e
                          "will OVERWRITE this value.",
d1681e
         },
d1681e
         { .key = {"quorum-reads"},
d1681e
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
d1681e
index 8d3407d..d01e282 100644
d1681e
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
d1681e
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
d1681e
@@ -847,6 +847,40 @@ out:
d1681e
 }
d1681e
 
d1681e
 static int
d1681e
+validate_quorum_count (glusterd_volinfo_t *volinfo, dict_t *dict, char *key,
d1681e
+                       char *value, char **op_errstr)
d1681e
+{
d1681e
+        int                  ret           = 0;
d1681e
+        xlator_t            *this          = NULL;
d1681e
+        int                  q_count       = 0;
d1681e
+
d1681e
+        this = THIS;
d1681e
+        GF_ASSERT (this);
d1681e
+
d1681e
+        ret = gf_string2int (value, &q_count);
d1681e
+        if (ret) {
d1681e
+                gf_asprintf (op_errstr, "%s is not an integer. %s expects a "
d1681e
+                             "valid integer value.", value, key);
d1681e
+                goto out;
d1681e
+        }
d1681e
+
d1681e
+        if (q_count < 1 || q_count > volinfo->replica_count) {
d1681e
+                gf_asprintf (op_errstr, "%d in %s %d is out of range [1 - %d]",
d1681e
+                             q_count, key, q_count, volinfo->replica_count);
d1681e
+                ret = -1;
d1681e
+        }
d1681e
+
d1681e
+out:
d1681e
+        if (ret) {
d1681e
+                gf_msg (this->name, GF_LOG_ERROR, 0, GD_MSG_INVALID_ENTRY, "%s",
d1681e
+                        *op_errstr);
d1681e
+        }
d1681e
+        gf_msg_debug (this->name, 0, "Returning %d", ret);
d1681e
+
d1681e
+        return ret;
d1681e
+}
d1681e
+
d1681e
+static int
d1681e
 validate_subvols_per_directory (glusterd_volinfo_t *volinfo, dict_t *dict,
d1681e
                                 char *key, char *value, char **op_errstr)
d1681e
 {
d1681e
@@ -1456,11 +1490,12 @@ struct volopt_map_entry glusterd_volopt_map[] = {
d1681e
           .op_version = 1,
d1681e
           .flags      = OPT_FLAG_CLIENT_OPT
d1681e
         },
d1681e
-        { .key        = "cluster.quorum-count",
d1681e
-          .voltype    = "cluster/replicate",
d1681e
-          .option     = "quorum-count",
d1681e
-          .op_version = 1,
d1681e
-          .flags      = OPT_FLAG_CLIENT_OPT
d1681e
+        { .key         = "cluster.quorum-count",
d1681e
+          .voltype     = "cluster/replicate",
d1681e
+          .option      = "quorum-count",
d1681e
+          .op_version  = 1,
d1681e
+          .validate_fn = validate_quorum_count,
d1681e
+          .flags       = OPT_FLAG_CLIENT_OPT
d1681e
         },
d1681e
         { .key        = "cluster.choose-local",
d1681e
           .voltype    = "cluster/replicate",
d1681e
-- 
d1681e
1.8.3.1
d1681e