From: Mykola Golub Date: Tue, 29 Oct 2019 14:39:09 +0000 (+0200) Subject: librbd: do not try to open parent journal when removing trash snapshot X-Git-Tag: v13.2.9~96^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bb7890013bed2013352aeeaeaf2fe69d43984d28;p=ceph.git librbd: do not try to open parent journal when removing trash snapshot Because the parent may be not promoted. Also disallow any proxied maintenance operations before acquiring the lock. Fixes: https://tracker.ceph.com/issues/42405 Signed-off-by: Mykola Golub (cherry picked from commit 23e300cbf99987902669baeb6486d9ad37c8c69d) Conflicts: src/librbd/image/DetachChildRequest.cc (headers, RWLock::RLocker vs std::shared_lock, snap_lock vs image_lock) --- diff --git a/src/librbd/image/DetachChildRequest.cc b/src/librbd/image/DetachChildRequest.cc index a573ac251e46..b10235b35170 100644 --- a/src/librbd/image/DetachChildRequest.cc +++ b/src/librbd/image/DetachChildRequest.cc @@ -6,10 +6,12 @@ #include "common/errno.h" #include "common/WorkQueue.h" #include "cls/rbd/cls_rbd_client.h" +#include "librbd/ExclusiveLock.h" #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" #include "librbd/Operations.h" #include "librbd/Utils.h" +#include "librbd/journal/DisabledPolicy.h" #include #define dout_subsys ceph_subsys_rbd @@ -176,6 +178,21 @@ void DetachChildRequest::handle_clone_v2_open_parent(int r) { return; } + // do not attempt to open the parent journal when removing the trash + // snapshot, because the parent may be not promoted + if (m_parent_image_ctx->test_features(RBD_FEATURE_JOURNALING)) { + RWLock::WLocker snap_locker(m_parent_image_ctx->snap_lock); + m_parent_image_ctx->set_journal_policy(new journal::DisabledPolicy()); + } + + // disallow any proxied maintenance operations + { + RWLock::RLocker owner_lock(m_parent_image_ctx->owner_lock); + if (m_parent_image_ctx->exclusive_lock != nullptr) { + m_parent_image_ctx->exclusive_lock->block_requests(0); + } + } + clone_v2_remove_snapshot(); } diff --git a/src/test/librbd/image/test_mock_DetachChildRequest.cc b/src/test/librbd/image/test_mock_DetachChildRequest.cc index 4167598c85c7..43161480295d 100644 --- a/src/test/librbd/image/test_mock_DetachChildRequest.cc +++ b/src/test/librbd/image/test_mock_DetachChildRequest.cc @@ -118,6 +118,10 @@ public: .WillOnce(WithArg<1>(Invoke([this, r](Context* ctx) { image_ctx->op_work_queue->queue(ctx, r); }))); + if (r == 0) { + EXPECT_CALL(mock_image_ctx, test_features(_)) + .WillOnce(Return(false)); + } } void expect_close(MockImageCtx &mock_image_ctx, int r) {