Blob Blame History Raw
From d2f48b625c0d7d361b62f7a4f1a698bef3d67dc9 Mon Sep 17 00:00:00 2001
From: Mohammed Rafi KC <rkavunga@redhat.com>
Date: Tue, 17 Mar 2015 19:57:47 +0530
Subject: [PATCH 302/304] snapshot:cleanup snaps during unprobe

    Backport of http://review.gluster.org/#/c/9930/

When doing an unprobe, the volume that doesnot
contain any brick of the particular node will be
deleted. So the snaps associated with that volume
should also delete

Change-Id: I9f3d23bd11b254ebf7d7722cc1e12455d6b024ff
BUG: 1238111
Signed-off-by: Mohammed Rafi KC <rkavunga@redhat.com>
Reviewed-on: http://review.gluster.org/9930
Tested-by: NetBSD Build System <jenkins@build.gluster.org>
Reviewed-by: Avra Sengupta <asengupt@redhat.com>
Reviewed-by: Rajesh Joseph <rjoseph@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/56396
Tested-by: Rajesh Joseph <rjoseph@redhat.com>
---
 xlators/mgmt/glusterd/src/glusterd-sm.c            |    9 ++
 .../mgmt/glusterd/src/glusterd-snapshot-utils.c    |   89 ++++++++++++++++++++
 .../mgmt/glusterd/src/glusterd-snapshot-utils.h    |    5 +
 xlators/mgmt/glusterd/src/glusterd-snapshot.c      |   23 +-----
 4 files changed, 104 insertions(+), 22 deletions(-)

diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index 8e91cef..f0159b2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -635,6 +635,15 @@ glusterd_peer_detach_cleanup (glusterd_conf_t *priv)
                         gf_msg (THIS->name, GF_LOG_INFO, 0,
                                 GD_MSG_STALE_VOL_DELETE_INFO,
                                 "Deleting stale volume %s", volinfo->volname);
