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

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
27 files changed:
src/librbd/DeepCopyRequest.cc
src/librbd/ExclusiveLock.cc
src/librbd/ExclusiveLock.h
src/librbd/Operations.cc
src/librbd/deep_copy/ObjectCopyRequest.cc
src/librbd/deep_copy/ObjectCopyRequest.h
src/librbd/deep_copy/SetHeadRequest.cc
src/librbd/deep_copy/SetHeadRequest.h
src/librbd/deep_copy/SnapshotCopyRequest.cc
src/librbd/deep_copy/SnapshotCopyRequest.h
src/librbd/deep_copy/SnapshotCreateRequest.cc
src/librbd/deep_copy/SnapshotCreateRequest.h
src/librbd/image/RemoveRequest.cc
src/librbd/internal.cc
src/librbd/io/ImageRequestWQ.cc
src/librbd/mirror/DemoteRequest.cc
src/librbd/operation/DisableFeaturesRequest.cc
src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc
src/test/librbd/deep_copy/test_mock_SetHeadRequest.cc
src/test/librbd/deep_copy/test_mock_SnapshotCopyRequest.cc
src/test/librbd/deep_copy/test_mock_SnapshotCreateRequest.cc
src/test/librbd/io/test_mock_ImageRequestWQ.cc
src/test/librbd/mock/MockExclusiveLock.h
src/test/librbd/test_mock_DeepCopyRequest.cc
src/test/rbd_mirror/image_deleter/test_mock_SnapshotPurgeRequest.cc
src/tools/rbd_mirror/image_deleter/SnapshotPurgeRequest.cc
src/tools/rbd_mirror/image_deleter/SnapshotPurgeRequest.h

index 0813b580c92ccae4147d1e7a1d71780c8b579d21..a522ceee246aac021697f18a1718945b87d4f2af 100644 (file)
@@ -201,14 +201,15 @@ void DeepCopyRequest<I>::send_copy_object_map() {
   ldout(m_cct, 20) << dendl;
 
   Context *finish_op_ctx = nullptr;
+  int r;
   if (m_dst_image_ctx->exclusive_lock != nullptr) {
-    finish_op_ctx = m_dst_image_ctx->exclusive_lock->start_op();
+    finish_op_ctx = m_dst_image_ctx->exclusive_lock->start_op(&r);
   }
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
     m_dst_image_ctx->snap_lock.put_read();
     m_dst_image_ctx->owner_lock.put_read();
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -235,16 +236,17 @@ void DeepCopyRequest<I>::handle_copy_object_map(int r) {
 
 template <typename I>
 void DeepCopyRequest<I>::send_refresh_object_map() {
+  int r;
   Context *finish_op_ctx = nullptr;
   {
     RWLock::RLocker owner_locker(m_dst_image_ctx->owner_lock);
     if (m_dst_image_ctx->exclusive_lock != nullptr) {
-      finish_op_ctx = m_dst_image_ctx->exclusive_lock->start_op();
+      finish_op_ctx = m_dst_image_ctx->exclusive_lock->start_op(&r);
     }
   }
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
index c2b2ef00364eeaed900bad5730f7a3d93aa032f7..ba3591fb904e63523c99de81f65b07506607aa93 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) {
   ceph_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 4940bffd9a0b24bef50065827de43c175d212dd0..43d96a852d7734c307cf53ee43569434cc236fa9 100644 (file)
@@ -227,14 +227,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;
@@ -801,7 +802,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);
@@ -1374,7 +1375,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);
@@ -1496,10 +1497,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;
@@ -1673,11 +1670,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 b363b57c8f3fd5fc849236465aa14d9a47049fe5..9f1ff8ac433434ed2fca66030821295712d2629a 100644 (file)
@@ -376,14 +376,15 @@ void ObjectCopyRequest<I>::send_write_object() {
     return;
   }
 
+  int r;
   Context *finish_op_ctx;
   {
     RWLock::RLocker owner_locker(m_dst_image_ctx->owner_lock);
-    finish_op_ctx = start_lock_op(m_dst_image_ctx->owner_lock);
+    finish_op_ctx = start_lock_op(m_dst_image_ctx->owner_lock, &r);
   }
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -392,8 +393,8 @@ void ObjectCopyRequest<I>::send_write_object() {
       finish_op_ctx->complete(0);
     });
   librados::AioCompletion *comp = create_rados_callback(ctx);
