summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorRaghavendra Bhat <raghavendra@redhat.com>2014-04-29 00:14:54 +0530
committerKrishnan Parthasarathi <kparthas@redhat.com>2014-05-08 23:10:16 -0700
commit26a4b5c98e9e50ace28a9bed97f04ecea262e11d (patch)
treeea103f96ec5b93aa74077c55bc67451e735cca4b /xlators
parentd74c10603196a57c5fa033aaeb55f93f7ef7b4be (diff)
mgmt/glusterd: delete oldest snapshot upon exceeding soft-limit
Change-Id: I2d6ebae3ced1910f2dee43eeb9fc430e9f31073f BUG: 1061685 Signed-off-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-on: http://review.gluster.org/7587 Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com> Tested-by: Krishnan Parthasarathi <kparthas@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c101
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h5
2 files changed, 106 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 44a987ef8b2..e47f85f7ff4 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -5788,6 +5788,104 @@ out:
}
int32_t
+glusterd_handle_snap_limit (dict_t *dict, dict_t *rsp_dict)
+{
+ int32_t ret = -1;
+ xlator_t *this = NULL;
+ glusterd_conf_t *priv = NULL;
+ uint64_t effective_max_limit = 0;
+ int64_t volcount = 0;
+ int64_t i = 0;
+ char *volname = NULL;
+ char key[PATH_MAX] = {0, };
+ glusterd_volinfo_t *volinfo = NULL;
+ uint64_t limit = 0;
+ int64_t count = 0;
+ glusterd_snap_t *snap = NULL;
+ glusterd_volinfo_t *tmp_volinfo = NULL;
+ glusterd_volinfo_t *other_volinfo = NULL;
+ int64_t var = 0;
+
+ this = THIS;
+ GF_ASSERT (this);
+ GF_ASSERT (dict);
+ GF_ASSERT (rsp_dict);
+
+ priv = this->private;
+ GF_ASSERT (priv);
+
+ ret = dict_get_int64 (dict, "volcount", &volcount);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "failed to get the volcount");
+ goto out;
+ }
+
+ for (i = 1; i <= volcount; i++) {
+ snprintf (key, sizeof (key), "volname%ld", i);
+ ret = dict_get_str (dict, key, &volname);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "failed to get the "
+ "volname");
+ goto out;
+ }
+
+ ret = glusterd_volinfo_find (volname, &volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "volinfo for %s "
+ "not found", volname);
+ goto out;
+ }
+
+ /* The minimum of the 2 limits i.e system wide limit and
+ volume wide limit will be considered
+ */
+ if (volinfo->snap_max_hard_limit < priv->snap_max_hard_limit)
+ effective_max_limit = volinfo->snap_max_hard_limit;
+ else
+ effective_max_limit = priv->snap_max_hard_limit;
+
+ limit = (priv->snap_max_soft_limit * effective_max_limit)/100;
+
+ count = volinfo->snap_count - limit;
+ if (count <= 0)
+ goto out;
+
+ list_for_each_entry_safe (tmp_volinfo, other_volinfo,
+ &volinfo->snap_volumes, snapvol_list) {
+ if (var == count)
+ break;
+
+ snap = tmp_volinfo->snapshot;
+ GF_ASSERT (snap);
+
+ LOCK (&snap->lock);
+ {
+ snap->snap_status = GD_SNAP_STATUS_DECOMMISSION;
+ ret = glusterd_store_snap (snap);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "could "
+ "not store snap object %s",
+ snap->snapname);
+ goto unlock;
+ }
+
+ ret = glusterd_snap_remove (rsp_dict, snap,
+ _gf_true, _gf_true);
+ if (ret)
+ gf_log (this->name, GF_LOG_WARNING,
+ "failed to remove snap %s",
+ snap->snapname);
+ }
+ unlock: UNLOCK (&snap->lock);
+ var++;
+ }
+ }
+
+out:
+ return ret;
+}
+
+int32_t
glusterd_snapshot_create_postvalidate (dict_t *dict, int32_t op_ret,
char **op_errstr, dict_t *rsp_dict)
{
@@ -5851,6 +5949,9 @@ glusterd_snapshot_create_postvalidate (dict_t *dict, int32_t op_ret,
goto out;
}
+ //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.h b/xlators/mgmt/glusterd/src/glusterd.h
index bf4a8e283d6..02441c9148b 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -1017,8 +1017,13 @@ glusterd_add_new_entry_to_list (char *missed_info, char *snap_vol_id,
int
glusterd_snapshot_revert_restore_from_snap (glusterd_snap_t *snap);
+
int
glusterd_add_brick_status_to_dict (dict_t *dict, glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo,
char *key_prefix);
+
+int32_t
+glusterd_handle_snap_limit (dict_t *dict, dict_t *rsp_dict);
+
#endif