]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tests: verify that librbd will periodically resend lock request
authorJason Dillaman <dillaman@redhat.com>
Thu, 7 May 2015 17:31:50 +0000 (13:31 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 29 Jul 2015 17:29:54 +0000 (13:29 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit d2a1c226ab3f7e202f62896f0c80c4cf3607cdaf)

src/test/librbd/test_ImageWatcher.cc

index 55f0236be4a28cf7e1772f2d7595f62b8fcb5690..adf087eb78c1ace08421b45ce68a1cab89d1ec77 100644 (file)
@@ -192,7 +192,8 @@ public:
     Mutex::Locker l(m_callback_lock);
     int r = 0;
     while (!m_aio_completions.empty() &&
-          m_aio_completion_restarts < m_expected_aio_restarts) {
+           (m_expected_aio_restarts == 0 ||
+           m_aio_completion_restarts < m_expected_aio_restarts)) {
       r = m_callback_cond.WaitInterval(ictx.cct, m_callback_lock,
                                       utime_t(10, 0));
       if (r != 0) {
@@ -580,6 +581,7 @@ TEST_F(TestImageWatcher, RequestLockTimedOut) {
   m_notify_acks = boost::assign::list_of(
     std::make_pair(NOTIFY_OP_REQUEST_LOCK, bufferlist()));
 
+  m_expected_aio_restarts = 1;
   {
     RWLock::WLocker l(ictx->owner_lock);
     ictx->image_watcher->request_lock(
@@ -595,6 +597,45 @@ TEST_F(TestImageWatcher, RequestLockTimedOut) {
   ASSERT_TRUE(wait_for_aio_completions(*ictx));
 }
 
+TEST_F(TestImageWatcher, RequestLockIgnored) {
+  REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
+
+  librbd::ImageCtx *ictx;
+  ASSERT_EQ(0, open_image(m_image_name, &ictx));
+  ASSERT_EQ(0, register_image_watch(*ictx));
+  ASSERT_EQ(0, lock_image(*ictx, LOCK_EXCLUSIVE,
+                         "auto " + stringify(m_watch_ctx->get_handle())));
+
+  m_notify_acks = boost::assign::list_of(
+    std::make_pair(NOTIFY_OP_REQUEST_LOCK, create_response_message(0)));
+
+  int orig_notify_timeout = ictx->cct->_conf->client_notify_timeout;
+  ictx->cct->_conf->set_val("client_notify_timeout", "0");
+  BOOST_SCOPE_EXIT( (ictx)(orig_notify_timeout) ) {
+    ictx->cct->_conf->set_val("client_notify_timeout",
+                              stringify(orig_notify_timeout));
+  } BOOST_SCOPE_EXIT_END;
+
+  {
+    RWLock::WLocker l(ictx->owner_lock);
+    ictx->image_watcher->request_lock(
+      boost::bind(&TestImageWatcher::handle_restart_aio, this, ictx, _1),
+      create_aio_completion(*ictx));
+  }
+
+  ASSERT_TRUE(wait_for_notifies(*ictx));
+  NotifyOps expected_notify_ops;
+  expected_notify_ops += NOTIFY_OP_REQUEST_LOCK;
+  ASSERT_EQ(expected_notify_ops, m_notifies);
+
+  // after the request times out -- it will be resent
+  ASSERT_TRUE(wait_for_notifies(*ictx));
+  ASSERT_EQ(expected_notify_ops, m_notifies);
+
+  ASSERT_EQ(0, unlock_image());
+  ASSERT_TRUE(wait_for_aio_completions(*ictx));
+}
+
 TEST_F(TestImageWatcher, RequestLockTryLockRace) {
   REQUIRE_FEATURE(RBD_FEATURE_EXCLUSIVE_LOCK);
 
@@ -607,6 +648,7 @@ TEST_F(TestImageWatcher, RequestLockTryLockRace) {
   m_notify_acks = boost::assign::list_of(
     std::make_pair(NOTIFY_OP_REQUEST_LOCK, create_response_message(0)));
 
+  m_expected_aio_restarts = 1;
   {
     RWLock::WLocker l(ictx->owner_lock);
     ictx->image_watcher->request_lock(
@@ -642,6 +684,7 @@ TEST_F(TestImageWatcher, RequestLockPreTryLockFailed) {
   ASSERT_EQ(0, open_image(m_image_name, &ictx));
   ASSERT_EQ(0, lock_image(*ictx, LOCK_SHARED, "manually 1234"));
 
+  m_expected_aio_restarts = 1;
   {
     RWLock::WLocker l(ictx->owner_lock);
     ictx->image_watcher->request_lock(