+
+                        ret = glusterd_cleanup_snaps_for_volume (volinfo);
+                        if (ret) {
+                                gf_msg (THIS->name, GF_LOG_ERROR, 0,
+                                        GD_MSG_VOL_DELETE_FAIL,
+                                        "Error deleting snapshots for volume %s",
+                                        volinfo->volname);
+                        }
+
                         ret = glusterd_delete_volume (volinfo);
                         if (ret) {
                                 gf_msg (THIS->name, GF_LOG_ERROR, 0,
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
index acc4e42..ccea9ff 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c
@@ -40,6 +40,95 @@
  *      This function restores the atime and mtime of marker.tstamp
  *      if present from snapped marker.tstamp file.
  */
+
+int32_t
+glusterd_snapobject_delete (glusterd_snap_t *snap)
+{
+        if (snap == NULL) {
+                gf_msg(THIS->name, GF_LOG_WARNING, 0,
+                       GD_MSG_PARAM_NULL, "snap is NULL");
+                return -1;
+        }
+
+        cds_list_del_init (&snap->snap_list);
+        cds_list_del_init (&snap->volumes);
+        if (LOCK_DESTROY(&snap->lock))
+                gf_msg (THIS->name, GF_LOG_WARNING, 0,
+                        GD_MSG_LOCK_DESTROY_FAILED,
+                        "Failed destroying lock"
+                        "of snap %s", snap->snapname);
+
+        GF_FREE (snap->description);
+        GF_FREE (snap);
+
+        return 0;
+}
+
+
+/*
+ * This function is to be called only from glusterd_peer_detach_cleanup()
+ * as this continues to delete snaps inspite of faiure while deleting
+ * one, as we don't want to fail peer_detach in such a case.
+ */
+int
+glusterd_cleanup_snaps_for_volume (glusterd_volinfo_t *volinfo)
+{
+        int32_t                  op_ret         = 0;
+        int32_t                  ret            = 0;
+        xlator_t                *this           = NULL;
+        glusterd_volinfo_t      *snap_vol       = NULL;
+        glusterd_volinfo_t      *dummy_snap_vol = NULL;
+        glusterd_snap_t         *snap           = NULL;
+
+        this = THIS;
+        GF_ASSERT (this);
+
+        cds_list_for_each_entry_safe (snap_vol, dummy_snap_vol,
+                                      &volinfo->snap_volumes,
+                                      snapvol_list) {
+                ret = glusterd_store_delete_volume (snap_vol);
+                if (ret) {
+                        gf_msg(this->name, GF_LOG_WARNING, 0,
+                               GD_MSG_VOL_DELETE_FAIL, "Failed to remove "
+                               "volume %s from store", snap_vol->volname);
+                        op_ret = ret;
+                        continue;
+                }
+
+                ret = glusterd_volinfo_delete (snap_vol);
+                if (ret) {
+                        gf_msg(this->name, GF_LOG_WARNING, 0,
+                               GD_MSG_VOL_DELETE_FAIL, "Failed to remove "
+                              "volinfo %s ", snap_vol->volname);
+                        op_ret = ret;
+                        continue;
+                }
+
+                snap = snap_vol->snapshot;
+                ret = glusterd_store_delete_snap (snap);
+                if (ret) {
+                        gf_msg(this->name, GF_LOG_WARNING, 0,
+                               GD_MSG_VOL_DELETE_FAIL, "Failed to remove "
+                               "snap %s from store", snap->snapname);
+                        op_ret = ret;
+                        continue;
+                }
+
+                ret = glusterd_snapobject_delete (snap);
+                if (ret) {
+                        gf_msg (this->name, GF_LOG_WARNING, 0,
+                                GD_MSG_VOL_DELETE_FAIL, "Failed to delete "
+                                "snap object %s", snap->snapname);
+                        op_ret = ret;
+                        continue;
+                }
+        }
+
+        return op_ret;
+}
+
+
+
 int
 glusterd_snap_geo_rep_restore (glusterd_volinfo_t *snap_volinfo,
                                glusterd_volinfo_t *new_volinfo)
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
index ce8d7d4..63d39e8 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h
@@ -38,6 +38,11 @@ glusterd_snap_volinfo_restore (dict_t *dict, dict_t *rsp_dict,
                                glusterd_volinfo_t *new_volinfo,
                                glusterd_volinfo_t *snap_volinfo,
                                int32_t volcount);
+int32_t
+glusterd_snapobject_delete (glusterd_snap_t *snap);
+
+int32_t
+glusterd_cleanup_snaps_for_volume (glusterd_volinfo_t *volinfo);
 
 int32_t
 glusterd_missed_snapinfo_new (glusterd_missed_snap_info **missed_snapinfo);
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 080aa88..6f10ebc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -86,6 +86,7 @@ typedef struct snap_create_args_ snap_create_args_t;
    then the snap device will be /dev/<group-name>/<snapname>.
    This function takes care of building the path for the snap device.
 */
+
 char *
 glusterd_build_snap_device_path (char *device, char *snapname,
                                  int32_t brickcount)
@@ -2961,28 +2962,6 @@ out:
 }
 
 int32_t
-glusterd_snapobject_delete (glusterd_snap_t *snap)
-{
-        if (snap == NULL) {
-                gf_msg(THIS->name, GF_LOG_WARNING, EINVAL,
-                       GD_MSG_INVALID_ENTRY, "snap is NULL");
-                return -1;
-        }
-
-        cds_list_del_init (&snap->snap_list);
-        cds_list_del_init (&snap->volumes);
-        if (LOCK_DESTROY(&snap->lock))
-                gf_msg (THIS->name, GF_LOG_WARNING, 0,
-                        GD_MSG_LOCK_DESTROY_FAILED, "Failed destroying lock"
-                        "of snap %s", snap->snapname);
-
-        GF_FREE (snap->description);
-        GF_FREE (snap);
-
-        return 0;
-}
-
-int32_t
 glusterd_snap_remove (dict_t *rsp_dict,
                       glusterd_snap_t *snap,
                       gf_boolean_t remove_lvm,
-- 
1.7.1