7f4c2a
From d2f48b625c0d7d361b62f7a4f1a698bef3d67dc9 Mon Sep 17 00:00:00 2001
7f4c2a
From: Mohammed Rafi KC <rkavunga@redhat.com>
7f4c2a
Date: Tue, 17 Mar 2015 19:57:47 +0530
7f4c2a
Subject: [PATCH 302/304] snapshot:cleanup snaps during unprobe
7f4c2a
7f4c2a
    Backport of http://review.gluster.org/#/c/9930/
7f4c2a
7f4c2a
When doing an unprobe, the volume that doesnot
7f4c2a
contain any brick of the particular node will be
7f4c2a
deleted. So the snaps associated with that volume
7f4c2a
should also delete
7f4c2a
7f4c2a
Change-Id: I9f3d23bd11b254ebf7d7722cc1e12455d6b024ff
7f4c2a
BUG: 1238111
7f4c2a
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
7f4c2a
Reviewed-on: http://review.gluster.org/9930
7f4c2a
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
7f4c2a
Reviewed-by: Avra Sengupta <asengupt@redhat.com>
7f4c2a
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
7f4c2a
Reviewed-on: https://code.engineering.redhat.com/gerrit/56396
7f4c2a
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
7f4c2a
---
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-sm.c            |    9 ++
7f4c2a
 .../mgmt/glusterd/src/glusterd-snapshot-utils.c    |   89 ++++++++++++++++++++
7f4c2a
 .../mgmt/glusterd/src/glusterd-snapshot-utils.h    |    5 +
7f4c2a
 xlators/mgmt/glusterd/src/glusterd-snapshot.c      |   23 +-----
7f4c2a
 4 files changed, 104 insertions(+), 22 deletions(-)
7f4c2a
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
7f4c2a
index 8e91cef..f0159b2 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
7f4c2a
@@ -635,6 +635,15 @@ glusterd_peer_detach_cleanup (glusterd_conf_t *priv)
7f4c2a
                         gf_msg (THIS->name, GF_LOG_INFO, 0,
7f4c2a
                                 GD_MSG_STALE_VOL_DELETE_INFO,
7f4c2a
                                 "Deleting stale volume %s", volinfo->volname);
7f4c2a
+
7f4c2a
+                        ret = glusterd_cleanup_snaps_for_volume (volinfo);
7f4c2a
+                        if (ret) {
7f4c2a
+                                gf_msg (THIS->name, GF_LOG_ERROR, 0,
7f4c2a
+                                        GD_MSG_VOL_DELETE_FAIL,
7f4c2a
+                                        "Error deleting snapshots for volume %s",
7f4c2a
+                                        volinfo->volname);
7f4c2a
+                        }
7f4c2a
+
7f4c2a
                         ret = glusterd_delete_volume (volinfo);