-  int r = m_dst_io_ctx.aio_operate(m_dst_oid, comp, &op, dst_snap_seq,
-                                   dst_snap_ids, nullptr);
+  r = m_dst_io_ctx.aio_operate(m_dst_oid, comp, &op, dst_snap_seq, dst_snap_ids,
+                               nullptr);
   ceph_assert(r == 0);
   comp->release();
 }
@@ -454,12 +455,13 @@ void ObjectCopyRequest<I>::send_update_object_map() {
   ldout(m_cct, 20) << "dst_snap_id=" << dst_snap_id << ", object_state="
                    << static_cast<uint32_t>(object_state) << dendl;
 
-  auto finish_op_ctx = start_lock_op(m_dst_image_ctx->owner_lock);
+  int r;
+  auto finish_op_ctx = start_lock_op(m_dst_image_ctx->owner_lock, &r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
     m_dst_image_ctx->snap_lock.put_read();
     m_dst_image_ctx->owner_lock.put_read();
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -494,12 +496,12 @@ void ObjectCopyRequest<I>::handle_update_object_map(int r) {
 }
 
 template <typename I>
-Context *ObjectCopyRequest<I>::start_lock_op(RWLock &owner_lock) {
+Context *ObjectCopyRequest<I>::start_lock_op(RWLock &owner_lock, int* r) {
   ceph_assert(m_dst_image_ctx->owner_lock.is_locked());
   if (m_dst_image_ctx->exclusive_lock == nullptr) {
     return new FunctionContext([](int r) {});
   }
-  return m_dst_image_ctx->exclusive_lock->start_op();
+  return m_dst_image_ctx->exclusive_lock->start_op(r);
 }
 
 template <typename I>
index 090f42ffc00cc9ef1192d11d6af34cc72f85024f..4b3f88e1fc6c7b550e3a0e82c69827bd8cfffb71 100644 (file)
@@ -176,7 +176,7 @@ private:
   void send_update_object_map();
   void handle_update_object_map(int r);
 
-  Context *start_lock_op(RWLock &owner_lock);
+  Context *start_lock_op(RWLock &owner_lock, int* r);
 
   uint64_t src_to_dst_object_offset(uint64_t objectno, uint64_t offset);
 
index ae110f47650bae8a38adf0617f64d66a9d0f21e9..a5cf9059a7c9cc0359e79d30e97949cf9eeb5f82 100644 (file)
@@ -57,10 +57,11 @@ void SetHeadRequest<I>::send_set_size() {
   librados::ObjectWriteOperation op;
   librbd::cls_client::set_size(&op, m_size);
 
-  auto finish_op_ctx = start_lock_op();
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -69,7 +70,7 @@ void SetHeadRequest<I>::send_set_size() {
       finish_op_ctx->complete(0);
     });
   librados::AioCompletion *comp = create_rados_callback(ctx);
-  int r = m_image_ctx->md_ctx.aio_operate(m_image_ctx->header_oid, comp, &op);
+  r = m_image_ctx->md_ctx.aio_operate(m_image_ctx->header_oid, comp, &op);
   ceph_assert(r == 0);
   comp->release();
 }
@@ -113,10 +114,12 @@ void SetHeadRequest<I>::send_detach_parent() {
   m_image_ctx->parent_lock.put_read();
 
   ldout(m_cct, 20) << dendl;
-  auto finish_op_ctx = start_lock_op();
+
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -160,10 +163,12 @@ void SetHeadRequest<I>::send_attach_parent() {
   m_image_ctx->parent_lock.put_read();
 
   ldout(m_cct, 20) << dendl;
-  auto finish_op_ctx = start_lock_op();
+
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -197,12 +202,12 @@ void SetHeadRequest<I>::handle_attach_parent(int r) {
 }
 
 template <typename I>
-Context *SetHeadRequest<I>::start_lock_op() {
+Context *SetHeadRequest<I>::start_lock_op(int* r) {
   RWLock::RLocker owner_locker(m_image_ctx->owner_lock);
   if (m_image_ctx->exclusive_lock == nullptr) {
     return new FunctionContext([](int r) {});
   }
-  return m_image_ctx->exclusive_lock->start_op();
+  return m_image_ctx->exclusive_lock->start_op(r);
 }
 
 template <typename I>
index 3b9fab7a73bb1b98da8fec47cd8561bdb75ef116..9a17c9fd01cbfe651f301fb6e4812529c63a6383 100644 (file)
@@ -74,7 +74,7 @@ private:
   void send_attach_parent();
   void handle_attach_parent(int r);
 
-  Context *start_lock_op();
+  Context *start_lock_op(int* r);
 
   void finish(int r);
 };
index 68da4e6ef1377631a5d51134dc297eb43a28d803..b8947d733f74fde938c1eaaa353f674337137c54 100644 (file)
@@ -174,10 +174,11 @@ void SnapshotCopyRequest<I>::send_snap_unprotect() {
   ldout(m_cct, 20) << "snap_name=" << m_snap_name << ", "
                    << "snap_id=" << m_prev_snap_id << dendl;
 
-  auto finish_op_ctx = start_lock_op();
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -270,10 +271,11 @@ void SnapshotCopyRequest<I>::send_snap_remove() {
            << "snap_name=" << m_snap_name << ", "
            << "snap_id=" << m_prev_snap_id << dendl;
 
-  auto finish_op_ctx = start_lock_op();
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -370,10 +372,11 @@ void SnapshotCopyRequest<I>::send_snap_create() {
                    << "snap_id=" << parent_spec.snap_id << ", "
                    << "overlap=" << parent_overlap << "]" << dendl;
 
-  Context *finish_op_ctx = start_lock_op();
+  int r;
+  Context *finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -477,10 +480,11 @@ void SnapshotCopyRequest<I>::send_snap_protect() {
   ldout(m_cct, 20) << "snap_name=" << m_snap_name << ", "
                    << "snap_id=" << m_prev_snap_id << dendl;
 
-  auto finish_op_ctx = start_lock_op();
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -571,7 +575,7 @@ void SnapshotCopyRequest<I>::send_resize_object_map() {
 
       ldout(m_cct, 20) << dendl;
 
-      auto finish_op_ctx = start_lock_op(m_dst_image_ctx->owner_lock);
+      auto finish_op_ctx = start_lock_op(m_dst_image_ctx->owner_lock, &r);
       if (finish_op_ctx != nullptr) {
         auto ctx = new FunctionContext([this, finish_op_ctx](int r) {
             handle_resize_object_map(r);
@@ -584,7 +588,6 @@ void SnapshotCopyRequest<I>::send_resize_object_map() {
       }
 
       lderr(m_cct) << "lost exclusive lock" << dendl;
-      r = -EROFS;
     }
   }
 
@@ -644,18 +647,18 @@ int SnapshotCopyRequest<I>::validate_parent(I *image_ctx,
 }
 
 template <typename I>
-Context *SnapshotCopyRequest<I>::start_lock_op() {
+Context *SnapshotCopyRequest<I>::start_lock_op(int* r) {
   RWLock::RLocker owner_locker(m_dst_image_ctx->owner_lock);
-  return start_lock_op(m_dst_image_ctx->owner_lock);
+  return start_lock_op(m_dst_image_ctx->owner_lock, r);
 }
 
 template <typename I>
-Context *SnapshotCopyRequest<I>::start_lock_op(RWLock &owner_lock) {
+Context *SnapshotCopyRequest<I>::start_lock_op(RWLock &owner_lock, int* r) {
   ceph_assert(m_dst_image_ctx->owner_lock.is_locked());
   if (m_dst_image_ctx->exclusive_lock == nullptr) {
     return new FunctionContext([](int r) {});
   }
-  return m_dst_image_ctx->exclusive_lock->start_op();
+  return m_dst_image_ctx->exclusive_lock->start_op(r);
 }
 
 template <typename I>
index 994344227608a782795fc0e6f1ec1464bc6c6825..1e4f3badba0ca8e9da8c55abbac8967223c34e3c 100644 (file)
@@ -126,8 +126,8 @@ private:
 
   int validate_parent(ImageCtxT *image_ctx, cls::rbd::ParentImageSpec *spec);
 
-  Context *start_lock_op();
-  Context *start_lock_op(RWLock &owner_lock);
+  Context *start_lock_op(int* r);
+  Context *start_lock_op(RWLock &owner_locki, int* r);
 
   void finish(int r);
 };
index 1a8800cb64658bdb8ca13afd8face7204889ef2d..0ff9c8325fa592ac32c660c50ca0653f5fe3e17a 100644 (file)
@@ -68,10 +68,11 @@ template <typename I>
 void SnapshotCreateRequest<I>::send_create_snap() {
   ldout(m_cct, 20) << "snap_name=" << m_snap_name << dendl;
 
-  auto finish_op_ctx = start_lock_op();
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -131,10 +132,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_lock_op();
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     lderr(m_cct) << "lost exclusive lock" << dendl;
-    finish(-EROFS);
+    finish(r);
     return;
   }
 
@@ -143,7 +145,7 @@ void SnapshotCreateRequest<I>::send_create_object_map() {
       finish_op_ctx->complete(0);
     });
   librados::AioCompletion *comp = create_rados_callback(ctx);
-  int r = m_dst_image_ctx->md_ctx.aio_operate(object_map_oid, comp, &op);
+  r = m_dst_image_ctx->md_ctx.aio_operate(object_map_oid, comp, &op);
   ceph_assert(r == 0);
   comp->release();
 }
@@ -163,12 +165,12 @@ void SnapshotCreateRequest<I>::handle_create_object_map(int r) {
 }
 
 template <typename I>
-Context *SnapshotCreateRequest<I>::start_lock_op() {
+Context *SnapshotCreateRequest<I>::start_lock_op(int* r) {
   RWLock::RLocker owner_locker(m_dst_image_ctx->owner_lock);
   if (m_dst_image_ctx->exclusive_lock == nullptr) {
     return new FunctionContext([](int r) {});
   }
-  return m_dst_image_ctx->exclusive_lock->start_op();
+  return m_dst_image_ctx->exclusive_lock->start_op(r);
 }
 
 template <typename I>
index 30a31dc591a38b761a21fce2a15dc4a818569eae..8c228063a24f396dbef5b51c57843b3f4baa6642 100644 (file)
@@ -82,7 +82,7 @@ private:
   void send_create_object_map();
   void handle_create_object_map(int r);
 
-  Context *start_lock_op();
+  Context *start_lock_op(int* r);
 
   void finish(int r);
 };
index f06345ab3c30ac57e89e4a93c81a4820d5ac78e5..d6edb2c9f51032d692fac8a74e4b7168ba9b9360 100644 (file)
@@ -128,7 +128,8 @@ void RemoveRequest<I>::handle_open_image(int r) {
 template<typename I>
 void RemoveRequest<I>::check_exclusive_lock() {
   if (m_image_ctx->operations_disabled) {
-    lderr(m_cct) << "image operations disabled due to unsupported op features" << dendl;
+    lderr(m_cct) << "image operations disabled due to unsupported op features"
+                 << dendl;
     send_close_image(-EROFS);
     return;
   }
index 88271739cc2e5d1e67551befae6ce92e541f6fea..534b80bb5f4c5c02b70a12e7524086c32b617d85 100644 (file)
@@ -1177,11 +1177,12 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
 
   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;
     }
 
@@ -1237,11 +1238,11 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
     }
 
     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 80ac6de363c3a1b40a19d5ac0e3544a2ddd7c7ab..393211a0dca87bb384861242349bd89a34693cc0 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"
@@ -725,7 +726,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 afb99e34b929d5bf5be8eda521819a7f4639ee02..a248ec7c427f573f36ecd714c8fa72b3bfd3f9da 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;
@@ -196,6 +197,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 bc0f4a6b17bd4ec679428f91b813300092add329..aefac1279dddbf890afd4ce4719712a4e96cbb60 100644 (file)
@@ -167,7 +167,7 @@ public:
     if ((m_src_image_ctx->features & RBD_FEATURE_EXCLUSIVE_LOCK) == 0) {
       return;
     }
-    EXPECT_CALL(mock_exclusive_lock, start_op()).WillOnce(
+    EXPECT_CALL(mock_exclusive_lock, start_op(_)).WillOnce(
       ReturnNew<FunctionContext>([](int) {}));
   }
 
index 42bf0baa3c9b6efe8fa87b82f9778f426c2296de..e417374049e37f932f597c27daf477b2ba923714 100644 (file)
@@ -110,7 +110,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 44eb4b2bb516f856448b9bd6481a7891f29a8e70..2e15b4d4d85e79ac90120de77b5fb1954282efbb 100644 (file)
@@ -148,7 +148,7 @@ public:
     if ((m_src_image_ctx->features & RBD_FEATURE_EXCLUSIVE_LOCK) == 0) {
       return;
     }
-    EXPECT_CALL(mock_exclusive_lock, start_op()).WillOnce(
+    EXPECT_CALL(mock_exclusive_lock, start_op(_)).WillOnce(
       ReturnNew<FunctionContext>([](int) {}));
   }
 
index 64d2d11d710bfd76323e65ca27ae914e0d0b96f6..57945e70cf2da9d9dd44a1c9efb1c5db2f72b8f2 100644 (file)
@@ -89,7 +89,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 b3c0042fc253ae704b19e26269588b3cb94e83f8..b15209608642a99100f8ebeb9ef6239071de934d 100644 (file)
@@ -296,6 +296,50 @@ 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;
+
+  auto mock_queued_image_request = new MockImageDispatchSpec();
+  expect_was_throttled(*mock_queued_image_request, false);
+  expect_set_throttled(*mock_queued_image_request);
+
+  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);
+
+  expect_is_write_op(*mock_queued_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_queued_image_request);
+  expect_is_refresh_request(mock_image_ctx, false);
+  expect_is_write_op(*mock_queued_image_request, true);
+  expect_dequeue(mock_image_request_wq, mock_queued_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_queued_image_request, -EBLACKLISTED);
+  expect_is_write_op(*mock_queued_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 31de7c67aea4e0a70c470f499adce73a9599224c..fd45e9f0e5d4f25cf8426d68f6bbf10c383c0315 100644 (file)
@@ -170,7 +170,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 daff8b33e3f2d79d44c54db3efc47c7caa7aa9e9..35850d3a39aab7171df52c093bc041558b7eea3b 100644 (file)
@@ -139,9 +139,10 @@ public:
   }
 
   void expect_start_op(librbd::MockTestImageCtx &mock_image_ctx, bool success) {
-    EXPECT_CALL(*mock_image_ctx.exclusive_lock, start_op())
-      .WillOnce(Invoke([success]() {
+    EXPECT_CALL(*mock_image_ctx.exclusive_lock, start_op(_))
+      .WillOnce(Invoke([success](int* r) {
                   if (!success) {
+                    *r = -EROFS;
                     return static_cast<FunctionContext*>(nullptr);
                   }
                   return new FunctionContext([](int r) {});
index 4d1c3737d61a4ed96cf66287ddbe17ff62347555..a0e9fd908976d01b1b34690f933add658635667d 100644 (file)
@@ -151,10 +151,10 @@ void SnapshotPurgeRequest<I>::snap_unprotect() {
            << "snap_namespace=" << m_snap_namespace << ", "
            << "snap_name=" << m_snap_name << dendl;
 
-  auto finish_op_ctx = start_lock_op();
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     derr << "lost exclusive lock" << dendl;
-    m_ret_val = -EROFS;
+    m_ret_val = r;
     close_image();
     return;
   }
@@ -205,10 +205,11 @@ void SnapshotPurgeRequest<I>::snap_remove() {
            << "snap_namespace=" << m_snap_namespace << ", "
            << "snap_name=" << m_snap_name << dendl;
 
-  auto finish_op_ctx = start_lock_op();
+  int r;
+  auto finish_op_ctx = start_lock_op(&r);
   if (finish_op_ctx == nullptr) {
     derr << "lost exclusive lock" << dendl;
-    m_ret_val = -EROFS;
+    m_ret_val = r;
     close_image();
     return;
   }
@@ -277,9 +278,9 @@ void SnapshotPurgeRequest<I>::finish(int r) {
 }
 
 template <typename I>
-Context *SnapshotPurgeRequest<I>::start_lock_op() {
+Context *SnapshotPurgeRequest<I>::start_lock_op(int* r) {
   RWLock::RLocker owner_locker(m_image_ctx->owner_lock);
-  return m_image_ctx->exclusive_lock->start_op();
+  return m_image_ctx->exclusive_lock->start_op(r);
 }
 
 } // namespace image_deleter
index 59a13cb8f448252c5deaf468efed923e33a1f08f..b8b635fe765ae5f92f6edc198f26839baf8fc0b9 100644 (file)
@@ -90,7 +90,7 @@ private:
 
   void finish(int r);
 
-  Context *start_lock_op();
+  Context *start_lock_op(int* r);
 
 };