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