From: Jason Dillaman Date: Thu, 7 May 2015 17:31:50 +0000 (-0400) Subject: tests: verify that librbd will periodically resend lock request X-Git-Tag: v0.94.4~76^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7b21ccba7c2885027b1d345baaad08a978fbc72f;p=ceph.git tests: verify that librbd will periodically resend lock request Signed-off-by: Jason Dillaman (cherry picked from commit d2a1c226ab3f7e202f62896f0c80c4cf3607cdaf) --- diff --git a/src/test/librbd/test_ImageWatcher.cc b/src/test/librbd/test_ImageWatcher.cc index 55f0236be4a..adf087eb78c 100644 --- a/src/test/librbd/test_ImageWatcher.cc +++ b/src/test/librbd/test_ImageWatcher.cc @@ -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(