summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 84d836e187a..b4dc3fe49bd 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -3917,25 +3917,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 6834e28decf..a240f376f7f 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7811,17 +7811,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 148acec8882..79242afc500 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);
@@ -6281,8 +6300,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);
@@ -6314,15 +6333,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
@@ -6332,16 +6348,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;
@@ -6450,18 +6456,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 cfebadc3e1d..712fb9687ca 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -10311,6 +10311,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;
@@ -10329,9 +10331,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");
@@ -10343,14 +10349,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");
@@ -13421,81 +13431,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;
@@ -13508,44 +13450,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 "
@@ -13561,6 +13488,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 c277445ce61..dfff95f01a1 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -899,4 +899,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 5a6e55ef39e..f4ead6115e3 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;
}