summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-snapshot.c
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 /xlators/mgmt/glusterd/src/glusterd-snapshot.c
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>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-snapshot.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c285
1 files changed, 145 insertions, 140 deletions
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;