From dc38a26e2e48f0a1fabdb51f1819e402e5b214ce Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 10 Jun 2016 00:12:06 -0400 Subject: [PATCH] rbd-mirror: image deleter properly handles multiple snapshots Fixes: http://tracker.ceph.com/issues/16226 Signed-off-by: Jason Dillaman (cherry picked from commit d72a8cb67fbdc7361f8f9e265c659ddb96dc0f74) --- src/tools/rbd_mirror/ImageDeleter.cc | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/tools/rbd_mirror/ImageDeleter.cc b/src/tools/rbd_mirror/ImageDeleter.cc index 8e65223659e0..f67019aab4b6 100644 --- a/src/tools/rbd_mirror/ImageDeleter.cc +++ b/src/tools/rbd_mirror/ImageDeleter.cc @@ -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 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()); -- 2.47.3