7f4c2a
From 6674020a7a1503f2ca1da30a622f950bfcbb34e3 Mon Sep 17 00:00:00 2001
7f4c2a
From: Manikandan Selvaganesh <mselvaga@redhat.com>
7f4c2a
Date: Wed, 5 Aug 2015 19:23:01 +0530
7f4c2a
Subject: [PATCH 275/279] quota : volume-reset shouldn't remove quota-deem-statfs
7f4c2a
7f4c2a
Volume-reset shouldn't remove quota-deem-statfs, unless
7f4c2a
explicitly specified, when quota is enabled.
7f4c2a
7f4c2a
1) glusterd_op_stage_reset_volume ()
7f4c2a
   'gluster volume set/reset <VOLNAME>' features.quota/
7f4c2a
   features.inode-quota' should not be allowed as it is deprecated.
7f4c2a
   Setting and resetting quota/inode-quota features should be allowed
7f4c2a
   only through 'gluster volume quota <VOLNAME> enable/disable'.
7f4c2a
7f4c2a
2) glusterd_enable_default_options ()
7f4c2a
   Option 'features.quota-deem-statfs' should not be turned off
7f4c2a
   with 'gluster volume reset <VOLNAME>', since quota features
7f4c2a
   can be set/reset only with 'gluster volume quota <VOLNAME>
7f4c2a
   enable/disable'.
7f4c2a
7f4c2a
But, 'gluster volume set features.quota-deem-statfs'
7f4c2a
can be turned on/off when quota is enabled.
7f4c2a
7f4c2a
> Change-Id: Ib5aa00a4d8c82819c08dfc23e2a86f43ebc436c4
7f4c2a
> BUG: 1250582
7f4c2a
> Signed-off-by: Manikandan Selvaganesh <mselvaga@redhat.com>
7f4c2a
> Reviewed-on: http://review.gluster.org/11839
7f4c2a
> Tested-by: NetBSD Build System <jenkins@build.gluster.org>
7f4c2a
> Tested-by: Gluster Build System <jenkins@build.gluster.com>
7f4c2a
> Reviewed-by: Vijaikumar Mallikarjuna <vmallika@redhat.com>
7f4c2a
> Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
7f4c2a
7f4c2a
Change-Id: Ib5aa00a4d8c82819c08dfc23e2a86f43ebc436c4
7f4c2a
BUG: 1027723
7f4c2a
Signed-off-by: Manikandan Selvaganesh <mselvaga@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/55299
7f4c2a
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
7f4c2a
Tested-by: Krishnan Parthasarathi <kparthas@redhat.com>
7f4c2a
---
7f4c2a
 ...set-should-not-remove-quota-quota-deem-statfs.t |   53 ++++++++++++++++++++
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-op-sm.c         |   31 +++++++++++
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-utils.c         |   22 ++++++++
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-volgen.h        |    1 +
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-volume-set.c    |    4 +-
7f4c2a
 5 files changed, 109 insertions(+), 2 deletions(-)
7f4c2a
 create mode 100644 tests/bugs/quota/bug-1250582-volume-reset-should-not-remove-quota-quota-deem-statfs.t
