Blob Blame History Raw
From 27a3fd3e46dcfd46f81a5989789313e1bc78da19 Mon Sep 17 00:00:00 2001
From: Mohammed Rafi KC <rkavunga@redhat.com>
Date: Mon, 11 May 2015 14:43:23 +0530
Subject: [PATCH 119/129] tier/volume set: Validate volume set option for tier

Backport of http://review.gluster.org/#/c/10751/

Volume set option related to tier volume can only be set
for tier volume, also currently all volume set i for tier
option accepts a non-negative integer. This patch validate
both condition.

Change-Id: I3611af048ff4ab193544058cace8db205ea92336
BUG: 1216960
Signed-off-by: Joseph Fernandes <josferna@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50617
Reviewed-by: Dan Lambright <dlambrig@redhat.com>
Tested-by: Dan Lambright <dlambrig@redhat.com>
---
 tests/basic/tier/tier.t                         |   21 ++++--
 xlators/mgmt/glusterd/src/glusterd-volume-set.c |   82 +++++++++++++++++++++-
 2 files changed, 93 insertions(+), 10 deletions(-)

diff --git a/tests/basic/tier/tier.t b/tests/basic/tier/tier.t
index 2a5f748..bec34ef 100755
--- a/tests/basic/tier/tier.t
+++ b/tests/basic/tier/tier.t
@@ -52,8 +52,6 @@ function confirm_vol_stopped {
     fi
 }
 
-LAST_BRICK=1
-CACHE_BRICK=2
 DEMOTE_TIMEOUT=12
 PROMOTE_TIMEOUT=5
 MIGRATION_TIMEOUT=10
@@ -67,16 +65,27 @@ TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{0..$LAST_BRICK}
 TEST ! $CLI volume attach-tier $V0 replica 5 $H0:$B0/${V0}$CACHE_BRICK_FIRST $H0:$B0/${V0}$CACHE_BRICK_LAST
 
 TEST $CLI volume start $V0
-TEST $CLI volume set $V0 cluster.tier-demote-frequency 4
-TEST $CLI volume set $V0 cluster.tier-promote-frequency 4
-TEST $CLI volume set $V0 cluster.read-freq-threshold 0
-TEST $CLI volume set $V0 cluster.write-freq-threshold 0
+
 TEST $CLI volume set $V0 performance.quick-read off
 TEST $CLI volume set $V0 performance.io-cache off
 TEST $CLI volume set $V0 features.ctr-enabled on
 
+#Not a tier volume
+TEST ! $CLI volume set $V0 cluster.tier-demote-frequency 4
+
 TEST $CLI volume attach-tier $V0 replica 2 $H0:$B0/${V0}$CACHE_BRICK_FIRST $H0:$B0/${V0}$CACHE_BRICK_LAST
 
+#Tier options expect non-negative value
+TEST ! $CLI volume set $V0 cluster.tier-promote-frequency -1
+
+#Tier options expect non-negative value
+TEST ! $CLI volume set $V0 cluster.read-freq-threshold qwerty
+
+TEST $CLI volume set $V0 cluster.tier-demote-frequency 4
+TEST $CLI volume set $V0 cluster.tier-promote-frequency 4
+TEST $CLI volume set $V0 cluster.read-freq-threshold 0
+TEST $CLI volume set $V0 cluster.write-freq-threshold 0
+
 TEST $GFS --volfile-id=/$V0 --volfile-server=$H0 $M0;
 
 # Basic operations.
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
index 415bc01..34c9fc5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
@@ -17,6 +17,76 @@
 #include "glusterd-utils.h"
 
 static int
