]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: block RPC requests while updating features 8869/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 28 Apr 2016 16:48:59 +0000 (12:48 -0400)
committerAbhishek Varshney <abhishek.varshney@flipkart.com>
Mon, 2 May 2016 06:42:50 +0000 (12:12 +0530)
Disabling the journal and object map require acquiring the exclusive
lock locally.  We don't want to start executing long-running ops
for this quick process.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit db7aaff0f6d7a57e2b36d22b609f915f9b2b3893)

src/librbd/ExclusiveLock.cc
src/librbd/ExclusiveLock.h
src/librbd/internal.cc

index 01043e5dcfca6d3f81301af9b0d9af47ed1ce79a..932fe042d3e79ed0e31e36bc665130e61dbb3b5d 100644 (file)
@@ -78,12 +78,32 @@ template <typename I>
 bool ExclusiveLock<I>::accept_requests() const {
   Mutex::Locker locker(m_lock);
 
-  bool accept_requests = (!is_shutdown() && m_state == STATE_LOCKED);
+  bool accept_requests = (!is_shutdown() && m_state == STATE_LOCKED &&
+                          m_request_blockers == 0);
   ldout(m_image_ctx.cct, 20) << this << " " << __func__ << "="
                              << accept_requests << dendl;
   return accept_requests;
 }
 
+template <typename I>
+void ExclusiveLock<I>::block_requests() {
+  Mutex::Locker locker(m_lock);
+  ++m_request_blockers;
+
+  ldout(m_image_ctx.cct, 20) << this << " " << __func__ << "="
+                             << m_request_blockers << dendl;
+}
+
+template <typename I>
+void ExclusiveLock<I>::unblock_requests() {
+  Mutex::Locker locker(m_lock);
+  assert(m_request_blockers > 0);
+  --m_request_blockers;
+
+  ldout(m_image_ctx.cct, 20) << this << " " << __func__ << "="
+                             << m_request_blockers << dendl;
+}
+
 template <typename I>
 void ExclusiveLock<I>::init(uint64_t features, Context *on_init) {
   assert(m_image_ctx.owner_lock.is_locked());
index e2e14160a9cafb07c327c3ebb61641e449ad0c23..6268c8080be11af3366e18c760f107442fe4013f 100644 (file)
@@ -32,6 +32,9 @@ public:
   bool is_lock_owner() const;
   bool accept_requests() const;
 
+  void block_requests();
+  void unblock_requests();
+
   void init(uint64_t features, Context *on_init);
   void shut_down(Context *on_shutdown);
 
@@ -127,6 +130,8 @@ private:
 
   ActionsContexts m_actions_contexts;
 
+  uint32_t m_request_blockers = 0;
+
   std::string encode_lock_cookie() const;
 
   bool is_transition_state() const;
index 3ac77935baffeb7b1a78923e7bc5f02cc10d0398..81328f970e6cd384e3855312f8114bfdd14b082d 100644 (file)
@@ -1590,8 +1590,10 @@ remove_mirroring_image:
     }
 
     RWLock::RLocker owner_locker(ictx->owner_lock);
-    RWLock::WLocker md_locker(ictx->md_lock);
-    r = ictx->flush();
+    r = ictx->aio_work_queue->block_writes();
+    BOOST_SCOPE_EXIT_ALL( (ictx) ) {
+      ictx->aio_work_queue->unblock_writes();
+    };
     if (r < 0) {
       return r;
     }
@@ -1607,6 +1609,17 @@ remove_mirroring_image:
       return -EINVAL;
     }
 
+    // avoid accepting new requests from peers while we manipulate
+    // the image features
+    if (ictx->exclusive_lock != nullptr) {
+      ictx->exclusive_lock->block_requests();
+    }
+    BOOST_SCOPE_EXIT_ALL( (ictx) ) {
+      if (ictx->exclusive_lock != nullptr) {
+        ictx->exclusive_lock->unblock_requests();
+      }
+    };
+
     // if disabling features w/ exclusive lock supported, we need to
     // acquire the lock to temporarily block IO against the image
     if (ictx->exclusive_lock != nullptr && !enabled) {