7f4c2a
                         if (ret) {
7f4c2a
                                 gf_msg (THIS->name, GF_LOG_ERROR, 0,
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
7f4c2a
index acc4e42..ccea9ff 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
7f4c2a
@@ -40,6 +40,95 @@
7f4c2a
  *      This function restores the atime and mtime of marker.tstamp
7f4c2a
  *      if present from snapped marker.tstamp file.
7f4c2a
  */
7f4c2a
+
7f4c2a
+int32_t
7f4c2a
+glusterd_snapobject_delete (glusterd_snap_t *snap)
7f4c2a
+{
7f4c2a
+        if (snap == NULL) {
7f4c2a
+                gf_msg(THIS->name, GF_LOG_WARNING, 0,
7f4c2a
+                       GD_MSG_PARAM_NULL, "snap is NULL");
7f4c2a
+                return -1;
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        cds_list_del_init (&snap->snap_list);
7f4c2a
+        cds_list_del_init (&snap->volumes);
7f4c2a
+        if (LOCK_DESTROY(&snap->lock))
7f4c2a
+                gf_msg (THIS->name, GF_LOG_WARNING, 0,
7f4c2a
+                        GD_MSG_LOCK_DESTROY_FAILED,
7f4c2a
+                        "Failed destroying lock"
7f4c2a
+                        "of snap %s", snap->snapname);
7f4c2a
+
7f4c2a
+        GF_FREE (snap->description);
7f4c2a
+        GF_FREE (snap);
7f4c2a
+
7f4c2a
+        return 0;
7f4c2a
+}
7f4c2a
+
7f4c2a
+
7f4c2a
+/*
7f4c2a
+ * This function is to be called only from glusterd_peer_detach_cleanup()
7f4c2a
+ * as this continues to delete snaps inspite of faiure while deleting
7f4c2a
+ * one, as we don't want to fail peer_detach in such a case.
7f4c2a
+ */
7f4c2a
+int
7f4c2a
+glusterd_cleanup_snaps_for_volume (glusterd_volinfo_t *volinfo)
7f4c2a
+{
7f4c2a
+        int32_t                  op_ret         = 0;
7f4c2a
+        int32_t                  ret            = 0;
7f4c2a
+        xlator_t                *this           = NULL;
7f4c2a
+        glusterd_volinfo_t      *snap_vol       = NULL;
7f4c2a
+        glusterd_volinfo_t      *dummy_snap_vol = NULL;
7f4c2a
+        glusterd_snap_t         *snap           = NULL;
7f4c2a
+
7f4c2a
+        this = THIS;
7f4c2a
+        GF_ASSERT (this);
7f4c2a
+
7f4c2a
+        cds_list_for_each_entry_safe (snap_vol, dummy_snap_vol,
7f4c2a
+                                      &volinfo->snap_volumes,
7f4c2a
+                                      snapvol_list) {
7f4c2a
+                ret = glusterd_store_delete_volume (snap_vol);
7f4c2a
+                if (ret) {
7f4c2a
+                        gf_msg(this->name, GF_LOG_WARNING, 0,
7f4c2a
+                               GD_MSG_VOL_DELETE_FAIL, "Failed to remove "
7f4c2a
+                               "volume %s from store", snap_vol->volname);
7f4c2a
+                        op_ret = ret;
7f4c2a
+                        continue;
7f4c2a
+                }
7f4c2a
+
7f4c2a
+                ret = glusterd_volinfo_delete (snap_vol);
7f4c2a
+                if (ret) {
7f4c2a
+                        gf_msg(this->name, GF_LOG_WARNING, 0,
7f4c2a
+                               GD_MSG_VOL_DELETE_FAIL, "Failed to remove "
7f4c2a
+                              "volinfo %s ", snap_vol->volname);
7f4c2a
+                        op_ret = ret;
7f4c2a
+                        continue;
7f4c2a
+                }
7f4c2a
+
7f4c2a
+                snap = snap_vol->snapshot;
7f4c2a
+                ret = glusterd_store_delete_snap (snap);
7f4c2a
+                if (ret) {
7f4c2a
+                        gf_msg(this->name, GF_LOG_WARNING, 0,
7f4c2a
+                               GD_MSG_VOL_DELETE_FAIL, "Failed to remove "
7f4c2a
+                               "snap %s from store", snap->snapname);
7f4c2a
+                        op_ret = ret;
7f4c2a
+                        continue;
7f4c2a
+                }
7f4c2a
+
7f4c2a
+                ret = glusterd_snapobject_delete (snap);
7f4c2a
+                if (ret) {
7f4c2a
+                        gf_msg (this->name, GF_LOG_WARNING, 0,
7f4c2a
+                                GD_MSG_VOL_DELETE_FAIL, "Failed to delete "
7f4c2a
+                                "snap object %s", snap->snapname);
7f4c2a
+                        op_ret = ret;
7f4c2a
+                        continue;
7f4c2a
+                }
7f4c2a
+        }
7f4c2a
+
7f4c2a
+        return op_ret;
7f4c2a
+}
7f4c2a
+
7f4c2a
+
7f4c2a
+
7f4c2a
 int
7f4c2a
 glusterd_snap_geo_rep_restore (glusterd_volinfo_t *snap_volinfo,
7f4c2a
                                glusterd_volinfo_t *new_volinfo)
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
7f4c2a
index ce8d7d4..63d39e8 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
7f4c2a
@@ -38,6 +38,11 @@ glusterd_snap_volinfo_restore (dict_t *dict, dict_t *rsp_dict,
7f4c2a
                                glusterd_volinfo_t *new_volinfo,
7f4c2a
                                glusterd_volinfo_t *snap_volinfo,
7f4c2a
                                int32_t volcount);
7f4c2a
+int32_t
7f4c2a
+glusterd_snapobject_delete (glusterd_snap_t *snap);
7f4c2a
+
7f4c2a
+int32_t
7f4c2a
+glusterd_cleanup_snaps_for_volume (glusterd_volinfo_t *volinfo);
7f4c2a
 
7f4c2a
 int32_t
7f4c2a
 glusterd_missed_snapinfo_new (glusterd_missed_snap_info **missed_snapinfo);
7f4c2a
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
7f4c2a
index 080aa88..6f10ebc 100644
7f4c2a
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
7f4c2a
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
7f4c2a
@@ -86,6 +86,7 @@ typedef struct snap_create_args_ snap_create_args_t;
7f4c2a
    then the snap device will be /dev/<group-name>/<snapname>.
7f4c2a
    This function takes care of building the path for the snap device.
7f4c2a
 */
7f4c2a
+
7f4c2a
 char *
7f4c2a
 glusterd_build_snap_device_path (char *device, char *snapname,
7f4c2a
                                  int32_t brickcount)
7f4c2a
@@ -2961,28 +2962,6 @@ out:
7f4c2a
 }
7f4c2a
 
7f4c2a
 int32_t
7f4c2a
-glusterd_snapobject_delete (glusterd_snap_t *snap)
7f4c2a
-{
7f4c2a
-        if (snap == NULL) {
7f4c2a
-                gf_msg(THIS->name, GF_LOG_WARNING, EINVAL,
7f4c2a
-                       GD_MSG_INVALID_ENTRY, "snap is NULL");
7f4c2a
-                return -1;
7f4c2a
-        }
7f4c2a
-
7f4c2a
-        cds_list_del_init (&snap->snap_list);
7f4c2a
-        cds_list_del_init (&snap->volumes);
7f4c2a
-        if (LOCK_DESTROY(&snap->lock))
7f4c2a
-                gf_msg (THIS->name, GF_LOG_WARNING, 0,
7f4c2a
-                        GD_MSG_LOCK_DESTROY_FAILED, "Failed destroying lock"
7f4c2a
-                        "of snap %s", snap->snapname);
7f4c2a
-
7f4c2a
-        GF_FREE (snap->description);
7f4c2a
-        GF_FREE (snap);
7f4c2a
-
7f4c2a
-        return 0;
7f4c2a
-}
7f4c2a
-
7f4c2a
-int32_t
7f4c2a
 glusterd_snap_remove (dict_t *rsp_dict,
7f4c2a
                       glusterd_snap_t *snap,
7f4c2a
                       gf_boolean_t remove_lvm,
7f4c2a
-- 
7f4c2a
1.7.1
7f4c2a