7f4c2a
7f4c2a
diff --git a/tests/bugs/quota/bug-1250582-volume-reset-should-not-remove-quota-quota-deem-statfs.t b/tests/bugs/quota/bug-1250582-volume-reset-should-not-remove-quota-quota-deem-statfs.t
7f4c2a
new file mode 100644
7f4c2a
index 0000000..3b55e73
7f4c2a
--- /dev/null
7f4c2a
+++ b/tests/bugs/quota/bug-1250582-volume-reset-should-not-remove-quota-quota-deem-statfs.t
7f4c2a
@@ -0,0 +1,53 @@
7f4c2a
+#!/bin/bash
7f4c2a
+
7f4c2a
+# This test ensures that 'gluster volume reset' command do not remove
7f4c2a
+# features.quota-deem-statfs, features.quota.
7f4c2a
+# Also, tests that 'gluster volume set features.quota-deem-statfs' can be
7f4c2a
+# turned on/off when quota is enabled.
7f4c2a
+
7f4c2a
+.  $(dirname $0)/../../include.rc
7f4c2a
+.  $(dirname $0)/../../volume.rc
7f4c2a
+
7f4c2a
+cleanup;
7f4c2a
+
7f4c2a
+TEST glusterd;
7f4c2a
+TEST pidof glusterd;
7f4c2a
+TEST $CLI volume info;
7f4c2a
+
7f4c2a
+TEST $CLI volume create $V0 replica 2 $H0:$B0/${v0}{1,2};
7f4c2a
+EXPECT 'Created' volinfo_field $V0 'Status';
7f4c2a
+
7f4c2a
+TEST $CLI volume start $V0;
7f4c2a
+EXPECT 'Started' volinfo_field $V0 'Status';
7f4c2a
+
7f4c2a
+TEST $CLI volume quota $V0 enable
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota'
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.inode-quota'
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota-deem-statfs'
7f4c2a
+
7f4c2a
+TEST $CLI volume reset $V0
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota'
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.inode-quota'
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota-deem-statfs'
7f4c2a
+
7f4c2a
+TEST $CLI volume reset $V0 force
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota'
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.inode-quota'
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota-deem-statfs'
7f4c2a
+
7f4c2a
+TEST $CLI volume reset $V0 features.quota-deem-statfs
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota-deem-statfs'
7f4c2a
+
7f4c2a
+TEST $CLI volume set $V0 features.quota-deem-statfs off
7f4c2a
+EXPECT 'off' volinfo_field $V0 'features.quota-deem-statfs'
7f4c2a
+
7f4c2a
+TEST $CLI volume set $V0 features.quota-deem-statfs on
7f4c2a
+EXPECT 'on' volinfo_field $V0 'features.quota-deem-statfs'
7f4c2a
+
7f4c2a
+TEST $CLI volume quota $V0 disable
7f4c2a
+EXPECT 'off' volinfo_field $V0 'features.quota'
7f4c2a
+EXPECT 'off' volinfo_field $V0 'features.inode-quota'
7f4c2a
+EXPECT '' volinfo_field $V0 'features.quota-deem-statfs'
7f4c2a
+
7f4c2a
+cleanup;
7f4c2a
+
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7f4c2a
index e7ad7f4..4b06482 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
7f4c2a
@@ -1376,6 +1376,26 @@ glusterd_op_stage_reset_volume (dict_t *dict, char **op_errstr)
7f4c2a
                 } else if (exists > 0) {
7f4c2a
                         if (key_fixed)
7f4c2a
                                 key = key_fixed;
7f4c2a
+
7f4c2a
+                        /* 'gluster volume set/reset <VOLNAME>
7f4c2a
+                         * features.quota/features.inode-quota' should
7f4c2a
+                         * not be allowed as it is deprecated.
7f4c2a
+                         * Setting and resetting quota/inode-quota features
7f4c2a
+                         * should be allowed only through 'gluster volume quota
7f4c2a
+                         * <VOLNAME> enable/disable'.
7f4c2a
+                         * But, 'gluster volume set features.quota-deem-statfs'
7f4c2a
+                         * can be turned on/off when quota is enabled.
7f4c2a
+                         */
7f4c2a
+
7f4c2a
+                        if (strcmp (VKEY_FEATURES_INODE_QUOTA, key) == 0 ||
7f4c2a
+                            strcmp (VKEY_FEATURES_QUOTA, key) == 0) {
7f4c2a
+                                snprintf (msg, sizeof (msg), "'gluster volume "
7f4c2a
+                                          "reset <VOLNAME> %s' is deprecated. "
7f4c2a
+                                          "Use 'gluster volume quota <VOLNAME> "
7f4c2a
+                                          "disable' instead.", key);
7f4c2a
+                                ret = -1;
7f4c2a
+                                goto out;
7f4c2a
+                        }
7f4c2a
                         ALL_VOLUME_OPTION_CHECK (volname, key, ret,
7f4c2a
                                                  op_errstr, out);
7f4c2a
                 }
7f4c2a
@@ -1734,6 +1754,17 @@ _delete_reconfig_opt (dict_t *this, char *key, data_t *value, void *data)
7f4c2a
         GF_ASSERT (data);
7f4c2a
         is_force = (int32_t*)data;
7f4c2a
 
