summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-utils.c
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-06-11 09:03:16 +0530
committerVijay Bellur <vbellur@redhat.com>2014-06-13 02:12:29 -0700
commit10cd2bc38e1f0a1297d59c0791a85ed9d01c93ff (patch)
treee7230795e97b668c04011fa018597aae0619ef10 /xlators/mgmt/glusterd/src/glusterd-utils.c
parent6ba178fd9ebf9fc98415c30bcd338a68ee5eb601 (diff)
glusterd/snapshot : Provide enable/disable option for snapshot auto-delete feature.
This patch provides an interface to enable or disable the auto-delete feature. Syntax : gluster snapshot config auto-delete <enable/disable> DETAILS : 1) When auto-delete feature is disabled, If the the soft-limit is reached then user is given a warning about exceeding soft-limit along with successful snapshot creation message (oldest snapshot is not deleted). And upon reaching hard-limit further snapshot creation is not allowed. Example : ------------------------------------------------------------------ |Case - 1: Upon reaching soft-limit | |Snapshot create : snap successfully created. |Warning : soft-limit of volume (vol) is reached. Snapshot creation |is not possible once hard-limit is reached. | |----------------------------------------------------- |Case - 2: Upon reaching hard-limit | |Snapshot create : snap creation failed. |Error : hard-limit of volume (vol) is reached, Hence it is not |possible to take further snapshots. Please delete few snapshots |of the volume (vol) before taking another snapshot. ------------------------------------------------------------------ 2) When auto-delete feature is enabled, then as soon as the soft-limit is reached the oldest snapshot is deleted for every successful snapshot creation (same as existing method), With this it is made sure that number of snapshot created is not more than snap-max-hard-limit. Change-Id: Ie3ca64bbd2c763371f541cd2e378314e73b695b4 BUG: 1105415 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/8017 Tested-by: Justin Clift <justin@gluster.org> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com> Tested-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c107
1 files changed, 103 insertions, 4 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index d79ff249535..776278ff6c3 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -10612,6 +10612,7 @@ glusterd_snap_create_use_rsp_dict (dict_t *dst, dict_t *src)
int32_t src_missed_snap_count = -1;
int32_t dst_missed_snap_count = -1;
xlator_t *this = NULL;
+ int8_t soft_limit_flag = -1;
this = THIS;
GF_ASSERT (this);
@@ -10629,6 +10630,18 @@ glusterd_snap_create_use_rsp_dict (dict_t *dst, dict_t *src)
goto out;
}
+ /* set in dst dictionary soft-limit-reach only if soft-limit-reach
+ * is present src dictionary */
+ ret = dict_get_int8 (src, "soft-limit-reach", &soft_limit_flag);
+ if (!ret) {
+ ret = dict_set_int8 (dst, "soft-limit-reach", soft_limit_flag);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set "
+ "soft_limit_flag");
+ goto out;
+ }
+ }
+
ret = dict_get_int32 (src, "missed_snap_count",
&src_missed_snap_count);
if (ret) {
@@ -13433,10 +13446,11 @@ 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;
+ 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;
@@ -13472,6 +13486,21 @@ glusterd_check_and_set_config_limit (glusterd_conf_t *priv)
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,
@@ -13481,3 +13510,73 @@ glusterd_check_and_set_config_limit (glusterd_conf_t *priv)
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 limit = 0;
+ char *auto_delete = NULL;
+ uint64_t effective_max_limit = 0;
+ xlator_t *this = NULL;
+ glusterd_conf_t *priv = NULL;
+
+ GF_ASSERT (volinfo);
+ GF_ASSERT (dict);
+
+ this = THIS;
+ GF_ASSERT (this);
+ 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;
+ }
+
+ 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)) {
+ ret = dict_set_int8 (dict, "soft-limit-reach",
+ _gf_true);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to "
+ "set soft limit exceed flag in "
+ "response dictionary");
+ }
+ goto out;
+ }
+out :
+ return ret;
+}