]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: mark exclusive lock as released after journal is closed 9905/head
authorJason Dillaman <dillaman@redhat.com>
Thu, 23 Jun 2016 17:34:56 +0000 (13:34 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 23 Jun 2016 17:34:56 +0000 (13:34 -0400)
Fixes: http://tracker.ceph.com/issues/16450
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/exclusive_lock/ReleaseRequest.cc
src/test/librbd/exclusive_lock/test_mock_ReleaseRequest.cc

index 0583c266d03891cb45aba34359bf8a0b66e0e19c..e122c8ad2c5831706d55f52925746002125c50e6 100644 (file)
@@ -103,12 +103,6 @@ Context *ReleaseRequest<I>::handle_block_writes(int *ret_val) {
     return m_on_finish;
   }
 
-  if (m_on_releasing != nullptr) {
-    // alert caller that we no longer own the exclusive lock
-    m_on_releasing->complete(0);
-    m_on_releasing = nullptr;
-  }
-
   send_flush_notifies();
   return nullptr;
 }
@@ -211,6 +205,12 @@ void ReleaseRequest<I>::send_unlock() {
   CephContext *cct = m_image_ctx.cct;
   ldout(cct, 10) << __func__ << dendl;
 
+  if (m_on_releasing != nullptr) {
+    // alert caller that we no longer own the exclusive lock
+    m_on_releasing->complete(0);
+    m_on_releasing = nullptr;
+  }
+
   librados::ObjectWriteOperation op;
   rados::cls::lock::unlock(&op, RBD_LOCK_NAME, m_cookie);
 
index 2ed8b8ef9a54dd7178612ffde9927b15237f42c4..99ae094045bd0fae85fc28735f23f4c15910c66d 100644 (file)
@@ -19,6 +19,15 @@ template class librbd::exclusive_lock::ReleaseRequest<librbd::MockImageCtx>;
 namespace librbd {
 namespace exclusive_lock {
 
+namespace {
+
+struct MockContext : public Context {
+  MOCK_METHOD1(complete, void(int));
+  MOCK_METHOD1(finish, void(int));
+};
+
+} // anonymous namespace
+
 using ::testing::_;
 using ::testing::InSequence;
 using ::testing::Return;
@@ -30,6 +39,10 @@ class TestMockExclusiveLockReleaseRequest : public TestMockFixture {
 public:
   typedef ReleaseRequest<MockImageCtx> MockReleaseRequest;
 
+  void expect_complete_context(MockContext &mock_context, int r) {
+    EXPECT_CALL(mock_context, complete(r));
+  }
+
   void expect_test_features(MockImageCtx &mock_image_ctx, uint64_t features,
                             bool enabled) {
     EXPECT_CALL(mock_image_ctx, test_features(features))
@@ -105,15 +118,16 @@ TEST_F(TestMockExclusiveLockReleaseRequest, Success) {
   mock_image_ctx.object_map = mock_object_map;
   expect_close_object_map(mock_image_ctx, *mock_object_map);
 
+  MockContext mock_releasing_ctx;
+  expect_complete_context(mock_releasing_ctx, 0);
   expect_unlock(mock_image_ctx, 0);
 
-  C_SaferCond release_ctx;
   C_SaferCond ctx;
   MockReleaseRequest *req = MockReleaseRequest::create(mock_image_ctx,
                                                        TEST_COOKIE,
-                                                       &release_ctx, &ctx);
+                                                       &mock_releasing_ctx,
+                                                       &ctx);
   req->send();
-  ASSERT_EQ(0, release_ctx.wait());
   ASSERT_EQ(0, ctx.wait());
 }