21ab4e
From d93905382b198c3a8bb4b47302519e195d168b5d Mon Sep 17 00:00:00 2001
21ab4e
From: hari gowtham <hgowtham@redhat.com>
21ab4e
Date: Tue, 19 Apr 2016 14:01:09 +0530
21ab4e
Subject: [PATCH 368/369] TIER: watermark check during low watermark reset
21ab4e
21ab4e
	backport of : https://review.gluster.org/#/c/14028/8
21ab4e
21ab4e
PROBLEM: during a low watermark reset, checking of whether
21ab4e
the low watermark is lower than hi watermark is not done.
21ab4e
21ab4e
FIX: This patch checks if the hi watermark value is higher
21ab4e
the default low watermark. Else throws an failure of the reset
21ab4e
command
21ab4e
21ab4e
>Change-Id: I8b49090c6bccce6d45c2e8076ab766047a2a6162
21ab4e
>BUG: 1328342
21ab4e
>Signed-off-by: hari gowtham <hgowtham@redhat.com>
21ab4e
>Reviewed-on: https://review.gluster.org/14028
21ab4e
>Smoke: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Tested-by: hari gowtham <hari.gowtham005@gmail.com>
21ab4e
>NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
21ab4e
>CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
21ab4e
>Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
>Signed-off-by: hari gowtham <hgowtham@redhat.com>
21ab4e
21ab4e
Change-Id: If6d0688653d6681e1a6da42988dd74aea6f5df16
21ab4e
BUG: 1315583
21ab4e
Signed-off-by: hari gowtham <hgowtham@redhat.com>
21ab4e
Reviewed-on: https://code.engineering.redhat.com/gerrit/102301
21ab4e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
21ab4e
---
21ab4e
 tests/basic/tier/tier.t                       |  6 ++
21ab4e
 xlators/mgmt/glusterd/src/glusterd-messages.h | 10 +++-
21ab4e
 xlators/mgmt/glusterd/src/glusterd-op-sm.c    | 86 +++++++++++++++++++++++++++
21ab4e
 3 files changed, 101 insertions(+), 1 deletion(-)
21ab4e
21ab4e
diff --git a/tests/basic/tier/tier.t b/tests/basic/tier/tier.t
21ab4e
index 7bac2dd..75b834d 100755
21ab4e
--- a/tests/basic/tier/tier.t
21ab4e
+++ b/tests/basic/tier/tier.t
21ab4e
@@ -113,6 +113,12 @@ TEST ! $CLI volume set $V0 cluster.watermark-low 90
21ab4e
 TEST ! $CLI volume set $V0 cluster.read-freq-threshold -12
21ab4e
 TEST ! $CLI volume set $V0 cluster.write-freq-threshold -12
21ab4e
 
21ab4e
+#check for watermark reset
21ab4e
+TEST $CLI volume set $V0 cluster.watermark-low 10
21ab4e
+TEST $CLI volume set $V0 cluster.watermark-hi 30
21ab4e
+TEST ! $CLI volume reset $V0 cluster.watermark-low
21ab4e
+TEST $CLI volume reset $V0 cluster.watermark-hi
21ab4e
+TEST $CLI volume reset $V0 cluster.watermark-low
21ab4e
 
21ab4e
 # stop the volume and restart it. The rebalance daemon should restart.
21ab4e
 cd /tmp
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-messages.h b/xlators/mgmt/glusterd/src/glusterd-messages.h
21ab4e
index 6e7e27d..4728810 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-messages.h
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-messages.h
21ab4e
@@ -41,7 +41,7 @@
21ab4e
 
21ab4e
 #define GLUSTERD_COMP_BASE      GLFS_MSGID_GLUSTERD
21ab4e
 
21ab4e
-#define GLFS_NUM_MESSAGES       597
21ab4e
+#define GLFS_NUM_MESSAGES       598
21ab4e
 
21ab4e
 #define GLFS_MSGID_END          (GLUSTERD_COMP_BASE + GLFS_NUM_MESSAGES + 1)
21ab4e
 /* Messaged with message IDs */
21ab4e
@@ -4781,6 +4781,14 @@
21ab4e
  */
21ab4e
 
21ab4e
 #define GD_MSG_NO_SIG_TO_PID_ZERO                  (GLUSTERD_COMP_BASE + 597)
21ab4e
+/*!
21ab4e
+ * @messageid
21ab4e
+ * @diagnosis
21ab4e
+ * @recommendedaction
21ab4e
+ *
21ab4e
+ */
21ab4e
+
21ab4e
+#define GD_MSG_TIER_WATERMARK_RESET_FAIL           (GLUSTERD_COMP_BASE + 598)
21ab4e
 
21ab4e
 /*------------*/
21ab4e
 
21ab4e
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
21ab4e
index dae6c1e..c78a7a4 100644
21ab4e
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
21ab4e
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
21ab4e
@@ -1442,6 +1442,82 @@ out:
21ab4e
         }
21ab4e
         return ret;
21ab4e
 }