7f4c2a
+        /* Keys which has the flag OPT_FLAG_NEVER_RESET
7f4c2a
+         * should not be deleted
7f4c2a
+         */
7f4c2a
+
7f4c2a
+        if (_gf_true == glusterd_check_voloption_flags (key,
7f4c2a
+                                                OPT_FLAG_NEVER_RESET)) {
7f4c2a
+                if (*is_force != 1)
7f4c2a
+                        *is_force = *is_force | GD_OP_PROTECTED;
7f4c2a
+                goto out;
7f4c2a
+        }
7f4c2a
+
7f4c2a
         if (*is_force != 1) {
7f4c2a
                 if (_gf_true == glusterd_check_voloption_flags (key,
7f4c2a
                                                          OPT_FLAG_FORCE)) {
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
7f4c2a
index 0101ec5..4982828 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
7f4c2a
@@ -9527,6 +9527,28 @@ glusterd_enable_default_options (glusterd_volinfo_t *volinfo, char *option)
7f4c2a
                         }
7f4c2a
                 }
7f4c2a
 
7f4c2a
+                /* Option 'features.quota-deem-statfs' should not be turned off
7f4c2a
+                 * with 'gluster volume reset <VOLNAME>', since quota features
7f4c2a
+                 * can be reset only with 'gluster volume quota <VOLNAME>
7f4c2a
+                 * disable'.
7f4c2a
+                 */
7f4c2a
+
7f4c2a
+                if (!option || !strcmp ("features.quota-deem-statfs", option)) {
7f4c2a
+                        if (glusterd_is_volume_quota_enabled(volinfo)) {
7f4c2a
+                                ret = dict_set_dynstr_with_alloc (volinfo->dict,
7f4c2a
+                                            "features.quota-deem-statfs", "on");
7f4c2a
+                                if (ret) {
7f4c2a
+                                        gf_msg (this->name, GF_LOG_ERROR, errno,
7f4c2a
+                                                GD_MSG_DICT_SET_FAILED,
7f4c2a
+                                                "Failed to set option "
7f4c2a
+                                                "'features.quota-deem-statfs' "
7f4c2a
+                                                "on volume %s",
7f4c2a
+                                                volinfo->volname);
7f4c2a
+                                        goto out;
7f4c2a
+                                }
7f4c2a
+                        }
7f4c2a
+                }
7f4c2a
+
7f4c2a
         }
7f4c2a
 out:
7f4c2a
         return ret;
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.h b/xlators/mgmt/glusterd/src/glusterd-volgen.h
7f4c2a
index 7453c0d..3128b6b 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.h
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.h
7f4c2a
@@ -91,6 +91,7 @@ typedef enum gd_volopt_flags_ {
7f4c2a
         OPT_FLAG_FORCE = 0x01,      // option needs force to be reset
7f4c2a
         OPT_FLAG_XLATOR_OPT = 0x02, // option enables/disables xlators
7f4c2a
         OPT_FLAG_CLIENT_OPT = 0x04, // option affects clients
7f4c2a
+        OPT_FLAG_NEVER_RESET = 0x08, /* option which should not be reset */
7f4c2a
 } gd_volopt_flags_t;
7f4c2a
 
7f4c2a
 typedef enum {
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
7f4c2a
index b536d18..709ac31 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c
7f4c2a
@@ -1383,7 +1383,7 @@ struct volopt_map_entry glusterd_volopt_map[] = {
7f4c2a
           .option      = "quota",
7f4c2a
           .value       = "off",
7f4c2a
           .type        = NO_DOC,
7f4c2a
-          .flags       = OPT_FLAG_FORCE,
7f4c2a
+          .flags       = OPT_FLAG_NEVER_RESET,
7f4c2a
           .op_version  = 1
7f4c2a
         },
7f4c2a
         { .key         = VKEY_FEATURES_INODE_QUOTA,
7f4c2a
@@ -1391,7 +1391,7 @@ struct volopt_map_entry glusterd_volopt_map[] = {
7f4c2a
           .option      = "inode-quota",
7f4c2a
           .value       = "off",
7f4c2a
           .type        = NO_DOC,
7f4c2a
-          .flags       = OPT_FLAG_FORCE,
7f4c2a
+          .flags       = OPT_FLAG_NEVER_RESET,
7f4c2a
           .op_version  = 1
7f4c2a
         },
7f4c2a
 
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a