diff options
author | Jason Dillaman <dillaman@redhat.com> | 2015-06-25 00:35:58 +0200 |
---|---|---|
committer | Jason Dillaman <dillaman@redhat.com> | 2015-11-06 02:42:40 +0100 |
commit | 8270170f6099189452dfe1df25eed3b77a79c38e (patch) | |
tree | e2390bb299d93cb3d3acee254df15a8996fbc9b5 | |
parent | tests: new test for librados AIO notify API (diff) | |
download | ceph-8270170f6099189452dfe1df25eed3b77a79c38e.tar.xz ceph-8270170f6099189452dfe1df25eed3b77a79c38e.zip |
librados_test_stub: add support for new aio_notify API
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
-rw-r--r-- | src/test/librados_test_stub/LibradosTestStub.cc | 7 | ||||
-rw-r--r-- | src/test/librados_test_stub/TestIoCtxImpl.cc | 15 | ||||
-rw-r--r-- | src/test/librados_test_stub/TestIoCtxImpl.h | 14 | ||||
-rw-r--r-- | src/test/librados_test_stub/TestRadosClient.cc | 4 | ||||
-rw-r--r-- | src/test/librados_test_stub/TestRadosClient.h | 2 | ||||
-rw-r--r-- | src/test/librados_test_stub/TestWatchNotify.cc | 68 | ||||
-rw-r--r-- | src/test/librados_test_stub/TestWatchNotify.h | 4 |
7 files changed, 73 insertions, 41 deletions
diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index 2a0006e662d..80690897af1 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -354,6 +354,13 @@ int IoCtx::aio_flush_async(AioCompletion *c) { return 0; } +int IoCtx::aio_notify(const std::string& oid, AioCompletion *c, bufferlist& bl, + uint64_t timeout_ms, bufferlist *pbl) { + TestIoCtxImpl *ctx = reinterpret_cast<TestIoCtxImpl*>(io_ctx_impl); + ctx->aio_notify(oid, c->pc, bl, timeout_ms, pbl); + return 0; +} + int IoCtx::aio_operate(const std::string& oid, AioCompletion *c, ObjectReadOperation *op, bufferlist *pbl) { return aio_operate(oid, c, op, 0, pbl); diff --git a/src/test/librados_test_stub/TestIoCtxImpl.cc b/src/test/librados_test_stub/TestIoCtxImpl.cc index 30c1e13a381..ebb5d745232 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestIoCtxImpl.cc @@ -90,6 +90,15 @@ void TestIoCtxImpl::aio_flush_async(AioCompletionImpl *c) { m_client->flush_aio_operations(c); } +void TestIoCtxImpl::aio_notify(const std::string& oid, AioCompletionImpl *c, + bufferlist& bl, uint64_t timeout_ms, + bufferlist *pbl) { + m_pending_ops.inc(); + c->get(); + C_AioNotify *ctx = new C_AioNotify(this, c); + m_client->get_watch_notify().aio_notify(oid, bl, timeout_ms, pbl, ctx); +} + int TestIoCtxImpl::aio_operate(const std::string& oid, TestObjectOperationImpl &ops, AioCompletionImpl *c, SnapContext *snap_context, int flags) { @@ -274,4 +283,10 @@ int TestIoCtxImpl::execute_aio_operations(const std::string& oid, return ret; } +void TestIoCtxImpl::handle_aio_notify_complete(AioCompletionImpl *c, int r) { + m_pending_ops.dec(); + + m_client->finish_aio_completion(c, r); +} + } // namespace librados diff --git a/src/test/librados_test_stub/TestIoCtxImpl.h b/src/test/librados_test_stub/TestIoCtxImpl.h index 450ee59d713..4d924f49883 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.h +++ b/src/test/librados_test_stub/TestIoCtxImpl.h @@ -6,6 +6,7 @@ #include "include/rados/librados.hpp" #include "include/atomic.h" +#include "include/Context.h" #include "common/snap_types.h" #include <boost/function.hpp> #include <list> @@ -71,6 +72,8 @@ public: virtual int aio_flush(); virtual void aio_flush_async(AioCompletionImpl *c); + virtual void aio_notify(const std::string& oid, AioCompletionImpl *c, + bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl); virtual int aio_operate(const std::string& oid, TestObjectOperationImpl &ops, AioCompletionImpl *c, SnapContext *snap_context, int flags); @@ -150,6 +153,16 @@ protected: bufferlist *pbl, const SnapContext &snapc); private: + struct C_AioNotify : public Context { + TestIoCtxImpl *io_ctx; + AioCompletionImpl *aio_comp; + C_AioNotify(TestIoCtxImpl *_io_ctx, AioCompletionImpl *_aio_comp) + : io_ctx(_io_ctx), aio_comp(_aio_comp) { + } + virtual void finish(int r) { + io_ctx->handle_aio_notify_complete(aio_comp, r); + } + }; TestRadosClient *m_client; int64_t m_pool_id; @@ -158,6 +171,7 @@ private: SnapContext m_snapc; atomic_t m_refcount; + void handle_aio_notify_complete(AioCompletionImpl *aio_comp, int r); }; } // namespace librados diff --git a/src/test/librados_test_stub/TestRadosClient.cc b/src/test/librados_test_stub/TestRadosClient.cc index 46437ac8657..1a9792c6e02 100644 --- a/src/test/librados_test_stub/TestRadosClient.cc +++ b/src/test/librados_test_stub/TestRadosClient.cc @@ -221,6 +221,10 @@ void TestRadosClient::flush_aio_operations(AioCompletionImpl *c) { } } +void TestRadosClient::finish_aio_completion(AioCompletionImpl *c, int r) { + librados::finish_aio_completion(c, r); +} + Finisher *TestRadosClient::get_finisher(const std::string &oid) { std::size_t h = m_hash(oid); return m_finishers[h % m_finishers.size()]; diff --git a/src/test/librados_test_stub/TestRadosClient.h b/src/test/librados_test_stub/TestRadosClient.h index ad0cf676dd0..d3c20349e74 100644 --- a/src/test/librados_test_stub/TestRadosClient.h +++ b/src/test/librados_test_stub/TestRadosClient.h @@ -99,6 +99,8 @@ public: void flush_aio_operations(); void flush_aio_operations(AioCompletionImpl *c); + void finish_aio_completion(AioCompletionImpl *c, int r); + protected: virtual ~TestRadosClient(); diff --git a/src/test/librados_test_stub/TestWatchNotify.cc b/src/test/librados_test_stub/TestWatchNotify.cc index 14a43bc58cb..ef8f5378fae 100644 --- a/src/test/librados_test_stub/TestWatchNotify.cc +++ b/src/test/librados_test_stub/TestWatchNotify.cc @@ -58,38 +58,31 @@ int TestWatchNotify::list_watchers(const std::string& o, return 0; } +void TestWatchNotify::aio_notify(const std::string& oid, bufferlist& bl, + uint64_t timeout_ms, bufferlist *pbl, + Context *on_notify) { + SharedWatcher watcher = get_watcher(oid); + RWLock::WLocker watcher_locker(watcher->lock); + Mutex::Locker file_watcher_lock(m_file_watcher_lock); + ++m_pending_notifies; + uint64_t notify_id = ++m_notify_id; + + SharedNotifyHandle notify_handle(new NotifyHandle()); + notify_handle->pbl = pbl; + + watcher->notify_handles[notify_id] = notify_handle; + + FunctionContext *ctx = new FunctionContext( + boost::bind(&TestWatchNotify::execute_notify, this, + oid, bl, notify_id, on_notify)); + m_finisher->queue(ctx); +} + int TestWatchNotify::notify(const std::string& oid, bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl) { - Mutex lock("TestRadosClient::watcher_notify::lock"); - Cond cond; - bool done = false; - - { - SharedWatcher watcher = get_watcher(oid); - 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()); - notify_handle->pbl = pbl; - - watcher->notify_handles[notify_id] = notify_handle; - - FunctionContext *ctx = new FunctionContext( - boost::bind(&TestWatchNotify::execute_notify, this, - oid, bl, notify_id, &lock, &cond, &done)); - m_finisher->queue(ctx); - } - } - - lock.Lock(); - while (!done) { - cond.Wait(lock); - } - lock.Unlock(); - return 0; + C_SaferCond cond; + aio_notify(oid, bl, timeout_ms, pbl, &cond); + return cond.wait(); } void TestWatchNotify::notify_ack(const std::string& o, uint64_t notify_id, @@ -169,8 +162,7 @@ TestWatchNotify::SharedWatcher TestWatchNotify::_get_watcher( void TestWatchNotify::execute_notify(const std::string &oid, bufferlist &bl, uint64_t notify_id, - Mutex *lock, Cond *cond, - bool *done) { + Context *on_notify) { WatchHandles watch_handles; SharedNotifyHandle notify_handle; @@ -218,15 +210,11 @@ void TestWatchNotify::execute_notify(const std::string &oid, } } - Mutex::Locker l3(*lock); - *done = true; - cond->Signal(); + on_notify->complete(0); - { - Mutex::Locker file_watcher_locker(m_file_watcher_lock); - if (--m_pending_notifies == 0) { - m_file_watcher_cond.Signal(); - } + Mutex::Locker file_watcher_locker(m_file_watcher_lock); + if (--m_pending_notifies == 0) { + m_file_watcher_cond.Signal(); } } diff --git a/src/test/librados_test_stub/TestWatchNotify.h b/src/test/librados_test_stub/TestWatchNotify.h index 1761302bbf3..6f99704784e 100644 --- a/src/test/librados_test_stub/TestWatchNotify.h +++ b/src/test/librados_test_stub/TestWatchNotify.h @@ -57,6 +57,8 @@ public: void flush(); int list_watchers(const std::string& o, std::list<obj_watch_t> *out_watchers); + void aio_notify(const std::string& oid, bufferlist& bl, uint64_t timeout_ms, + bufferlist *pbl, Context *on_notify); int notify(const std::string& o, bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl); void notify_ack(const std::string& o, uint64_t notify_id, @@ -84,7 +86,7 @@ private: SharedWatcher get_watcher(const std::string& oid); SharedWatcher _get_watcher(const std::string& oid); void execute_notify(const std::string &oid, bufferlist &bl, - uint64_t notify_id, Mutex *lock, Cond *cond, bool *done); + uint64_t notify_id, Context *on_notify); }; |