]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: image deleter properly handles multiple snapshots 9618/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 10 Jun 2016 04:12:06 +0000 (00:12 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 10 Jun 2016 04:15:27 +0000 (00:15 -0400)
Fixes: http://tracker.ceph.com/issues/16226
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd_mirror/ImageDeleter.cc

index 8e65223659e0657c61498d34cdf5c6783c9654f8..f67019aab4b6d0835cfe6c11a2ac154a32b0c970 100644 (file)
@@ -26,6 +26,7 @@
 #include "librbd/ImageState.h"
 #include "librbd/Journal.h"
 #include "librbd/Operations.h"
+#include "librbd/journal/Policy.h"
 #include "cls/rbd/cls_rbd_client.h"
 #include "cls/rbd/cls_rbd_types.h"
 #include "librbd/Utils.h"
@@ -70,6 +71,16 @@ private:
   ImageDeleter *image_del;
 };
 
+struct DeleteJournalPolicy : public librbd::journal::Policy {
+  virtual void allocate_tag_on_lock(Context *on_finish) {
+    on_finish->complete(0);
+  }
+
+  virtual void cancel_external_replay(Context *on_finish) {
+    on_finish->complete(0);
+  }
+};
+
 } // anonymous namespace
 
 class ImageDeleterAdminSocketHook : public AdminSocketHook {
@@ -302,10 +313,10 @@ bool ImageDeleter::process_image_delete() {
       return true;
     }
 
-    // We are disabling Journaling so that we can delete image snapshots
-    // of a non-primary image. Otherwise, we would fail to acquire the
-    // exclusive lock.
-    imgctx->features ^= RBD_FEATURE_JOURNALING;
+    {
+      RWLock::WLocker snap_locker(imgctx->snap_lock);
+      imgctx->set_journal_policy(new DeleteJournalPolicy());
+    }
 
     std::vector<librbd::snap_info_t> snaps;
     r = librbd::snap_list(imgctx, snaps);
@@ -354,16 +365,6 @@ bool ImageDeleter::process_image_delete() {
           enqueue_failed_delete(r);
           return true;
         }
-
-        r = imgctx->state->refresh();
-        if (r < 0) {
-          derr << "error refreshing image " << imgctx->name << ": "
-               << cpp_strerror(r) << dendl;
-          imgctx->state->close();
-          enqueue_failed_delete(r);
-          return true;
-        }
-        imgctx->features ^= RBD_FEATURE_JOURNALING;
       }
 
       r = imgctx->operations->snap_remove(snap.name.c_str());