]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use the correct error code when the exclusive lock isn't locked 24405/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 6 Sep 2018 21:08:12 +0000 (17:08 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 3 Oct 2018 17:48:15 +0000 (13:48 -0400)
If the client is currently blacklisted, use -EBLACKLISTED, otherwise
use -EROFS.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(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.

20 files changed:
src/librbd/ExclusiveLock.cc
src/librbd/ExclusiveLock.h
src/librbd/Operations.cc
src/librbd/internal.cc
src/librbd/io/ImageRequestWQ.cc
src/librbd/mirror/DemoteRequest.cc
src/librbd/operation/DisableFeaturesRequest.cc
src/test/librbd/io/test_mock_ImageRequestWQ.cc
src/test/librbd/mock/MockExclusiveLock.h
src/test/rbd_mirror/image_sync/test_mock_ObjectCopyRequest.cc
src/test/rbd_mirror/image_sync/test_mock_SnapshotCopyRequest.cc
src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc
src/test/rbd_mirror/test_mock_ImageSync.cc
src/tools/rbd_mirror/ImageSync.cc
src/tools/rbd_mirror/image_sync/ObjectCopyRequest.cc
src/tools/rbd_mirror/image_sync/ObjectCopyRequest.h
src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc
src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.h
src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.cc
src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.h

index b224a7504b43bfb2c42b3831e8668b7011d12c75..a70e77e917c053594b6038c6017a342282ece78c 100644 (file)
@@ -137,11 +137,12 @@ void ExclusiveLock<I>::handle_peer_notification(int r) {
 }
 
 template <typename I>
-Context *ExclusiveLock<I>::start_op() {
+Context *ExclusiveLock<I>::start_op(int* ret_val) {
   assert(m_image_ctx.owner_lock.is_locked());
   Mutex::Locker locker(ML<I>::m_lock);
 
   if (!accept_ops(ML<I>::m_lock)) {
+    *ret_val = get_unlocked_op_error();
     return nullptr;
   }
 
index 3c5ebab33a38dbe3d3d71a71b0967bd115ebe9b0..8b2a411f44232debfed2996337bf48b0ec1789f5 100644 (file)
@@ -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;
index e9e8fa4b76fdf2a6f50ed044d661fac11fe1e770..ba90025ff7a5610083771f684232664106947648 100644 (file)
@@ -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<I>::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<I>::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<I>::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<I>::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;
index 2ee304bccb3b1d8545630f3b333bdf29153e1b16..bd77bb439f849391f5e24939b5ddb45c0be057bf 100644 (file)
@@ -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;
index 81800cc4ae73cf904fb245ce98c91b83a1f210e9..fe2a39bd7fb1a78c3c06df6efd12c1168a68f93a 100644 (file)
@@ -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<I>::_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();
index 1fb23a5ddf2253f5533d3a9ccdf0b46b3e5906cb..c5d38752ea9200b4c1f73a0f7d96210eb7e69c38 100644 (file)
@@ -105,11 +105,12 @@ void DemoteRequest<I>::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();
index 34cc9579fe84567a41fdf6c7cd4a400cc6dfddbc..d7ddb23dea1a99f087941c7fda8f7c5925306e35 100644 (file)
@@ -160,19 +160,20 @@ Context *DisableFeaturesRequest<I>::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<I>::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);
index 66589e5088dc0f9dd4cf9029223b326c7b0499d8..7a731db23a821b7ea0ed61be9fd329b1ccabaeec 100644 (file)
@@ -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));
index f8eeb0d20a850e4aaece10dee73b13f106f042b7..1b49fa6a75dc18cb983d48fdeeb63fbfbb9e1d77 100644 (file)
@@ -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
index f70df5c0582f58251047b442b06fda3c13fb9465..b803813a08843c032d3244844f6f39f3cc865f6e 100644 (file)
@@ -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<FunctionContext>([](int) {}));
   }
 
index 7801b66bd9ced787d72913dc8cbde710ef83c7ff..377af67f7ed3292ca0f66749f9055ec69d4f40e9 100644 (file)
@@ -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<FunctionContext>([](int) {}));
   }
 
index 4a8ab1fc73cf39f0cb420eec81286bb50b5515c7..cbf22e32bc4ef10e85bef75a2a4210020b0c5f21 100644 (file)
@@ -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<FunctionContext>([](int) {}));
   }
 
index 25b2cadc79fa0befae49f1718f1f30f592af37ce..7741848aeed7fe710b2622cee033ca2c9d68ec1e 100644 (file)
@@ -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<FunctionContext>([](int) {}));
   }
 
index 7361cfbb4c06ecff85269a69ed678504f9802491..14e6bd46a053b114ae4191f180a00a6f5abc2c71 100644 (file)
@@ -315,15 +315,16 @@ void ImageSync<I>::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;
   }
 
index 533f175f9ff3011cfc5f054d277c1bb52ccf6421..377a62a1814c5939c4af9b7387c51145f58640e2 100644 (file)
@@ -218,14 +218,15 @@ void ObjectCopyRequest<I>::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<I>::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<I>::send_update_object_map() {
            << "object_state=" << static_cast<uint32_t>(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<I>::handle_update_object_map(int r) {
 }
 
 template <typename I>
-Context *ObjectCopyRequest<I>::start_local_op(RWLock &owner_lock) {
+Context *ObjectCopyRequest<I>::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 <typename I>
index d52097dc6fbd48f13dd6f0cce28239b0087499dd..0ef205a07a6684e3b64b937ebd9db3fde44cb6df 100644 (file)
@@ -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);
index f5f0701d1134c1cb0ed346f93eacabaade27e006..be38b098c02ba58165ed5a770ebc953b51dc7a77 100644 (file)
@@ -170,10 +170,11 @@ void SnapshotCopyRequest<I>::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<I>::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<I>::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<I>::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<I>::validate_parent(I *image_ctx,
 }
 
 template <typename I>
-Context *SnapshotCopyRequest<I>::start_local_op() {
+Context *SnapshotCopyRequest<I>::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
index 85ae4d41305a025c35e8904d7a9d2f1c36b905d1..464764044a4744d0faf7a942a9be5bdbed8e6ad7 100644 (file)
@@ -134,7 +134,7 @@ private:
 
   int validate_parent(ImageCtxT *image_ctx, librbd::ParentSpec *spec);
 
-  Context *start_local_op();
+  Context *start_local_op(int *r);
 
 };
 
index 2384179343549c8ad4446c8c3b71630ee1ade2fa..44e805b39f398bf64596efabf6a653868994b91c 100644 (file)
@@ -63,10 +63,11 @@ void SnapshotCreateRequest<I>::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<I>::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<I>::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<I>::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<I>::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<I>::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 <typename I>
 void SnapshotCreateRequest<I>::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<I>::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 <typename I>
@@ -279,10 +282,11 @@ void SnapshotCreateRequest<I>::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<I>::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<I>::handle_create_object_map(int r) {
 }
 
 template <typename I>
-Context *SnapshotCreateRequest<I>::start_local_op() {
+Context *SnapshotCreateRequest<I>::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 <typename I>
index 503a164a0d5966af106b88c6c4f5616e1814f3dc..76ba9fc2ca658b40618e5806d0549ec160bfbb61 100644 (file)
@@ -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);
 };