From: Jason Dillaman Date: Thu, 30 Apr 2015 17:36:26 +0000 (-0400) Subject: librados_test_stub: add support for flushing watches X-Git-Tag: v9.0.2~46^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6e400b9049ede5870e40e4dd2cb41874550eac25;p=ceph.git librados_test_stub: add support for flushing watches Signed-off-by: Jason Dillaman --- diff --git a/src/test/librados_test_stub/TestMemRadosClient.cc b/src/test/librados_test_stub/TestMemRadosClient.cc index 73abfa9a0898..b89f4eb6fed2 100644 --- a/src/test/librados_test_stub/TestMemRadosClient.cc +++ b/src/test/librados_test_stub/TestMemRadosClient.cc @@ -116,6 +116,7 @@ int TestMemRadosClient::pool_reverse_lookup(int64_t id, std::string *name) { } int TestMemRadosClient::watch_flush() { + get_watch_notify().flush(); return 0; } diff --git a/src/test/librados_test_stub/TestWatchNotify.cc b/src/test/librados_test_stub/TestWatchNotify.cc index 6fd77483bf27..d51b893cf8d9 100644 --- a/src/test/librados_test_stub/TestWatchNotify.cc +++ b/src/test/librados_test_stub/TestWatchNotify.cc @@ -11,7 +11,8 @@ namespace librados { TestWatchNotify::TestWatchNotify(CephContext *cct) : m_cct(cct), m_finisher(new Finisher(cct)), m_handle(), m_notify_id(), - m_file_watcher_lock("librados::TestWatchNotify::m_file_watcher_lock") { + m_file_watcher_lock("librados::TestWatchNotify::m_file_watcher_lock"), + m_pending_notifies(0) { m_cct->get(); m_finisher->start(); } @@ -31,6 +32,13 @@ TestWatchNotify::Watcher::Watcher() : lock("TestWatchNotify::Watcher::lock") { } +void TestWatchNotify::flush() { + Mutex::Locker file_watcher_locker(m_file_watcher_lock); + while (m_pending_notifies > 0) { + m_file_watcher_cond.Wait(m_file_watcher_lock); + } +} + int TestWatchNotify::list_watchers(const std::string& o, std::list *out_watchers) { SharedWatcher watcher = get_watcher(o); @@ -61,6 +69,7 @@ int TestWatchNotify::notify(const std::string& oid, bufferlist& bl, RWLock::WLocker l(watcher->lock); { Mutex::Locker l2(m_file_watcher_lock); + ++m_pending_notifies; uint64_t notify_id = ++m_notify_id; SharedNotifyHandle notify_handle(new NotifyHandle()); @@ -203,6 +212,13 @@ void TestWatchNotify::execute_notify(const std::string &oid, Mutex::Locker l3(*lock); *done = true; cond->Signal(); + + { + Mutex::Locker file_watcher_locker(m_file_watcher_lock); + if (--m_pending_notifies == 0) { + m_file_watcher_cond.Signal(); + } + } } } // namespace librados diff --git a/src/test/librados_test_stub/TestWatchNotify.h b/src/test/librados_test_stub/TestWatchNotify.h index f73ee3a793e8..4912ef27444a 100644 --- a/src/test/librados_test_stub/TestWatchNotify.h +++ b/src/test/librados_test_stub/TestWatchNotify.h @@ -53,6 +53,7 @@ public: TestWatchNotify(CephContext *cct); ~TestWatchNotify(); + void flush(); int list_watchers(const std::string& o, std::list *out_watchers); int notify(const std::string& o, bufferlist& bl, @@ -74,6 +75,9 @@ private: uint64_t m_notify_id; Mutex m_file_watcher_lock; + Cond m_file_watcher_cond; + uint64_t m_pending_notifies; + FileWatchers m_file_watchers; SharedWatcher get_watcher(const std::string& oid);