summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-06-26 07:51:02 +0530
committerKaushal M <kaushal@redhat.com>2014-07-24 03:03:53 -0700
commit00bcf8e80bd65de7a8a102b137d35af3ba2cc3c1 (patch)
tree6b34aca9816d37f0b32228f586b82794d5e44d8b
parentf4110bed9230025ef7cac8e550057e316f9de1cb (diff)
cli/snapshot : Dont display the snapshot hard-limit, soft-limit
and auto-delete value in gluster volume info. Problem : Even though snap-max-hard-limit, snap-max-soft-limit and auto-delete values were not set explicitly, It was getting showed in the output of gluster volume info. Solution : Check if the value is already present in dictionary (That means, it is set), If value is not present then consider the default value, NOTE : This patch doesn't solve the problem where the values which is set globally are being displayed in gluster volume info Change-Id: I61445b3d2a12eb68c38a19bea53b9051ad028050 BUG: 1113476 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/8191 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Atin Mukherjee <amukherj@redhat.com> Reviewed-by: Avra Sengupta <asengupt@redhat.com> Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-by: Kaushal M <kaushal@redhat.com>
-rw-r--r--cli/src/cli-cmd-parser.c23
-rw-r--r--cli/src/cli-rpc-ops.c13
-rw-r--r--tests/bugs/bug-1087203.t13
-rw-r--r--tests/bugs/bug-1113476.t44
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c285
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c178
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c13
8 files changed, 289 insertions, 283 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 4a00b8485d3..85a916e380c 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -3919,25 +3919,14 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
goto out;
}
- if ((strcmp (words[cmdi], "enable") == 0) ||
- (strcmp (words[cmdi], "disable") == 0)) {
- ret = dict_set_str (dict, "auto-delete",
- (char *)words[cmdi]);
- if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Failed to set "
- "value of auto-delete in request "
- "dictionary");
- goto out;
- }
- auto_delete = 1;
- } else {
- ret = -1;
- cli_err ("Please enter a valid value (enable/disable) "
- "for auto-delete");
- gf_log ("cli", GF_LOG_ERROR, "Invalid value for "
- "auto-delete");
+ ret = dict_set_str (dict, "auto-delete", (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to set "
+ "value of auto-delete in request "
+ "dictionary");
goto out;
}
+ auto_delete = 1;
if (++cmdi != wordcount) {
ret = -1;
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index b7c6691abd5..d195db5f6e0 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7808,17 +7808,16 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
"& snap-max-soft-limit for system set "
"successfully");
} else if (hard_limit) {
- cli_out ("snapshot config: %s "
- "for snap-max-hard-limit set successfully",
+ cli_out ("snapshot config: snap-max-hard-limit "
+ "for %s set successfully",
volname);
} else if (soft_limit) {
- cli_out ("snapshot config: %s "
- "for snap-max-soft-limit set successfully",
+ cli_out ("snapshot config: snap-max-soft-limit "
+ "for %s set successfully",
volname);
} else if (auto_delete) {
- cli_out ("snapshot config: %s "
- "auto-delete successfully %sd",
- volname, auto_delete);
+ cli_out ("snapshot config: auto-delete "
+ "successfully set");
}
break;
diff --git a/tests/bugs/bug-1087203.t b/tests/bugs/bug-1087203.t
index 8926274dac7..585ecf440ac 100644
--- a/tests/bugs/bug-1087203.t
+++ b/tests/bugs/bug-1087203.t
@@ -96,6 +96,9 @@ TEST $CLI_1 snapshot config $V0 snap-max-hard-limit 10
# Make sure auto-delete is disabled by default
EXPECT 'disable' config_validate 'auto-delete'
+# Test for invalid value for auto-delete
+TEST ! $CLI_1 snapshot config auto-delete test
+
TEST $CLI_1 snapshot config snap-max-hard-limit 6
TEST $CLI_1 snapshot config snap-max-soft-limit 50
@@ -113,8 +116,14 @@ EXPECT 'No snapshots present' is_snapshot_present;
TEST $CLI_1 snapshot config auto-delete enable
# auto-delete is already enabled, Hence expect a failure.
-TEST ! $CLI_1 snapshot config auto-delete enable
-EXPECT 'enable' config_validate 'auto-delete'
+TEST ! $CLI_1 snapshot config auto-delete on
+
+# Testing other boolean values with auto-delete
+TEST $CLI_1 snapshot config auto-delete off
+EXPECT 'off' config_validate 'auto-delete'
+
+TEST $CLI_1 snapshot config auto-delete true
+EXPECT 'true' config_validate 'auto-delete'
# Try to create 4 snaps again, As auto-delete is enabled
# oldest snap should be deleted and snapcount should be 3
diff --git a/tests/bugs/bug-1113476.t b/tests/bugs/bug-1113476.t
new file mode 100644
index 00000000000..7cb9d908269
--- /dev/null
+++ b/tests/bugs/bug-1113476.t
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+. $(dirname $0)/../include.rc
+. $(dirname $0)/../volume.rc
+. $(dirname $0)/../snapshot.rc
+
+function volinfo_validate ()
+{
+ local var=$1
+ $CLI volume info $V0 | grep "^$var" | sed 's/.*: //'
+}
+
+cleanup;
+
+TEST verify_lvm_version
+TEST glusterd
+TEST pidof glusterd
+TEST setup_lvm 1
+
+TEST $CLI volume create $V0 $H0:$L1
+TEST $CLI volume start $V0
+
+EXPECT '' volinfo_validate 'snap-max-hard-limit'
+EXPECT '' volinfo_validate 'snap-max-soft-limit'
+EXPECT '' volinfo_validate 'auto-delete'
+
+TEST $CLI snapshot config snap-max-hard-limit 100
+EXPECT '100' volinfo_validate 'snap-max-hard-limit'
+EXPECT '' volinfo_validate 'snap-max-soft-limit'
+EXPECT '' volinfo_validate 'auto-delete'
+
+TEST $CLI snapshot config snap-max-soft-limit 50
+EXPECT '100' volinfo_validate 'snap-max-hard-limit'
+EXPECT '50' volinfo_validate 'snap-max-soft-limit'
+EXPECT '' volinfo_validate 'auto-delete'
+
+TEST $CLI snapshot config auto-delete enable
+EXPECT '100' volinfo_validate 'snap-max-hard-limit'
+EXPECT '50' volinfo_validate 'snap-max-soft-limit'
+EXPECT 'enable' volinfo_validate 'auto-delete'
+
+cleanup;
+
+
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 58e611d20dc..ed9933a587b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -207,19 +207,19 @@ int
snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
char *op_errstr, int len)
{
- char err_str[PATH_MAX] = "";
- char buf[PATH_MAX] = "";
- glusterd_conf_t *conf = NULL;
- glusterd_volinfo_t *volinfo = NULL;
- int ret = -1;
- uint64_t active_hard_limit = 0;
- uint64_t snap_max_limit = 0;
- uint64_t soft_limit_value = -1;
- uint64_t count = 0;
- xlator_t *this = NULL;
- uint64_t opt_hard_max = 0;
- uint64_t opt_soft_max = 0;
- char *auto_delete = NULL;
+ char err_str[PATH_MAX] = "";
+ char buf[PATH_MAX] = "";
+ glusterd_conf_t *conf = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ int ret = -1;
+ uint64_t active_hard_limit = 0;
+ uint64_t snap_max_limit = 0;
+ uint64_t soft_limit_value = -1;
+ uint64_t count = 0;
+ xlator_t *this = NULL;
+ uint64_t opt_hard_max = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
+ uint64_t opt_soft_max = GLUSTERD_SNAPS_DEF_SOFT_LIMIT_PERCENT;
+ char *auto_delete = "disable";
this = THIS;
@@ -231,25 +231,13 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
GF_ASSERT (conf);
- ret = dict_get_uint64 (conf->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
- &opt_hard_max);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
- }
- ret = dict_get_uint64 (conf->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
- &opt_soft_max);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from options",
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT);
- goto out;
- }
+ /* config values snap-max-hard-limit and snap-max-soft-limit are
+ * optional and hence we are not erroring out if values are not
+ * present
+ */
+ gd_get_snap_conf_values_if_present (conf->opts, &opt_hard_max,
+ &opt_soft_max);
if (!volname) {
/* For system limit */
@@ -395,15 +383,12 @@ snap_max_limits_display_commit (dict_t *rsp_dict, char *volname,
goto out;
}
- ret = dict_get_str (conf->opts,
- GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
+ /* "auto-delete" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
+ ret = dict_get_str (conf->opts, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
&auto_delete);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from options",
- GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE);
- goto out;
- }
ret = dict_set_dynstr_with_alloc (rsp_dict,
GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
@@ -1042,7 +1027,7 @@ snap_max_hard_limits_validate (dict_t *dict, char *volname,
int ret = -1;
uint64_t max_limit = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
xlator_t *this = NULL;
- uint64_t opt_hard_max = 0;
+ uint64_t opt_hard_max = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
this = THIS;
@@ -1068,14 +1053,18 @@ snap_max_hard_limits_validate (dict_t *dict, char *volname,
}
}
+ /* "snap-max-hard-limit" might not be set by user explicitly,
+ * in that case it's better to use the default value.
+ * Hence not erroring out if Key is not found.
+ */
ret = dict_get_uint64 (conf->opts,
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
&opt_hard_max);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
+ ret = 0;
+ gf_log (this->name, GF_LOG_DEBUG, "%s is not present in "
+ "opts dictionary",
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
}
/* volume snap-max-hard-limit cannot exceed system snap-max-hard-limit.
@@ -1118,8 +1107,8 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
uint64_t soft_limit = 0;
gf_loglevel_t loglevel = GF_LOG_ERROR;
uint64_t max_limit = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
- char *req_auto_delete = NULL;
- char *cur_auto_delete = NULL;
+ char cur_auto_delete = 0;
+ int req_auto_delete = 0;
this = THIS;
@@ -1138,12 +1127,11 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
goto out;
}
- ret = dict_get_uint64 (dict, "snap-max-hard-limit", &hard_limit);
-
- ret = dict_get_uint64 (dict, "snap-max-soft-limit", &soft_limit);
-
- ret = dict_get_str (dict, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
- &req_auto_delete);
+ /* config values snap-max-hard-limit and snap-max-soft-limit are
+ * optional and hence we are not erroring out if values are not
+ * present
+ */
+ gd_get_snap_conf_values_if_present (dict, &hard_limit, &soft_limit);
ret = dict_get_str (dict, "volname", &volname);
@@ -1183,23 +1171,42 @@ glusterd_snapshot_config_prevalidate (dict_t *dict, char **op_errstr)
break;
}
- if (req_auto_delete) {
- ret = dict_get_str (conf->opts,
- GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
- &cur_auto_delete);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
- "get auto-delete value from options");
- goto out;
- }
+ /* If hard_limit or soft_limit is set then need not check
+ * for auto-delete
+ */
+ if (hard_limit || soft_limit) {
+ ret = 0;
+ goto out;
+ }
- if (strcmp (req_auto_delete, cur_auto_delete) == 0) {
- ret = -1;
- snprintf (err_str, PATH_MAX, "auto-delete "
- "is already %sd", req_auto_delete);
- goto out;
- }
+ req_auto_delete = dict_get_str_boolean (dict,
+ GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
+ _gf_false);
+ if (req_auto_delete < 0) {
+ ret = -1;
+ snprintf (err_str, sizeof (err_str), "Please enter a "
+ "valid boolean value for auto-delete");
+ goto out;
+ }
+
+ /* Ignoring the error as the auto-delete is optional and
+ * might not be present in the options dictionary.
+ */
+ cur_auto_delete = dict_get_str_boolean (conf->opts,
+ GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
+ _gf_false);
+
+ if (cur_auto_delete == req_auto_delete) {
+ ret = -1;
+ if (cur_auto_delete == _gf_true)
+ snprintf (err_str, sizeof (err_str),
+ "auto-delete is already enabled");
+ else
+ snprintf (err_str, sizeof (err_str),
+ "auto-delete is already disabled");
+ goto out;
}
+
default:
break;
}
@@ -1626,26 +1633,26 @@ int
glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
dict_t *rsp_dict)
{
- char *volname = NULL;
- char *snapname = NULL;
- char *device = NULL;
- char key[PATH_MAX] = "";
- char snap_volname[64] = "";
- char err_str[PATH_MAX] = "";
- int ret = -1;
- int64_t i = 0;
- int64_t volcount = 0;
- int64_t brick_count = 0;
- int64_t brick_order = 0;
- glusterd_brickinfo_t *brickinfo = NULL;
- glusterd_volinfo_t *volinfo = NULL;
- xlator_t *this = NULL;
- uuid_t *snap_volid = NULL;
- gf_loglevel_t loglevel = GF_LOG_ERROR;
- glusterd_conf_t *conf = NULL;
- int64_t effective_max_limit = 0;
- int flags = 0;
- uint64_t opt_hard_max = 0;
+ char *volname = NULL;
+ char *snapname = NULL;
+ char *device = NULL;
+ char key[PATH_MAX] = "";
+ char snap_volname[64] = "";
+ char err_str[PATH_MAX] = "";
+ int ret = -1;
+ int64_t i = 0;
+ int64_t volcount = 0;
+ int64_t brick_count = 0;
+ int64_t brick_order = 0;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ xlator_t *this = NULL;
+ uuid_t *snap_volid = NULL;
+ gf_loglevel_t loglevel = GF_LOG_ERROR;
+ glusterd_conf_t *conf = NULL;
+ int64_t effective_max_limit = 0;
+ int flags = 0;
+ uint64_t opt_hard_max = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
this = THIS;
GF_ASSERT (op_errstr);
@@ -1659,8 +1666,8 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
goto out;
}
if (volcount <= 0) {
- snprintf (err_str, sizeof (err_str), "Invalid volume count %"PRId64
- " supplied", volcount);
+ snprintf (err_str, sizeof (err_str),
+ "Invalid volume count %"PRId64" supplied", volcount);
ret = -1;
goto out;
}
@@ -1722,14 +1729,18 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
goto out;
}
+ /* "snap-max-hard-limit" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
ret = dict_get_uint64 (conf->opts,
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
&opt_hard_max);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
+ ret = 0;
+ gf_log (this->name, GF_LOG_DEBUG, "%s is not present "
+ "in opts dictionary",
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
}
if (volinfo->snap_max_hard_limit < opt_hard_max)
@@ -2456,7 +2467,7 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict,
glusterd_volinfo_t *origin_vol = NULL;
glusterd_conf_t *conf = NULL;
xlator_t *this = NULL;
- uint64_t opt_hard_max = 0;
+ uint64_t opt_hard_max = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
this = THIS;
conf = this->private;
@@ -2526,16 +2537,18 @@ glusterd_snapshot_get_snapvol_detail (dict_t *dict,
goto out;
}
- /* Snaps available */
-
+ /* "snap-max-hard-limit" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
ret = dict_get_uint64 (conf->opts,
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
&opt_hard_max);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
+ ret = 0;
+ gf_log (this->name, GF_LOG_DEBUG, "%s is not present in "
+ "opts dictionary",
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
}
if (opt_hard_max < origin_vol->snap_max_hard_limit) {
@@ -2821,7 +2834,7 @@ glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname,
glusterd_volinfo_t *tmp_vol = NULL;
glusterd_conf_t *conf = NULL;
xlator_t *this = NULL;
- uint64_t opt_hard_max = 0;
+ uint64_t opt_hard_max = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
this = THIS;
conf = this->private;
@@ -2837,15 +2850,18 @@ glusterd_snapshot_get_info_by_volume (dict_t *dict, char *volname,
goto out;
}
- /* Snaps available */
+ /* "snap-max-hard-limit" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
ret = dict_get_uint64 (conf->opts,
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
&opt_hard_max);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
+ ret = 0;
+ gf_log (this->name, GF_LOG_DEBUG, "%s is not present in "
+ "opts dictionary",
GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
}
if (opt_hard_max < volinfo->snap_max_hard_limit) {
@@ -5482,15 +5498,18 @@ glusterd_snapshot_config_commit (dict_t *dict, char **op_errstr,
goto out;
}
- /* Ignore the return value of the following dict_get,
- * as they are optional
- */
ret = dict_get_str (dict, "volname", &volname);
- ret = dict_get_uint64 (dict, "snap-max-hard-limit", &hard_limit);
-
- ret = dict_get_uint64 (dict, "snap-max-soft-limit", &soft_limit);
+ /* config values snap-max-hard-limit and snap-max-soft-limit are
+ * optional and hence we are not erroring out if values are not
+ * present
+ */
+ gd_get_snap_conf_values_if_present (dict, &hard_limit,
+ &soft_limit);
+ /* Ignoring the return value as auto-delete is optional and
+ * might not be present in the request dictionary.
+ */
ret = dict_get_str (dict, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
&auto_delete);
@@ -6280,8 +6299,8 @@ glusterd_handle_snap_limit (dict_t *dict, dict_t *rsp_dict)
glusterd_snap_t *snap = NULL;
glusterd_volinfo_t *tmp_volinfo = NULL;
glusterd_volinfo_t *other_volinfo = NULL;
- uint64_t opt_max_hard = 0;
- uint64_t opt_max_soft = 0;
+ uint64_t opt_max_hard = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
+ uint64_t opt_max_soft = GLUSTERD_SNAPS_DEF_SOFT_LIMIT_PERCENT;
this = THIS;
GF_ASSERT (this);
@@ -6313,15 +6332,12 @@ glusterd_handle_snap_limit (dict_t *dict, dict_t *rsp_dict)
goto out;
}
- ret = dict_get_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
- &opt_max_hard);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
- }
+ /* config values snap-max-hard-limit and snap-max-soft-limit are
+ * optional and hence we are not erroring out if values are not
+ * present
+ */
+ gd_get_snap_conf_values_if_present (priv->opts, &opt_max_hard,
+ &opt_max_soft);
/* The minimum of the 2 limits i.e system wide limit and
volume wide limit will be considered
@@ -6331,16 +6347,6 @@ glusterd_handle_snap_limit (dict_t *dict, dict_t *rsp_dict)
else
effective_max_limit = opt_max_hard;
- ret = dict_get_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
- &opt_max_soft);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT);
- goto out;
- }
-
limit = (opt_max_soft * effective_max_limit)/100;
count = volinfo->snap_count - limit;
@@ -6449,18 +6455,17 @@ glusterd_snapshot_create_postvalidate (dict_t *dict, int32_t op_ret,
goto out;
}
- ret = dict_get_str (priv->opts, GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
- &auto_delete);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "the value of auto-delete from options");
- goto out;
- }
-
- //ignore the errors of autodelete
- if (strcmp (auto_delete, "enable") == 0)
+ /* "auto-delete" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
+ ret = dict_get_str_boolean (priv->opts,
+ GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
+ _gf_false);
+ if ( _gf_true == ret ) {
+ //ignore the errors of autodelete
ret = glusterd_handle_snap_limit (dict, rsp_dict);
-
+ }
ret = 0;
out:
return ret;
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 3e90298a873..06283884357 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -10175,6 +10175,8 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src)
int ret = -1;
int config_command = 0;
uint64_t i = 0;
+ uint64_t hard_limit = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
+ uint64_t soft_limit = GLUSTERD_SNAPS_DEF_SOFT_LIMIT_PERCENT;
uint64_t value = 0;
uint64_t voldisplaycount = 0;
@@ -10193,9 +10195,13 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src)
switch (config_command) {
case GF_SNAP_CONFIG_DISPLAY:
- ret = dict_get_uint64 (src, "snap-max-hard-limit", &value);
+ ret = dict_get_uint64 (src,
+ GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
+ &hard_limit);
if (!ret) {
- ret = dict_set_uint64 (dst, "snap-max-hard-limit", value);
+ ret = dict_set_uint64 (dst,
+ GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
+ hard_limit);
if (ret) {
gf_log ("", GF_LOG_ERROR,
"Unable to set snap_max_hard_limit");
@@ -10207,14 +10213,18 @@ glusterd_snap_config_use_rsp_dict (dict_t *dst, dict_t *src)
goto out;
}
- ret = dict_get_uint64 (src, "snap-max-soft-limit", &value);
+ ret = dict_get_uint64 (src,
+ GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
+ &soft_limit);
if (ret) {
gf_log ("", GF_LOG_ERROR,
"Unable to get snap_max_soft_limit");
goto out;
}
- ret = dict_set_uint64 (dst, "snap-max-soft-limit", value);
+ ret = dict_set_uint64 (dst,
+ GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
+ soft_limit);
if (ret) {
gf_log ("", GF_LOG_ERROR,
"Unable to set snap_max_soft_limit");
@@ -13280,81 +13290,13 @@ out:
}
int32_t
-glusterd_check_and_set_config_limit (glusterd_conf_t *priv)
-{
- int32_t ret = -1;
- xlator_t *this = NULL;
- uint64_t hard_limit = 0;
- uint64_t soft_limit = 0;
- char *auto_delete = NULL;
-
- GF_ASSERT (priv);
- this = THIS;
- GF_ASSERT (this);
-
-
- ret = dict_get_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
- &hard_limit);
- if (ret) {
- ret = dict_set_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
- GLUSTERD_SNAPS_MAX_HARD_LIMIT);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
- "store %s during glusterd init",
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
- }
- }
-
- ret = dict_get_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
- &soft_limit);
- if (ret) {
- ret = dict_set_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
- GLUSTERD_SNAPS_DEF_SOFT_LIMIT_PERCENT);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
- "store %s during glusterd init",
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT);
- goto out;
- }
- }
-
- ret = dict_get_str (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
- &auto_delete);
- if (ret) {
- ret = dict_set_dynstr_with_alloc (priv->opts, "auto-delete",
- "disable");
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to store "
- "auto-delete value as disabled during "
- "glusterd init");
- goto out;
- }
- }
-
- ret = glusterd_store_options (this, priv->opts);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR,
- "Unable to store version");
- return ret;
- }
-out:
- return ret;
-}
-
-int32_t
glusterd_is_snap_soft_limit_reached (glusterd_volinfo_t *volinfo, dict_t *dict)
{
int32_t ret = -1;
- uint64_t opt_max_hard = 0;
- uint64_t opt_max_soft = 0;
+ uint64_t opt_max_hard = GLUSTERD_SNAPS_MAX_HARD_LIMIT;
+ uint64_t opt_max_soft = GLUSTERD_SNAPS_DEF_SOFT_LIMIT_PERCENT;
uint64_t limit = 0;
- char *auto_delete = NULL;
+ int auto_delete = 0;
uint64_t effective_max_limit = 0;
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
@@ -13367,44 +13309,29 @@ glusterd_is_snap_soft_limit_reached (glusterd_volinfo_t *volinfo, dict_t *dict)
priv = this->private;
GF_ASSERT (priv);
- ret = dict_get_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
- &opt_max_hard);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s", GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
- goto out;
- }
+ /* config values snap-max-hard-limit and snap-max-soft-limit are
+ * optional and hence we are not erroring out if values are not
+ * present
+ */
+ gd_get_snap_conf_values_if_present (priv->opts, &opt_max_hard,
+ &opt_max_soft);
+
+ /* "auto-delete" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
+ auto_delete = dict_get_str_boolean (priv->opts,
+ GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
+ _gf_false);
if (volinfo->snap_max_hard_limit < opt_max_hard)
effective_max_limit = volinfo->snap_max_hard_limit;
else
effective_max_limit = opt_max_hard;
- ret = dict_get_uint64 (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
- &opt_max_soft);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "%s from opts dictionary",
- GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT);
- goto out;
- }
-
- ret = dict_get_str (priv->opts,
- GLUSTERD_STORE_KEY_SNAP_AUTO_DELETE,
- &auto_delete);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "auto-delete from options dictionary");
- goto out;
- }
-
limit = (opt_max_soft * effective_max_limit)/100;
- if (volinfo->snap_count >= limit &&
- (strcmp (auto_delete, "enable") != 0)) {
-
+ if (volinfo->snap_count >= limit && auto_delete != _gf_true) {
gf_log (this->name, GF_LOG_WARNING, "Soft-limit "
"(value = %"PRIu64") of volume %s is reached. "
"Snapshot creation is not possible once effective "
@@ -13420,6 +13347,47 @@ glusterd_is_snap_soft_limit_reached (glusterd_volinfo_t *volinfo, dict_t *dict)
}
goto out;
}
+ ret = 0;
out :
return ret;
}
+
+/* This function initializes the parameter sys_hard_limit,
+ * sys_soft_limit and auto_delete value to the value set
+ * in dictionary, If value is not present then it is
+ * initialized to default values. Hence this function does not
+ * return any values.
+ */
+void
+gd_get_snap_conf_values_if_present (dict_t *dict, uint64_t *sys_hard_limit,
+ uint64_t *sys_soft_limit)
+{
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
+
+ GF_ASSERT (dict);
+
+ /* "snap-max-hard-limit" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
+ if (dict_get_uint64 (dict, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
+ sys_hard_limit)) {
+ gf_log (this->name, GF_LOG_DEBUG, "%s is not present in"
+ "dictionary",
+ GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT);
+ }
+
+ /* "snap-max-soft-limit" might not be set by user explicitly,
+ * in that case it's better to consider the default value.
+ * Hence not erroring out if Key is not found.
+ */
+ if (dict_get_uint64 (dict, GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT,
+ sys_soft_limit)) {
+ gf_log (this->name, GF_LOG_DEBUG, "%s is not present in"
+ "dictionary",
+ GLUSTERD_STORE_KEY_SNAP_MAX_SOFT_LIMIT);
+ }
+}
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index f8dfce7ca82..2486e54833f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -896,4 +896,7 @@ glusterd_update_fstype (char *orig_brick_path,
int
glusterd_update_fs_label (glusterd_brickinfo_t *brickinfo);
+void
+gd_get_snap_conf_values_if_present (dict_t *opts, uint64_t *sys_hard_limit,
+ uint64_t *sys_soft_limit);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index adf58cc7dde..c5fa245dbd8 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -200,7 +200,7 @@ glusterd_options_init (xlator_t *this)
ret = glusterd_store_retrieve_options (this);
if (ret == 0) {
- goto set;
+ goto out;
}
ret = dict_set_str (priv->opts, GLUSTERD_GLOBAL_OPT_VERSION,
@@ -213,17 +213,6 @@ glusterd_options_init (xlator_t *this)
gf_log (this->name, GF_LOG_ERROR, "Unable to store version");
return ret;
}
-
-set:
- if (priv->op_version >= GD_OP_VERSION_3_6_0) {
- ret = glusterd_check_and_set_config_limit (priv);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed "
- "to set config limit in options");
- return ret;
- }
- }
-
out:
return 0;
}