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