cb8e9e
From a415d682160dbb9cb86fcfd5c0371dc575de22ab Mon Sep 17 00:00:00 2001
cb8e9e
From: Gaurav Kumar Garg <ggarg@redhat.com>
cb8e9e
Date: Mon, 8 Jun 2015 13:01:44 +0530
cb8e9e
Subject: [PATCH 281/304] bitrot/glusterd: gluster volume set command for bitrot should not supported
cb8e9e
cb8e9e
This patch is backport of: http://review.gluster.org/11118
cb8e9e
cb8e9e
Currently gluster volume set <VOLNAME> bitrot succeeds. gluster volume
cb8e9e
set command for bitrot is not supported.
cb8e9e
Gluster should only accept gluster volume bitrot <VOLNAME> * commands.
cb8e9e
cb8e9e
    >>Change-Id: I5ff4b79f202ad018c76188f19d6311aad0d7c166
cb8e9e
    >>BUG: 1229134
cb8e9e
    >>Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com>
cb8e9e
cb8e9e
BUG: 1228135
cb8e9e
Change-Id: I6a9e3d07023021e5f910c8e7f436f9b64d48a277
cb8e9e
Signed-off-by: Gaurav Kumar Garg <ggarg@redhat.com>
cb8e9e
Reviewed-on: https://code.engineering.redhat.com/gerrit/55756
cb8e9e
Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
cb8e9e
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
cb8e9e
Tested-by: Atin Mukherjee <amukherj@redhat.com>
cb8e9e
---
cb8e9e
 .../bitrot/bug-1229134-bitd-not-support-vol-set.t  |   38 ++++++++++++++
cb8e9e
 xlators/mgmt/glusterd/src/glusterd-op-sm.c         |   53 ++++++++++++++++++++
cb8e9e
 2 files changed, 91 insertions(+), 0 deletions(-)
cb8e9e
 create mode 100644 tests/bugs/bitrot/bug-1229134-bitd-not-support-vol-set.t
cb8e9e
cb8e9e
diff --git a/tests/bugs/bitrot/bug-1229134-bitd-not-support-vol-set.t b/tests/bugs/bitrot/bug-1229134-bitd-not-support-vol-set.t
cb8e9e
new file mode 100644
cb8e9e
index 0000000..471471f
cb8e9e
--- /dev/null
cb8e9e
+++ b/tests/bugs/bitrot/bug-1229134-bitd-not-support-vol-set.t
cb8e9e
@@ -0,0 +1,38 @@
cb8e9e
+#!/bin/bash
cb8e9e
+
cb8e9e
+## Test case for bitrot BZ:1229134
cb8e9e
+## gluster volume set <VOLNAME> bitrot * command succeeds,
cb8e9e
+## which is not supported to enable bitrot.
cb8e9e
+
cb8e9e
+. $(dirname $0)/../../include.rc
cb8e9e
+. $(dirname $0)/../../volume.rc
cb8e9e
+. $(dirname $0)/../../cluster.rc
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
+
cb8e9e
+## Start glusterd
cb8e9e
+TEST glusterd;
cb8e9e
+TEST pidof glusterd;
cb8e9e
+
cb8e9e
+## Lets create and start the volume
cb8e9e
+TEST $CLI volume create $V0 $H0:$B0/${V0}{1..2}
cb8e9e
+TEST $CLI volume start $V0
cb8e9e
+
cb8e9e
+## 'gluster volume set <VOLNAME>' command for bitrot should failed.
cb8e9e
+TEST ! $CLI volume set $V0 bitrot enable
cb8e9e
+TEST ! $CLI volume set $V0 bitrot disable
cb8e9e
+TEST ! $CLI volume set $V0 scrub-frequency daily
cb8e9e
+TEST ! $CLI volume set $V0 scrub pause
cb8e9e
+TEST ! $CLI volume set $V0 scrub-throttle lazy
cb8e9e
+
cb8e9e
+
cb8e9e
+## 'gluster volume bitrot <VOLNAME> *' command for bitrot should succeeds.
cb8e9e
+TEST $CLI volume bitrot $V0 enable
cb8e9e
+EXPECT_WITHIN $PROCESS_UP_TIMEOUT "1" get_bitd_count
cb8e9e
+
cb8e9e
+TEST $CLI volume bitrot $V0 scrub pause
cb8e9e
+TEST $CLI volume bitrot $V0 scrub-frequency daily
cb8e9e
+TEST $CLI volume bitrot $V0 scrub-throttle lazy
cb8e9e
+
cb8e9e
+cleanup;
cb8e9e
+
cb8e9e
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
cb8e9e
index 4b06482..1c8925c 100644
cb8e9e
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
cb8e9e
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
cb8e9e
@@ -447,6 +447,54 @@ glusterd_op_sm_inject_all_acc (uuid_t *txn_id)
cb8e9e
 }