21ab4e
+static int
21ab4e
+glusterd_water_limit_check (glusterd_volinfo_t *volinfo, gf_boolean_t is_hi,
21ab4e
+                char **op_errstr)
21ab4e
+{
21ab4e
+
21ab4e
+        int                                     ret            = -1;
21ab4e
+        char                                    *default_value = NULL;
21ab4e
+        char                                    *temp          = NULL;
21ab4e
+        uint64_t                                wm             = 0;
21ab4e
+        uint64_t                                default_wm     = 0;
21ab4e
+        struct volopt_map_entry                 *vmap          = NULL;
21ab4e
+        xlator_t                                *this          = NULL;
21ab4e
+        extern struct volopt_map_entry          glusterd_volopt_map[];
21ab4e
+        char                                    msg[2048]      = {0};
21ab4e
+
21ab4e
+        this = THIS;
21ab4e
+        GF_ASSERT (this);
21ab4e
+
21ab4e
+        if (is_hi)
21ab4e
+                ret = glusterd_volinfo_get (volinfo,
21ab4e
+                                            "cluster.watermark-low", &temp);
21ab4e
+        else
21ab4e
+                ret = glusterd_volinfo_get (volinfo,
21ab4e
+                                            "cluster.watermark-hi", &temp);
21ab4e
+        if (ret) {
21ab4e
+                gf_msg (this->name, GF_LOG_ERROR, 0,
21ab4e
+                        GD_MSG_VOLINFO_GET_FAIL, "failed to get watermark");
21ab4e
+                goto out;
21ab4e
+        }
21ab4e
+
21ab4e
+        gf_string2bytesize_uint64 (temp, &wm;;
21ab4e
+
21ab4e
+        if (is_hi)
21ab4e
+                for (vmap = glusterd_volopt_map; vmap->key; vmap++) {
21ab4e
+                        if (strcmp (vmap->key, "cluster.watermark-hi") == 0)
21ab4e
+                                default_value = vmap->value;
21ab4e
+                }
21ab4e
+        else
21ab4e
+                for (vmap = glusterd_volopt_map; vmap->key; vmap++) {
21ab4e
+                        if (strcmp (vmap->key, "cluster.watermark-low") == 0)
21ab4e
+                                default_value = vmap->value;
21ab4e
+                }
21ab4e
+
21ab4e
+        gf_string2bytesize_uint64 (default_value, &default_wm);
21ab4e
+
21ab4e
+        if (is_hi) {
21ab4e
+                if (default_wm <= wm) {
21ab4e
+                        snprintf (msg, sizeof (msg), "Resetting hi-watermark "
21ab4e
+                                  "to default will make it lower or equal to "
21ab4e
+                                  "the low-watermark, which is an invalid "
21ab4e
+                                  "configuration state. Please lower the "
21ab4e
+                                  "low-watermark first to the desired value "
21ab4e
+                                  "and then reset the hi-watermark.");
21ab4e
+                        ret = -1;
21ab4e
+                        goto out;
21ab4e
+                }
21ab4e
+        } else {
21ab4e
+                if (default_wm >= wm) {
21ab4e
+                        snprintf (msg, sizeof (msg), "Resetting low-watermark "
21ab4e
+                                  "to default will make it higher or equal to "
21ab4e
+                                  "the hi-watermark, which is an invalid "
21ab4e
+                                  "configuration state. Please raise the "
21ab4e
+                                  "hi-watermark first to the desired value "
21ab4e
+                                  "and then reset the low-watermark.");
21ab4e
+                        ret = -1;
21ab4e
+                        goto out;
21ab4e
+                }
21ab4e
+        }
21ab4e
+out:
21ab4e
+        if (msg[0] != '\0') {
21ab4e
+                gf_msg (THIS->name, GF_LOG_ERROR, 0,
21ab4e
+                        GD_MSG_TIER_WATERMARK_RESET_FAIL, "%s", msg);
21ab4e
+                *op_errstr = gf_strdup (msg);
21ab4e
+        }
21ab4e
+        return ret;
21ab4e
+}
21ab4e
 
21ab4e
 static int
21ab4e
 glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
21ab4e
@@ -1518,6 +1594,16 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
21ab4e
                 if (exists == -1) {
21ab4e
                         ret = -1;
21ab4e
                         goto out;
21ab4e
+                } else if (strcmp (key, "cluster.watermark-low") == 0) {
21ab4e
+                        ret = glusterd_water_limit_check (volinfo, _gf_false,
21ab4e
+                                        op_errstr);
21ab4e
+                        if (ret)
21ab4e
+                                return ret;
21ab4e
+                } else if (strcmp (key, "cluster.watermark-hi") == 0) {
21ab4e
+                        ret = glusterd_water_limit_check (volinfo, _gf_true,
21ab4e
+                                        op_errstr);
21ab4e
+                        if (ret)
21ab4e
+                                return ret;
21ab4e
                 }
21ab4e
 
21ab4e
                 if (!exists) {
21ab4e
-- 
21ab4e
1.8.3.1
21ab4e