+validate_tier (glusterd_volinfo_t *volinfo, dict_t *dict, char *key,
+               char *value, char **op_errstr)
+{
+        char                 errstr[2048]  = "";
+        int                  ret           = 0;
+        xlator_t            *this          = NULL;
+        int                  origin_val    = -1;
+
+        this = THIS;
+        GF_ASSERT (this);
+
+        if (volinfo->type != GF_CLUSTER_TYPE_TIER) {
+                snprintf (errstr, sizeof (errstr), "Volume %s is not a tier "
+                          "volume. Option %s is only valid for tier volume.",
+                          volinfo->volname, key);
+                gf_log (this->name, GF_LOG_ERROR, "%s", errstr);
+                *op_errstr = gf_strdup (errstr);
+                ret = -1;
+                goto out;
+        }
+
+        /*
+         * All the volume set options for tier are expecting a positive
+         * Integer. Change the function accordingly if this constraint is
+         * changed.
+         */
+
+        ret = gf_string2int (value, &origin_val);
+        if (ret) {
+                snprintf (errstr, sizeof (errstr), "%s is not a compatible "
+                          "value. %s expects an integer value.",
+                          value, key);
+                gf_log (this->name, GF_LOG_ERROR, "%s", errstr);
+                *op_errstr = gf_strdup (errstr);
+                ret = -1;
+                goto out;
+        }
+
+        if (strstr ("cluster.tier-promote-frequency", key) ||
+            strstr ("cluster.tier-demote-frequency", key)) {
+                if (origin_val < 1) {
+                        snprintf (errstr, sizeof (errstr), "%s is not a "
+                                  "compatible value. %s expects a positive "
+                                  "integer value.",
+                                  value, key);
+                        gf_log (this->name, GF_LOG_ERROR, "%s", errstr);
+                        *op_errstr = gf_strdup (errstr);
+                        ret = -1;
+                        goto out;
+                }
+        } else {
+                if (origin_val < 0) {
+                        snprintf (errstr, sizeof (errstr), "%s is not a "
+                                   "compatible value. %s expects a non-negative"
+                                   " integer value.",
+                                   value, key);
+                         gf_log (this->name, GF_LOG_ERROR, "%s", errstr);
+                         *op_errstr = gf_strdup (errstr);
+                         ret = -1;
+                        goto out;
+                }
+        }
+
+out:
+        gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret);
+
+        return ret;
+}
+
+static int
 validate_cache_max_min_size (glusterd_volinfo_t *volinfo, dict_t *dict,
                              char *key, char *value, char **op_errstr)
 {
@@ -1764,25 +1834,29 @@ struct volopt_map_entry glusterd_volopt_map[] = {
           .voltype     = "cluster/tier",
           .option      = "write-freq-threshold",
           .op_version  = GD_OP_VERSION_3_7_0,
-          .flags       = OPT_FLAG_CLIENT_OPT
+          .flags       = OPT_FLAG_CLIENT_OPT,
+          .validate_fn = validate_tier
         },
         { .key         = "cluster.read-freq-threshold",
           .voltype     = "cluster/tier",
           .option      = "read-freq-threshold",
           .op_version  = GD_OP_VERSION_3_7_0,
-          .flags       = OPT_FLAG_CLIENT_OPT
+          .flags       = OPT_FLAG_CLIENT_OPT,
+          .validate_fn = validate_tier
         },
         { .key         = "cluster.tier-promote-frequency",
           .voltype     = "cluster/tier",
           .option      = "tier-promote-frequency",
           .op_version  = GD_OP_VERSION_3_7_0,
-          .flags       = OPT_FLAG_CLIENT_OPT
+          .flags       = OPT_FLAG_CLIENT_OPT,
+          .validate_fn = validate_tier
         },
         { .key         = "cluster.tier-demote-frequency",
           .voltype     = "cluster/tier",
           .option      = "tier-demote-frequency",
           .op_version  = GD_OP_VERSION_3_7_0,
-          .flags       = OPT_FLAG_CLIENT_OPT
+          .flags       = OPT_FLAG_CLIENT_OPT,
+          .validate_fn = validate_tier
         },
         { .key         = "features.ctr-enabled",
           .voltype     = "features/changetimerecorder",
-- 
1.7.1