From: Jason Dillaman Date: Tue, 10 Apr 2018 15:47:40 +0000 (-0400) Subject: test/librados_test_stub: aio_watch/aio_unwatch should be asynchronous X-Git-Tag: v13.1.0~244^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=35d456d4e0831c8925fdff863eddeee4718be6e2;p=ceph.git test/librados_test_stub: aio_watch/aio_unwatch should be asynchronous Signed-off-by: Jason Dillaman --- diff --git a/src/test/librados_test_stub/TestIoCtxImpl.cc b/src/test/librados_test_stub/TestIoCtxImpl.cc index 6cfde3cdcac..54c558ae590 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestIoCtxImpl.cc @@ -136,7 +136,7 @@ int TestIoCtxImpl::aio_watch(const std::string& o, AioCompletionImpl *c, m_client->get_aio_finisher()->queue(ctx, -EBLACKLISTED); } else { m_client->get_watch_notify()->aio_watch(m_client, o, get_instance_id(), - handle, watch_ctx, ctx); + handle, nullptr, watch_ctx, ctx); } return 0; } diff --git a/src/test/librados_test_stub/TestWatchNotify.cc b/src/test/librados_test_stub/TestWatchNotify.cc index 492c5a8dbc8..a2f2f69e24a 100644 --- a/src/test/librados_test_stub/TestWatchNotify.cc +++ b/src/test/librados_test_stub/TestWatchNotify.cc @@ -61,19 +61,41 @@ void TestWatchNotify::aio_flush(TestRadosClient *rados_client, rados_client->get_aio_finisher()->queue(on_finish); } +int TestWatchNotify::watch(TestRadosClient *rados_client, + const std::string& o, uint64_t gid, + uint64_t *handle, librados::WatchCtx *ctx, + librados::WatchCtx2 *ctx2) { + C_SaferCond cond; + aio_watch(rados_client, o, gid, handle, ctx, ctx2, &cond); + return cond.wait(); +} + void TestWatchNotify::aio_watch(TestRadosClient *rados_client, const std::string& o, uint64_t gid, uint64_t *handle, - librados::WatchCtx2 *watch_ctx, + librados::WatchCtx *watch_ctx, + librados::WatchCtx2 *watch_ctx2, Context *on_finish) { - int r = watch(rados_client, o, gid, handle, nullptr, watch_ctx); - rados_client->get_aio_finisher()->queue(on_finish, r); + auto ctx = new FunctionContext([=](int) { + execute_watch(rados_client, o, gid, handle, watch_ctx, watch_ctx2, + on_finish); + }); + rados_client->get_aio_finisher()->queue(ctx); +} + +int TestWatchNotify::unwatch(TestRadosClient *rados_client, + uint64_t handle) { + C_SaferCond ctx; + aio_unwatch(rados_client, handle, &ctx); + return ctx.wait(); } void TestWatchNotify::aio_unwatch(TestRadosClient *rados_client, uint64_t handle, Context *on_finish) { - unwatch(rados_client, handle); - rados_client->get_aio_finisher()->queue(on_finish); + auto ctx = new FunctionContext([this, rados_client, handle, on_finish](int) { + execute_unwatch(rados_client, handle, on_finish); + }); + rados_client->get_aio_finisher()->queue(ctx); } void TestWatchNotify::aio_notify(TestRadosClient *rados_client, @@ -128,13 +150,14 @@ void TestWatchNotify::notify_ack(TestRadosClient *rados_client, finish_notify(rados_client, o, notify_id); } -int TestWatchNotify::watch(TestRadosClient *rados_client, - const std::string& o, uint64_t gid, - uint64_t *handle, librados::WatchCtx *ctx, - librados::WatchCtx2 *ctx2) { +void TestWatchNotify::execute_watch(TestRadosClient *rados_client, + const std::string& o, uint64_t gid, + uint64_t *handle, librados::WatchCtx *ctx, + librados::WatchCtx2 *ctx2, + Context* on_finish) { CephContext *cct = rados_client->cct(); - Mutex::Locker lock(m_lock); + m_lock.Lock(); SharedWatcher watcher = get_watcher(o); WatchHandle watch_handle; @@ -151,29 +174,33 @@ int TestWatchNotify::watch(TestRadosClient *rados_client, ldout(cct, 20) << "oid=" << o << ", gid=" << gid << ": handle=" << *handle << dendl; - return 0; + m_lock.Unlock(); + + on_finish->complete(0); } -int TestWatchNotify::unwatch(TestRadosClient *rados_client, - uint64_t handle) { +void TestWatchNotify::execute_unwatch(TestRadosClient *rados_client, + uint64_t handle, Context* on_finish) { CephContext *cct = rados_client->cct(); ldout(cct, 20) << "handle=" << handle << dendl; - Mutex::Locker locker(m_lock); - for (FileWatchers::iterator it = m_file_watchers.begin(); - it != m_file_watchers.end(); ++it) { - SharedWatcher watcher = it->second; - - WatchHandles::iterator w_it = watcher->watch_handles.find(handle); - if (w_it != watcher->watch_handles.end()) { - watcher->watch_handles.erase(w_it); - if (watcher->watch_handles.empty() && watcher->notify_handles.empty()) { - m_file_watchers.erase(it); + { + Mutex::Locker locker(m_lock); + for (FileWatchers::iterator it = m_file_watchers.begin(); + it != m_file_watchers.end(); ++it) { + SharedWatcher watcher = it->second; + + WatchHandles::iterator w_it = watcher->watch_handles.find(handle); + if (w_it != watcher->watch_handles.end()) { + watcher->watch_handles.erase(w_it); + if (watcher->watch_handles.empty() && watcher->notify_handles.empty()) { + m_file_watchers.erase(it); + } + break; } - break; } } - return 0; + on_finish->complete(0); } TestWatchNotify::SharedWatcher TestWatchNotify::get_watcher( diff --git a/src/test/librados_test_stub/TestWatchNotify.h b/src/test/librados_test_stub/TestWatchNotify.h index baf56cb7e1a..04d37c2358d 100644 --- a/src/test/librados_test_stub/TestWatchNotify.h +++ b/src/test/librados_test_stub/TestWatchNotify.h @@ -60,8 +60,8 @@ public: void aio_flush(TestRadosClient *rados_client, Context *on_finish); void aio_watch(TestRadosClient *rados_client, const std::string& o, - uint64_t gid, uint64_t *handle, librados::WatchCtx2 *watch_ctx, - Context *on_finish); + uint64_t gid, uint64_t *handle, librados::WatchCtx *watch_ctx, + librados::WatchCtx2 *watch_ctx2, Context *on_finish); void aio_unwatch(TestRadosClient *rados_client, uint64_t handle, Context *on_finish); void aio_notify(TestRadosClient *rados_client, const std::string& oid, @@ -96,6 +96,14 @@ private: SharedWatcher get_watcher(const std::string& oid); + void execute_watch(TestRadosClient *rados_client, const std::string& o, + uint64_t gid, uint64_t *handle, + librados::WatchCtx *watch_ctx, + librados::WatchCtx2 *watch_ctx2, + Context *on_finish); + void execute_unwatch(TestRadosClient *rados_client, uint64_t handle, + Context *on_finish); + void execute_notify(TestRadosClient *rados_client, const std::string &oid, bufferlist &bl, uint64_t notify_id); void ack_notify(TestRadosClient *rados_client, const std::string &oid,