]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use counter to track exclusive lock block/unblock requests
authorMykola Golub <mgolub@mirantis.com>
Tue, 20 Sep 2016 13:45:41 +0000 (16:45 +0300)
committerMykola Golub <mgolub@mirantis.com>
Wed, 28 Sep 2016 12:17:19 +0000 (15:17 +0300)
It's possible the watch/notify message is duplicated resulting in two
concurrent block_requests() call.

Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/librbd/ExclusiveLock.cc
src/librbd/ExclusiveLock.h

index 6b3013c582243188d40065f6b78196e665c5702c..1d6b44bf8e11b4f76fd16e0e76ef1af0f2b76642 100644 (file)
@@ -82,7 +82,7 @@ bool ExclusiveLock<I>::accept_requests(int *ret_val) const {
   Mutex::Locker locker(m_lock);
 
   bool accept_requests = (!is_shutdown() && m_state == STATE_LOCKED &&
-                          !m_request_blocked);
+                          m_request_blocked_count == 0);
   *ret_val = m_request_blocked_ret_val;
 
   ldout(m_image_ctx.cct, 20) << this << " " << __func__ << "="
@@ -93,9 +93,10 @@ bool ExclusiveLock<I>::accept_requests(int *ret_val) const {
 template <typename I>
 void ExclusiveLock<I>::block_requests(int r) {
   Mutex::Locker locker(m_lock);
-  assert(!m_request_blocked);
-  m_request_blocked = true;
-  m_request_blocked_ret_val = r;
+  m_request_blocked_count++;
+  if (m_request_blocked_ret_val == 0) {
+    m_request_blocked_ret_val = r;
+  }
 
   ldout(m_image_ctx.cct, 20) << this << " " << __func__ << dendl;
 }
@@ -103,9 +104,11 @@ void ExclusiveLock<I>::block_requests(int r) {
 template <typename I>
 void ExclusiveLock<I>::unblock_requests() {
   Mutex::Locker locker(m_lock);
-  assert(m_request_blocked);
-  m_request_blocked = false;
-  m_request_blocked_ret_val = 0;
+  assert(m_request_blocked_count > 0);
+  m_request_blocked_count--;
+  if (m_request_blocked_count == 0) {
+    m_request_blocked_ret_val = 0;
+  }
 
   ldout(m_image_ctx.cct, 20) << this << " " << __func__ << dendl;
 }
index 5543bbb01f5798811686a8871908895c18485751..93ddd903e10191f91cdae475c2a31b6f8c8094ac 100644 (file)
@@ -151,7 +151,7 @@ private:
 
   ActionsContexts m_actions_contexts;
 
-  bool m_request_blocked = false;
+  uint32_t m_request_blocked_count = 0;
   int m_request_blocked_ret_val = 0;
 
   std::string encode_lock_cookie() const;