cb8e9e
 
cb8e9e
 static int
cb8e9e
+glusterd_check_bitrot_cmd (char *key, char *value, char *errstr, size_t size)
cb8e9e
+{
cb8e9e
+        int     ret = -1;
cb8e9e
+
cb8e9e
+        if ((!strncmp (key, "bitrot", strlen ("bitrot"))) ||
cb8e9e
+            (!strncmp (key, "features.bitrot", strlen ("features.bitrot")))) {
cb8e9e
+                snprintf (errstr, size, " 'gluster volume set <VOLNAME> %s' "
cb8e9e
+                          "is invalid command. Use 'gluster volume bitrot "
cb8e9e
+                          "<VOLNAME> {enable|disable}' instead.", key);
cb8e9e
+                ret = -1;
cb8e9e
+                goto out;
cb8e9e
+        } else if ((!strncmp (key, "scrub-freq", strlen ("scrub-freq"))) ||
cb8e9e
+                   (!strncmp (key, "features.scrub-freq",
cb8e9e
+                    strlen ("features.scrub-freq")))) {
cb8e9e
+                snprintf (errstr, size, " 'gluster volume "
cb8e9e
+                          "set <VOLNAME> %s' is invalid command. Use 'gluster "
cb8e9e
+                          "volume bitrot <VOLNAME> scrub-frequency"
cb8e9e
+                          " {hourly|daily|weekly|biweekly|monthly}' instead.",
cb8e9e
+                          key);
cb8e9e
+                ret = -1;
cb8e9e
+                goto out;
cb8e9e
+        } else if ((!strncmp (key, "scrub", strlen ("scrub"))) ||
cb8e9e
+                  (!strncmp (key, "features.scrub",
cb8e9e
+                   strlen ("features.scrub")))) {
cb8e9e
+                snprintf (errstr, size, " 'gluster volume set <VOLNAME> %s' is "
cb8e9e
+                          "invalid command. Use 'gluster volume bitrot "
cb8e9e
+                          "<VOLNAME> scrub {pause|resume}' instead.", key);
cb8e9e
+                ret = -1;
cb8e9e
+                goto out;
cb8e9e
+        } else if ((!strncmp (key, "scrub-throttle",
cb8e9e
+                     strlen ("scrub-throttle"))) ||
cb8e9e
+                   (!strncmp (key, "features.scrub-throttle",
cb8e9e
+                     strlen ("features.scrub-throttle")))) {
cb8e9e
+                snprintf (errstr, size, " 'gluster volume set <VOLNAME> %s' is "
cb8e9e
+                          "invalid command. Use 'gluster volume bitrot "
cb8e9e
+                          "<VOLNAME> scrub-throttle {lazy|normal|aggressive}' "
cb8e9e
+                          "instead.",
cb8e9e
+                          key);
cb8e9e
+                ret = -1;
cb8e9e
+                goto out;
cb8e9e
+        }
cb8e9e
+
cb8e9e
+        ret = 0;
cb8e9e
+out:
cb8e9e
+        return ret;
cb8e9e
+}
cb8e9e
+
cb8e9e
+static int
cb8e9e
 glusterd_check_quota_cmd (char *key, char *value, char *errstr, size_t size)
cb8e9e
 {
cb8e9e
         int                ret = -1;
cb8e9e
@@ -975,6 +1023,11 @@ glusterd_op_stage_set_volume (dict_t *dict, char **op_errstr)
cb8e9e
                         }
cb8e9e
                 }
cb8e9e
 
cb8e9e
+                ret = glusterd_check_bitrot_cmd (key, value, errstr,
cb8e9e
+                                                 sizeof (errstr));
cb8e9e
+                if (ret)
cb8e9e
+                        goto out;
cb8e9e
+
cb8e9e
                 ret = glusterd_check_quota_cmd (key, value, errstr, sizeof (errstr));
cb8e9e
                 if (ret)
cb8e9e
                         goto out;
cb8e9e
-- 
cb8e9e
1.7.1
cb8e9e