From 4dff6cb2d2592a173366751604cf8d716263a52d Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 6 Sep 2018 17:08:12 -0400 Subject: [PATCH] librbd: use the correct error code when the exclusive lock isn't locked If the client is currently blacklisted, use -EBLACKLISTED, otherwise use -EROFS. Signed-off-by: Jason Dillaman (cherry picked from commit e8eee15518facf562adf1aaba02d3a9523cdd2c3) Conflicts: src/librbd/ExclusiveLock.cc: trivial resolution src/librbd/image/RemoveRequest.cc: trivial resolution src/test/rbd_mirror/image_deleter/test_mock_SnapshotPurgeRequest.cc: DNE src/tools/rbd_mirror/image_deleter/SnapshotPurgeRequest.cc: DNE src/tools/rbd_mirror/image_deleter/SnapshotPurgeRequest.h: DNE src/librbd/DeepCopyRequest.cc: (see below) src/librbd/deep_copy/ObjectCopyRequest.cc: (see below) src/librbd/deep_copy/ObjectCopyRequest.h: (see below) src/librbd/deep_copy/SetHeadRequest.cc: (see below) src/librbd/deep_copy/SetHeadRequest.h: (see below) src/librbd/deep_copy/SnapshotCopyRequest.cc: (see below) src/librbd/deep_copy/SnapshotCopyRequest.h: (see below) src/librbd/deep_copy/SnapshotCreateRequest.cc: (see below) src/librbd/deep_copy/SnapshotCreateRequest.h: (see below) src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc: (see below) src/test/librbd/deep_copy/test_mock_SetHeadRequest.cc: (see below) src/test/librbd/deep_copy/test_mock_SnapshotCopyRequest.cc: (see below) src/test/librbd/deep_copy/test_mock_SnapshotCreateRequest.cc: (see below) src/test/librbd/test_mock_DeepCopyRequest.cc - deep-copy related files were originally derived from rbd-mirror equivalents. Similar modifications where made to the associated rbd-mirror files. --- src/librbd/ExclusiveLock.cc | 3 +- src/librbd/ExclusiveLock.h | 5 +- src/librbd/Operations.cc | 18 +++---- src/librbd/internal.cc | 13 ++--- src/librbd/io/ImageRequestWQ.cc | 4 +- src/librbd/mirror/DemoteRequest.cc | 5 +- .../operation/DisableFeaturesRequest.cc | 12 +++-- .../librbd/io/test_mock_ImageRequestWQ.cc | 42 +++++++++++++++++ src/test/librbd/mock/MockExclusiveLock.h | 2 +- .../image_sync/test_mock_ObjectCopyRequest.cc | 2 +- .../test_mock_SnapshotCopyRequest.cc | 2 +- .../test_mock_SnapshotCreateRequest.cc | 2 +- src/test/rbd_mirror/test_mock_ImageSync.cc | 2 +- src/tools/rbd_mirror/ImageSync.cc | 5 +- .../image_sync/ObjectCopyRequest.cc | 19 ++++---- .../rbd_mirror/image_sync/ObjectCopyRequest.h | 2 +- .../image_sync/SnapshotCopyRequest.cc | 25 ++++++---- .../image_sync/SnapshotCopyRequest.h | 2 +- .../image_sync/SnapshotCreateRequest.cc | 47 ++++++++++--------- .../image_sync/SnapshotCreateRequest.h | 2 +- 20 files changed, 138 insertions(+), 76 deletions(-) diff --git a/src/librbd/ExclusiveLock.cc b/src/librbd/ExclusiveLock.cc index b224a7504b43..a70e77e917c0 100644 --- a/src/librbd/ExclusiveLock.cc +++ b/src/librbd/ExclusiveLock.cc @@ -137,11 +137,12 @@ void ExclusiveLock::handle_peer_notification(int r) { } template -Context *ExclusiveLock::start_op() { +Context *ExclusiveLock::start_op(int* ret_val) { assert(m_image_ctx.owner_lock.is_locked()); Mutex::Locker locker(ML::m_lock); if (!accept_ops(ML::m_lock)) { + *ret_val = get_unlocked_op_error(); return nullptr; } diff --git a/src/librbd/ExclusiveLock.h b/src/librbd/ExclusiveLock.h index 3c5ebab33a38..8b2a411f4423 100644 --- a/src/librbd/ExclusiveLock.h +++ b/src/librbd/ExclusiveLock.h @@ -24,14 +24,13 @@ public: void block_requests(int r); void unblock_requests(); - int get_unlocked_op_error() const; - void init(uint64_t features, Context *on_init); void shut_down(Context *on_shutdown); void handle_peer_notification(int r); - Context *start_op(); + int get_unlocked_op_error() const; + Context *start_op(int* ret_val); protected: void shutdown_handler(int r, Context *on_finish) override; diff --git a/src/librbd/Operations.cc b/src/librbd/Operations.cc index e9e8fa4b76fd..ba90025ff7a5 100644 --- a/src/librbd/Operations.cc +++ b/src/librbd/Operations.cc @@ -224,14 +224,15 @@ struct C_InvokeAsyncRequest : public Context { ldout(cct, 20) << __func__ << ": r=" << r << dendl; if (r < 0) { - complete(-EROFS); + complete(r == -EBLACKLISTED ? -EBLACKLISTED : -EROFS); return; } // context can complete before owner_lock is unlocked RWLock &owner_lock(image_ctx.owner_lock); owner_lock.get_read(); - if (image_ctx.exclusive_lock->is_lock_owner()) { + if (image_ctx.exclusive_lock == nullptr || + image_ctx.exclusive_lock->is_lock_owner()) { send_local_request(); owner_lock.put_read(); return; @@ -786,7 +787,7 @@ int Operations::snap_rollback(const cls::rbd::SnapshotNamespace& snap_namespa r = prepare_image_update(false); if (r < 0) { - return -EROFS; + return r; } execute_snap_rollback(snap_namespace, snap_name, prog_ctx, &cond_ctx); @@ -1323,7 +1324,7 @@ int Operations::update_features(uint64_t features, bool enabled) { RWLock::RLocker owner_lock(m_image_ctx.owner_lock); r = prepare_image_update(true); if (r < 0) { - return -EROFS; + return r; } execute_update_features(features, enabled, &cond_ctx, 0); @@ -1435,10 +1436,6 @@ int Operations::metadata_remove(const std::string &key) { CephContext *cct = m_image_ctx.cct; ldout(cct, 5) << this << " " << __func__ << ": key=" << key << dendl; - if (m_image_ctx.read_only) { - return -EROFS; - } - int r = m_image_ctx.state->refresh_if_required(); if (r < 0) { return r; @@ -1529,11 +1526,14 @@ int Operations::prepare_image_update(bool request_lock) { m_image_ctx.exclusive_lock->unblock_requests(); } + if (r == -EAGAIN || r == -EBUSY) { + r = 0; + } if (r < 0) { return r; } else if (m_image_ctx.exclusive_lock != nullptr && !m_image_ctx.exclusive_lock->is_lock_owner()) { - return -EROFS; + return m_image_ctx.exclusive_lock->get_unlocked_op_error(); } return 0; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 2ee304bccb3b..bd77bb439f84 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1123,11 +1123,12 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { int is_exclusive_lock_owner(ImageCtx *ictx, bool *is_owner) { + CephContext *cct = ictx->cct; + ldout(cct, 20) << __func__ << ": ictx=" << ictx << dendl; *is_owner = false; RWLock::RLocker owner_locker(ictx->owner_lock); - if (ictx->exclusive_lock == nullptr || - !ictx->exclusive_lock->is_lock_owner()) { + if (ictx->exclusive_lock == nullptr) { return 0; } @@ -1183,11 +1184,11 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { } RWLock::RLocker l(ictx->owner_lock); - - if (ictx->exclusive_lock == nullptr || - !ictx->exclusive_lock->is_lock_owner()) { + if (ictx->exclusive_lock == nullptr) { + return -EINVAL; + } else if (!ictx->exclusive_lock->is_lock_owner()) { lderr(cct) << "failed to acquire exclusive lock" << dendl; - return -EROFS; + return ictx->exclusive_lock->get_unlocked_op_error(); } return 0; diff --git a/src/librbd/io/ImageRequestWQ.cc b/src/librbd/io/ImageRequestWQ.cc index 81800cc4ae73..fe2a39bd7fb1 100644 --- a/src/librbd/io/ImageRequestWQ.cc +++ b/src/librbd/io/ImageRequestWQ.cc @@ -7,6 +7,7 @@ #include "librbd/ExclusiveLock.h" #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" +#include "librbd/ImageWatcher.h" #include "librbd/internal.h" #include "librbd/Utils.h" #include "librbd/exclusive_lock/Policy.h" @@ -564,7 +565,8 @@ void *ImageRequestWQ::_void_dequeue() { ldout(cct, 5) << "exclusive lock required: delaying IO " << item << dendl; if (!m_image_ctx.get_exclusive_lock_policy()->may_auto_request_lock()) { lderr(cct) << "op requires exclusive lock" << dendl; - fail_in_flight_io(-EROFS, item); + fail_in_flight_io(m_image_ctx.exclusive_lock->get_unlocked_op_error(), + item); // wake up the IO since we won't be returning a request to process this->signal(); diff --git a/src/librbd/mirror/DemoteRequest.cc b/src/librbd/mirror/DemoteRequest.cc index 1fb23a5ddf22..c5d38752ea92 100644 --- a/src/librbd/mirror/DemoteRequest.cc +++ b/src/librbd/mirror/DemoteRequest.cc @@ -105,11 +105,12 @@ void DemoteRequest::handle_acquire_lock(int r) { } m_image_ctx.owner_lock.get_read(); - if (m_image_ctx.exclusive_lock == nullptr || + if (m_image_ctx.exclusive_lock != nullptr && !m_image_ctx.exclusive_lock->is_lock_owner()) { + r = m_image_ctx.exclusive_lock->get_unlocked_op_error(); m_image_ctx.owner_lock.put_read(); lderr(cct) << "failed to acquire exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } m_image_ctx.owner_lock.put_read(); diff --git a/src/librbd/operation/DisableFeaturesRequest.cc b/src/librbd/operation/DisableFeaturesRequest.cc index 34cc9579fe84..d7ddb23dea1a 100644 --- a/src/librbd/operation/DisableFeaturesRequest.cc +++ b/src/librbd/operation/DisableFeaturesRequest.cc @@ -160,19 +160,20 @@ Context *DisableFeaturesRequest::handle_acquire_exclusive_lock(int *result) { CephContext *cct = image_ctx.cct; ldout(cct, 20) << this << " " << __func__ << ": r=" << *result << dendl; + image_ctx.owner_lock.get_read(); if (*result < 0) { lderr(cct) << "failed to lock image: " << cpp_strerror(*result) << dendl; + image_ctx.owner_lock.put_read(); return handle_finish(*result); - } else if (m_acquired_lock && (image_ctx.exclusive_lock == nullptr || - !image_ctx.exclusive_lock->is_lock_owner())) { + } else if (image_ctx.exclusive_lock != nullptr && + !image_ctx.exclusive_lock->is_lock_owner()) { lderr(cct) << "failed to acquire exclusive lock" << dendl; - *result = -EROFS; + *result = image_ctx.exclusive_lock->get_unlocked_op_error(); + image_ctx.owner_lock.put_read(); return handle_finish(*result); } do { - RWLock::WLocker locker(image_ctx.owner_lock); - m_features &= image_ctx.features; m_new_features = image_ctx.features & ~m_features; m_features_mask = m_features; @@ -202,6 +203,7 @@ Context *DisableFeaturesRequest::handle_acquire_exclusive_lock(int *result) { m_disable_flags |= RBD_FLAG_OBJECT_MAP_INVALID; } } while (false); + image_ctx.owner_lock.put_read(); if (*result < 0) { return handle_finish(*result); diff --git a/src/test/librbd/io/test_mock_ImageRequestWQ.cc b/src/test/librbd/io/test_mock_ImageRequestWQ.cc index 66589e5088dc..7a731db23a82 100644 --- a/src/test/librbd/io/test_mock_ImageRequestWQ.cc +++ b/src/test/librbd/io/test_mock_ImageRequestWQ.cc @@ -240,6 +240,48 @@ TEST_F(TestMockIoImageRequestWQ, AcquireLockError) { aio_comp->release(); } +TEST_F(TestMockIoImageRequestWQ, AcquireLockBlacklisted) { + REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK); + + librbd::ImageCtx *ictx; + ASSERT_EQ(0, open_image(m_image_name, &ictx)); + + MockTestImageCtx mock_image_ctx(*ictx); + MockExclusiveLock mock_exclusive_lock; + mock_image_ctx.exclusive_lock = &mock_exclusive_lock; + + InSequence seq; + MockImageRequestWQ mock_image_request_wq(&mock_image_ctx, "io", 60, nullptr); + expect_signal(mock_image_request_wq); + mock_image_request_wq.set_require_lock(DIRECTION_WRITE, true); + + auto mock_image_request = new MockImageRequest(); + expect_is_write_op(*mock_image_request, true); + expect_queue(mock_image_request_wq); + auto *aio_comp = new librbd::io::AioCompletion(); + mock_image_request_wq.aio_write(aio_comp, 0, 0, {}, 0); + + librbd::exclusive_lock::MockPolicy mock_exclusive_lock_policy; + expect_front(mock_image_request_wq, mock_image_request); + expect_is_refresh_request(mock_image_ctx, false); + expect_is_write_op(*mock_image_request, true); + expect_dequeue(mock_image_request_wq, mock_image_request); + expect_get_exclusive_lock_policy(mock_image_ctx, mock_exclusive_lock_policy); + expect_may_auto_request_lock(mock_exclusive_lock_policy, false); + EXPECT_CALL(*mock_image_ctx.exclusive_lock, get_unlocked_op_error()) + .WillOnce(Return(-EBLACKLISTED)); + + expect_process_finish(mock_image_request_wq); + expect_fail(*mock_image_request, -EBLACKLISTED); + expect_is_write_op(*mock_image_request, true); + expect_signal(mock_image_request_wq); + ASSERT_TRUE(mock_image_request_wq.invoke_dequeue() == nullptr); + + ASSERT_EQ(0, aio_comp->wait_for_complete()); + ASSERT_EQ(-EBLACKLISTED, aio_comp->get_return_value()); + aio_comp->release(); +} + TEST_F(TestMockIoImageRequestWQ, RefreshError) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); diff --git a/src/test/librbd/mock/MockExclusiveLock.h b/src/test/librbd/mock/MockExclusiveLock.h index f8eeb0d20a85..1b49fa6a75dc 100644 --- a/src/test/librbd/mock/MockExclusiveLock.h +++ b/src/test/librbd/mock/MockExclusiveLock.h @@ -31,7 +31,7 @@ struct MockExclusiveLock { MOCK_METHOD0(accept_ops, bool()); MOCK_METHOD0(get_unlocked_op_error, int()); - MOCK_METHOD0(start_op, Context*()); + MOCK_METHOD1(start_op, Context*(int*)); }; } // namespace librbd diff --git a/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc index f70df5c0582f..b803813a0884 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc @@ -90,7 +90,7 @@ public: } void expect_start_op(librbd::MockExclusiveLock &mock_exclusive_lock) { - EXPECT_CALL(mock_exclusive_lock, start_op()).WillOnce( + EXPECT_CALL(mock_exclusive_lock, start_op(_)).WillOnce( ReturnNew([](int) {})); } diff --git a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc index 7801b66bd9ce..377af67f7ed3 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc @@ -107,7 +107,7 @@ public: } void expect_start_op(librbd::MockExclusiveLock &mock_exclusive_lock) { - EXPECT_CALL(mock_exclusive_lock, start_op()).WillOnce( + EXPECT_CALL(mock_exclusive_lock, start_op(_)).WillOnce( ReturnNew([](int) {})); } diff --git a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc index 4a8ab1fc73cf..cbf22e32bc4e 100644 --- a/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc +++ b/src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc @@ -56,7 +56,7 @@ public: } void expect_start_op(librbd::MockExclusiveLock &mock_exclusive_lock) { - EXPECT_CALL(mock_exclusive_lock, start_op()).WillOnce( + EXPECT_CALL(mock_exclusive_lock, start_op(_)).WillOnce( ReturnNew([](int) {})); } diff --git a/src/test/rbd_mirror/test_mock_ImageSync.cc b/src/test/rbd_mirror/test_mock_ImageSync.cc index 25b2cadc79fa..7741848aeed7 100644 --- a/src/test/rbd_mirror/test_mock_ImageSync.cc +++ b/src/test/rbd_mirror/test_mock_ImageSync.cc @@ -225,7 +225,7 @@ public: } void expect_start_op(librbd::MockExclusiveLock &mock_exclusive_lock) { - EXPECT_CALL(mock_exclusive_lock, start_op()).WillOnce( + EXPECT_CALL(mock_exclusive_lock, start_op(_)).WillOnce( ReturnNew([](int) {})); } diff --git a/src/tools/rbd_mirror/ImageSync.cc b/src/tools/rbd_mirror/ImageSync.cc index 7361cfbb4c06..14e6bd46a053 100644 --- a/src/tools/rbd_mirror/ImageSync.cc +++ b/src/tools/rbd_mirror/ImageSync.cc @@ -315,15 +315,16 @@ void ImageSync::send_copy_object_map() { dout(20) << ": snap_id=" << snap_id << ", " << "snap_name=" << sync_point.snap_name << dendl; + int r = -EROFS; Context *finish_op_ctx = nullptr; if (m_local_image_ctx->exclusive_lock != nullptr) { - finish_op_ctx = m_local_image_ctx->exclusive_lock->start_op(); + finish_op_ctx = m_local_image_ctx->exclusive_lock->start_op(&r); } if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; m_local_image_ctx->snap_lock.put_read(); m_local_image_ctx->owner_lock.put_read(); - finish(-EROFS); + finish(r); return; } diff --git a/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.cc b/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.cc index 533f175f9ff3..377a62a1814c 100644 --- a/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.cc +++ b/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.cc @@ -218,14 +218,15 @@ void ObjectCopyRequest::send_write_object() { } } + int r; Context *finish_op_ctx; { RWLock::RLocker owner_locker(m_local_image_ctx->owner_lock); - finish_op_ctx = start_local_op(m_local_image_ctx->owner_lock); + finish_op_ctx = start_local_op(m_local_image_ctx->owner_lock, &r); } if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -294,8 +295,8 @@ void ObjectCopyRequest::send_write_object() { finish_op_ctx->complete(0); }); librados::AioCompletion *comp = create_rados_callback(ctx); - int r = m_local_io_ctx.aio_operate(m_local_oid, comp, &op, local_snap_seq, - local_snap_ids); + r = m_local_io_ctx.aio_operate(m_local_oid, comp, &op, local_snap_seq, + local_snap_ids); assert(r == 0); comp->release(); } @@ -354,12 +355,13 @@ void ObjectCopyRequest::send_update_object_map() { << "object_state=" << static_cast(snap_object_state.second) << dendl; - auto finish_op_ctx = start_local_op(m_local_image_ctx->owner_lock); + int r; + auto finish_op_ctx = start_local_op(m_local_image_ctx->owner_lock, &r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; m_local_image_ctx->snap_lock.put_read(); m_local_image_ctx->owner_lock.put_read(); - finish(-EROFS); + finish(r); return; } @@ -391,12 +393,13 @@ void ObjectCopyRequest::handle_update_object_map(int r) { } template -Context *ObjectCopyRequest::start_local_op(RWLock &owner_lock) { +Context *ObjectCopyRequest::start_local_op(RWLock &owner_lock, int *r) { assert(m_local_image_ctx->owner_lock.is_locked()); if (m_local_image_ctx->exclusive_lock == nullptr) { + *r = -EROFS; return nullptr; } - return m_local_image_ctx->exclusive_lock->start_op(); + return m_local_image_ctx->exclusive_lock->start_op(r); } template diff --git a/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h b/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h index d52097dc6fbd..0ef205a07a66 100644 --- a/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h +++ b/src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h @@ -138,7 +138,7 @@ private: void send_update_object_map(); void handle_update_object_map(int r); - Context *start_local_op(RWLock &owner_lock); + Context *start_local_op(RWLock &owner_lock, int *r); void compute_diffs(); void finish(int r); diff --git a/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc b/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc index f5f0701d1134..be38b098c02b 100644 --- a/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc +++ b/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc @@ -170,10 +170,11 @@ void SnapshotCopyRequest::send_snap_unprotect() { << "snap_name=" << m_snap_name << ", " << "snap_id=" << m_prev_snap_id << dendl; - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -257,10 +258,11 @@ void SnapshotCopyRequest::send_snap_remove() { << "snap_name=" << m_snap_name << ", " << "snap_id=" << m_prev_snap_id << dendl; - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -360,10 +362,11 @@ void SnapshotCopyRequest::send_snap_create() { << "snap_id=" << parent_spec.snap_id << ", " << "overlap=" << parent_overlap << "]" << dendl; - Context *finish_op_ctx = start_local_op(); + int r; + Context *finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -471,10 +474,11 @@ void SnapshotCopyRequest::send_snap_protect() { << "snap_name=" << m_snap_name << ", " << "snap_id=" << m_prev_snap_id << dendl; - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -599,12 +603,13 @@ int SnapshotCopyRequest::validate_parent(I *image_ctx, } template -Context *SnapshotCopyRequest::start_local_op() { +Context *SnapshotCopyRequest::start_local_op(int *r) { RWLock::RLocker owner_locker(m_local_image_ctx->owner_lock); if (m_local_image_ctx->exclusive_lock == nullptr) { + *r = -EROFS; return nullptr; } - return m_local_image_ctx->exclusive_lock->start_op(); + return m_local_image_ctx->exclusive_lock->start_op(r); } } // namespace image_sync diff --git a/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.h b/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.h index 85ae4d41305a..464764044a47 100644 --- a/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.h +++ b/src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.h @@ -134,7 +134,7 @@ private: int validate_parent(ImageCtxT *image_ctx, librbd::ParentSpec *spec); - Context *start_local_op(); + Context *start_local_op(int *r); }; diff --git a/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.cc b/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.cc index 238417934354..44e805b39f39 100644 --- a/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.cc +++ b/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.cc @@ -63,10 +63,11 @@ void SnapshotCreateRequest::send_set_size() { librados::ObjectWriteOperation op; librbd::cls_client::set_size(&op, m_size); - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -75,8 +76,8 @@ void SnapshotCreateRequest::send_set_size() { finish_op_ctx->complete(0); }); librados::AioCompletion *comp = create_rados_callback(ctx); - int r = m_local_image_ctx->md_ctx.aio_operate(m_local_image_ctx->header_oid, - comp, &op); + r = m_local_image_ctx->md_ctx.aio_operate(m_local_image_ctx->header_oid, comp, + &op); assert(r == 0); comp->release(); } @@ -117,10 +118,11 @@ void SnapshotCreateRequest::send_remove_parent() { librados::ObjectWriteOperation op; librbd::cls_client::remove_parent(&op); - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -129,8 +131,8 @@ void SnapshotCreateRequest::send_remove_parent() { finish_op_ctx->complete(0); }); librados::AioCompletion *comp = create_rados_callback(ctx); - int r = m_local_image_ctx->md_ctx.aio_operate(m_local_image_ctx->header_oid, - comp, &op); + r = m_local_image_ctx->md_ctx.aio_operate(m_local_image_ctx->header_oid, comp, + &op); assert(r == 0); comp->release(); } @@ -172,10 +174,11 @@ void SnapshotCreateRequest::send_set_parent() { librados::ObjectWriteOperation op; librbd::cls_client::set_parent(&op, m_parent_spec, m_parent_overlap); - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -184,8 +187,8 @@ void SnapshotCreateRequest::send_set_parent() { finish_op_ctx->complete(0); }); librados::AioCompletion *comp = create_rados_callback(ctx); - int r = m_local_image_ctx->md_ctx.aio_operate(m_local_image_ctx->header_oid, - comp, &op); + r = m_local_image_ctx->md_ctx.aio_operate(m_local_image_ctx->header_oid, comp, + &op); assert(r == 0); comp->release(); } @@ -215,10 +218,11 @@ template void SnapshotCreateRequest::send_snap_create() { dout(20) << ": snap_name=" << m_snap_name << dendl; - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -229,8 +233,7 @@ void SnapshotCreateRequest::send_snap_create() { RWLock::RLocker owner_locker(m_local_image_ctx->owner_lock); m_local_image_ctx->operations->execute_snap_create(m_snap_namespace, m_snap_name.c_str(), - ctx, - 0U, true); + ctx, 0U, true); } template @@ -279,10 +282,11 @@ void SnapshotCreateRequest::send_create_object_map() { librados::ObjectWriteOperation op; librbd::cls_client::object_map_resize(&op, object_count, OBJECT_NONEXISTENT); - auto finish_op_ctx = start_local_op(); + int r; + auto finish_op_ctx = start_local_op(&r); if (finish_op_ctx == nullptr) { derr << ": lost exclusive lock" << dendl; - finish(-EROFS); + finish(r); return; } @@ -291,7 +295,7 @@ void SnapshotCreateRequest::send_create_object_map() { finish_op_ctx->complete(0); }); librados::AioCompletion *comp = create_rados_callback(ctx); - int r = m_local_image_ctx->md_ctx.aio_operate(object_map_oid, comp, &op); + r = m_local_image_ctx->md_ctx.aio_operate(object_map_oid, comp, &op); assert(r == 0); comp->release(); } @@ -311,12 +315,13 @@ void SnapshotCreateRequest::handle_create_object_map(int r) { } template -Context *SnapshotCreateRequest::start_local_op() { +Context *SnapshotCreateRequest::start_local_op(int *r) { RWLock::RLocker owner_locker(m_local_image_ctx->owner_lock); if (m_local_image_ctx->exclusive_lock == nullptr) { + *r = -EROFS; return nullptr; } - return m_local_image_ctx->exclusive_lock->start_op(); + return m_local_image_ctx->exclusive_lock->start_op(r); } template diff --git a/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.h b/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.h index 503a164a0d59..76ba9fc2ca65 100644 --- a/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.h +++ b/src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.h @@ -94,7 +94,7 @@ private: void send_create_object_map(); void handle_create_object_map(int r); - Context *start_local_op(); + Context *start_local_op(int *r); void finish(int r); }; -- 2.47.3