From 90dcbc8752323954ca99eab081412f2987e5bad0 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 18 Jun 2018 13:47:18 -0400 Subject: [PATCH] test/librados_test_stub: implement namespace support Signed-off-by: Jason Dillaman --- .../librados_test_stub/LibradosTestStub.cc | 5 ++ src/test/librados_test_stub/TestCluster.h | 22 ++++- src/test/librados_test_stub/TestIoCtxImpl.cc | 28 +++--- src/test/librados_test_stub/TestIoCtxImpl.h | 10 +++ src/test/librados_test_stub/TestMemCluster.cc | 21 +++-- src/test/librados_test_stub/TestMemCluster.h | 20 ++--- .../librados_test_stub/TestMemIoCtxImpl.cc | 32 ++++--- .../librados_test_stub/TestMemRadosClient.cc | 12 +-- .../librados_test_stub/TestMemRadosClient.h | 6 +- src/test/librados_test_stub/TestRadosClient.h | 16 ++-- .../librados_test_stub/TestWatchNotify.cc | 88 +++++++++++-------- src/test/librados_test_stub/TestWatchNotify.h | 58 +++++++----- 12 files changed, 195 insertions(+), 123 deletions(-) diff --git a/src/test/librados_test_stub/LibradosTestStub.cc b/src/test/librados_test_stub/LibradosTestStub.cc index 692f70d73696c..edfb988446527 100644 --- a/src/test/librados_test_stub/LibradosTestStub.cc +++ b/src/test/librados_test_stub/LibradosTestStub.cc @@ -733,6 +733,11 @@ int IoCtx::application_metadata_list(const std::string& app_name, return -EOPNOTSUPP; } +void IoCtx::set_namespace(const std::string& nspace) { + TestIoCtxImpl *ctx = reinterpret_cast(io_ctx_impl); + ctx->set_namespace(nspace); +} + static int save_operation_result(int result, int *pval) { if (pval != NULL) { *pval = result; diff --git a/src/test/librados_test_stub/TestCluster.h b/src/test/librados_test_stub/TestCluster.h index c21dd7ef947bd..d7a31b6c08ad8 100644 --- a/src/test/librados_test_stub/TestCluster.h +++ b/src/test/librados_test_stub/TestCluster.h @@ -15,6 +15,22 @@ class TestWatchNotify; class TestCluster { public: + struct ObjectLocator { + std::string nspace; + std::string name; + + ObjectLocator(const std::string& nspace, const std::string& name) + : nspace(nspace), name(name) { + } + + bool operator<(const ObjectLocator& rhs) const { + if (nspace != rhs.nspace) { + return nspace < rhs.nspace; + } + return name < rhs.name; + } + }; + struct ObjectHandler { virtual ~ObjectHandler() {} @@ -28,9 +44,11 @@ public: virtual TestRadosClient *create_rados_client(CephContext *cct) = 0; - virtual int register_object_handler(int64_t pool_id, const std::string& o, + virtual int register_object_handler(int64_t pool_id, + const ObjectLocator& locator, ObjectHandler* object_handler) = 0; - virtual void unregister_object_handler(int64_t pool_id, const std::string& o, + virtual void unregister_object_handler(int64_t pool_id, + const ObjectLocator& locator, ObjectHandler* object_handler) = 0; TestWatchNotify *get_watch_notify() { diff --git a/src/test/librados_test_stub/TestIoCtxImpl.cc b/src/test/librados_test_stub/TestIoCtxImpl.cc index 96786a84e067a..0c5ce25a926aa 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestIoCtxImpl.cc @@ -32,6 +32,7 @@ TestIoCtxImpl::TestIoCtxImpl(const TestIoCtxImpl& rhs) : m_client(rhs.m_client), m_pool_id(rhs.m_pool_id), m_pool_name(rhs.m_pool_name), + m_namespace_name(rhs.m_namespace_name), m_snap_seq(rhs.m_snap_seq) { m_client->get(); @@ -98,8 +99,8 @@ void TestIoCtxImpl::aio_notify(const std::string& oid, AioCompletionImpl *c, m_pending_ops++; c->get(); C_AioNotify *ctx = new C_AioNotify(this, c); - m_client->get_watch_notify()->aio_notify(m_client, m_pool_id, oid, bl, - timeout_ms, pbl, ctx); + m_client->get_watch_notify()->aio_notify(m_client, m_pool_id, get_namespace(), + oid, bl, timeout_ms, pbl, ctx); } int TestIoCtxImpl::aio_operate(const std::string& oid, TestObjectOperationImpl &ops, @@ -135,7 +136,8 @@ int TestIoCtxImpl::aio_watch(const std::string& o, AioCompletionImpl *c, if (m_client->is_blacklisted()) { m_client->get_aio_finisher()->queue(ctx, -EBLACKLISTED); } else { - m_client->get_watch_notify()->aio_watch(m_client, m_pool_id, o, + m_client->get_watch_notify()->aio_watch(m_client, m_pool_id, + get_namespace(), o, get_instance_id(), handle, nullptr, watch_ctx, ctx); } @@ -177,8 +179,8 @@ int TestIoCtxImpl::list_watchers(const std::string& o, return -EBLACKLISTED; } - return m_client->get_watch_notify()->list_watchers(m_pool_id, o, - out_watchers); + return m_client->get_watch_notify()->list_watchers(m_pool_id, get_namespace(), + o, out_watchers); } int TestIoCtxImpl::notify(const std::string& o, bufferlist& bl, @@ -187,15 +189,16 @@ int TestIoCtxImpl::notify(const std::string& o, bufferlist& bl, return -EBLACKLISTED; } - return m_client->get_watch_notify()->notify(m_client, m_pool_id, o, bl, + return m_client->get_watch_notify()->notify(m_client, m_pool_id, + get_namespace(), o, bl, timeout_ms, pbl); } void TestIoCtxImpl::notify_ack(const std::string& o, uint64_t notify_id, uint64_t handle, bufferlist& bl) { - m_client->get_watch_notify()->notify_ack(m_client, m_pool_id, o, notify_id, - handle, m_client->get_instance_id(), - bl); + m_client->get_watch_notify()->notify_ack(m_client, m_pool_id, get_namespace(), + o, notify_id, handle, + m_client->get_instance_id(), bl); } int TestIoCtxImpl::operate(const std::string& oid, TestObjectOperationImpl &ops) { @@ -335,7 +338,8 @@ int TestIoCtxImpl::watch(const std::string& o, uint64_t *handle, return -EBLACKLISTED; } - return m_client->get_watch_notify()->watch(m_client, m_pool_id, o, + return m_client->get_watch_notify()->watch(m_client, m_pool_id, + get_namespace(), o, get_instance_id(), handle, ctx, ctx2); } @@ -346,7 +350,7 @@ int TestIoCtxImpl::execute_operation(const std::string& oid, return -EBLACKLISTED; } - TestRadosClient::Transaction transaction(m_client, oid); + TestRadosClient::Transaction transaction(m_client, get_namespace(), oid); return operation(this, oid); } @@ -358,7 +362,7 @@ int TestIoCtxImpl::execute_aio_operations(const std::string& oid, if (m_client->is_blacklisted()) { ret = -EBLACKLISTED; } else { - TestRadosClient::Transaction transaction(m_client, oid); + TestRadosClient::Transaction transaction(m_client, get_namespace(), oid); for (ObjectOperations::iterator it = ops->ops.begin(); it != ops->ops.end(); ++it) { ret = (*it)(this, oid, pbl, snapc); diff --git a/src/test/librados_test_stub/TestIoCtxImpl.h b/src/test/librados_test_stub/TestIoCtxImpl.h index 87053085e9990..448575a334df9 100644 --- a/src/test/librados_test_stub/TestIoCtxImpl.h +++ b/src/test/librados_test_stub/TestIoCtxImpl.h @@ -61,6 +61,14 @@ public: virtual int64_t get_id(); virtual uint64_t get_last_version(); virtual std::string get_pool_name(); + + inline void set_namespace(const std::string& namespace_name) { + m_namespace_name = namespace_name; + } + inline std::string get_namespace() const { + return m_namespace_name; + } + snap_t get_snap_read() const { return m_snap_seq; } @@ -188,6 +196,8 @@ private: TestRadosClient *m_client; int64_t m_pool_id = 0; std::string m_pool_name; + std::string m_namespace_name; + snap_t m_snap_seq = 0; SnapContext m_snapc; std::atomic m_refcount = { 0 }; diff --git a/src/test/librados_test_stub/TestMemCluster.cc b/src/test/librados_test_stub/TestMemCluster.cc index 4b1efcdb57f8d..e8e2c60ca1032 100644 --- a/src/test/librados_test_stub/TestMemCluster.cc +++ b/src/test/librados_test_stub/TestMemCluster.cc @@ -38,7 +38,7 @@ TestRadosClient *TestMemCluster::create_rados_client(CephContext *cct) { } int TestMemCluster::register_object_handler(int64_t pool_id, - const std::string& o, + const ObjectLocator& locator, ObjectHandler* object_handler) { Mutex::Locker locker(m_lock); auto pool = get_pool(m_lock, pool_id); @@ -47,12 +47,12 @@ int TestMemCluster::register_object_handler(int64_t pool_id, } RWLock::WLocker pool_locker(pool->file_lock); - auto file_it = pool->files.find(o); + auto file_it = pool->files.find(locator); if (file_it == pool->files.end()) { return -ENOENT; } - auto& object_handlers = pool->file_handlers[o]; + auto& object_handlers = pool->file_handlers[locator]; auto it = object_handlers.find(object_handler); assert(it == object_handlers.end()); @@ -61,7 +61,7 @@ int TestMemCluster::register_object_handler(int64_t pool_id, } void TestMemCluster::unregister_object_handler(int64_t pool_id, - const std::string& o, + const ObjectLocator& locator, ObjectHandler* object_handler) { Mutex::Locker locker(m_lock); auto pool = get_pool(m_lock, pool_id); @@ -70,7 +70,7 @@ void TestMemCluster::unregister_object_handler(int64_t pool_id, } RWLock::WLocker pool_locker(pool->file_lock); - auto handlers_it = pool->file_handlers.find(o); + auto handlers_it = pool->file_handlers.find(locator); if (handlers_it == pool->file_handlers.end()) { return; } @@ -183,19 +183,18 @@ void TestMemCluster::blacklist(uint32_t nonce) { m_blacklist.insert(nonce); } -void TestMemCluster::transaction_start(const std::string &oid) { +void TestMemCluster::transaction_start(const ObjectLocator& locator) { Mutex::Locker locker(m_lock); - while (m_transactions.count(oid)) { + while (m_transactions.count(locator)) { m_transaction_cond.Wait(m_lock); } - std::pair::iterator, bool> result = - m_transactions.insert(oid); + auto result = m_transactions.insert(locator); assert(result.second); } -void TestMemCluster::transaction_finish(const std::string &oid) { +void TestMemCluster::transaction_finish(const ObjectLocator& locator) { Mutex::Locker locker(m_lock); - size_t count = m_transactions.erase(oid); + size_t count = m_transactions.erase(locator); assert(count == 1); m_transaction_cond.Signal(); } diff --git a/src/test/librados_test_stub/TestMemCluster.h b/src/test/librados_test_stub/TestMemCluster.h index a285a24cc5c28..af5c1af4fc6f4 100644 --- a/src/test/librados_test_stub/TestMemCluster.h +++ b/src/test/librados_test_stub/TestMemCluster.h @@ -23,12 +23,12 @@ namespace librados { class TestMemCluster : public TestCluster { public: typedef std::map OMap; - typedef std::map FileOMaps; - typedef std::map FileTMaps; + typedef std::map FileOMaps; + typedef std::map FileTMaps; typedef std::map XAttrs; - typedef std::map FileXAttrs; + typedef std::map FileXAttrs; typedef std::set ObjectHandlers; - typedef std::map FileHandlers; + typedef std::map FileHandlers; struct File { File(); @@ -47,7 +47,7 @@ public: typedef boost::shared_ptr SharedFile; typedef std::list FileSnapshots; - typedef std::map Files; + typedef std::map Files; typedef std::set SnapSeqs; struct Pool : public RefCountedObject { @@ -71,9 +71,9 @@ public: TestRadosClient *create_rados_client(CephContext *cct) override; - int register_object_handler(int64_t pool_id, const std::string& o, + int register_object_handler(int64_t pool_id, const ObjectLocator& locator, ObjectHandler* object_handler) override; - void unregister_object_handler(int64_t pool_id, const std::string& o, + void unregister_object_handler(int64_t pool_id, const ObjectLocator& locator, ObjectHandler* object_handler) override; int pool_create(const std::string &pool_name); @@ -92,8 +92,8 @@ public: bool is_blacklisted(uint32_t nonce) const; void blacklist(uint32_t nonce); - void transaction_start(const std::string &oid); - void transaction_finish(const std::string &oid); + void transaction_start(const ObjectLocator& locator); + void transaction_finish(const ObjectLocator& locator); private: @@ -111,7 +111,7 @@ private: Blacklist m_blacklist; Cond m_transaction_cond; - std::set m_transactions; + std::set m_transactions; Pool *get_pool(const Mutex& lock, int64_t pool_id); diff --git a/src/test/librados_test_stub/TestMemIoCtxImpl.cc b/src/test/librados_test_stub/TestMemIoCtxImpl.cc index 528383d8f04c7..013b47992964c 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.cc @@ -109,7 +109,8 @@ int TestMemIoCtxImpl::list_snaps(const std::string& oid, snap_set_t *out_snaps) out_snaps->clones.clear(); RWLock::RLocker l(m_pool->file_lock); - TestMemCluster::Files::iterator it = m_pool->files.find(oid); + TestMemCluster::Files::iterator it = m_pool->files.find( + {get_namespace(), oid}); if (it == m_pool->files.end()) { return -ENOENT; } @@ -194,7 +195,8 @@ int TestMemIoCtxImpl::omap_get_vals2(const std::string& oid, out_vals->clear(); RWLock::RLocker l(file->lock); - TestMemCluster::FileOMaps::iterator o_it = m_pool->file_omaps.find(oid); + TestMemCluster::FileOMaps::iterator o_it = m_pool->file_omaps.find( + {get_namespace(), oid}); if (o_it == m_pool->file_omaps.end()) { if (pmore) { *pmore = false; @@ -250,7 +252,7 @@ int TestMemIoCtxImpl::omap_rm_keys(const std::string& oid, RWLock::WLocker l(file->lock); for (std::set::iterator it = keys.begin(); it != keys.end(); ++it) { - m_pool->file_omaps[oid].erase(*it); + m_pool->file_omaps[{get_namespace(), oid}].erase(*it); } return 0; } @@ -277,7 +279,7 @@ int TestMemIoCtxImpl::omap_set(const std::string& oid, it != map.end(); ++it) { bufferlist bl; bl.append(it->second); - m_pool->file_omaps[oid][it->first] = bl; + m_pool->file_omaps[{get_namespace(), oid}][it->first] = bl; } return 0; @@ -330,13 +332,14 @@ int TestMemIoCtxImpl::remove(const std::string& oid, const SnapContext &snapc) { file->exists = false; } - TestMemCluster::Files::iterator it = m_pool->files.find(oid); + TestCluster::ObjectLocator locator(get_namespace(), oid); + TestMemCluster::Files::iterator it = m_pool->files.find(locator); assert(it != m_pool->files.end()); if (*it->second.rbegin() == file) { TestMemCluster::ObjectHandlers object_handlers; - std::swap(object_handlers, m_pool->file_handlers[oid]); - m_pool->file_handlers.erase(oid); + std::swap(object_handlers, m_pool->file_handlers[locator]); + m_pool->file_handlers.erase(locator); for (auto object_handler : object_handlers) { object_handler->handle_removed(m_client); @@ -345,7 +348,7 @@ int TestMemIoCtxImpl::remove(const std::string& oid, const SnapContext &snapc) { if (it->second.size() == 1) { m_pool->files.erase(it); - m_pool->file_omaps.erase(oid); + m_pool->file_omaps.erase(locator); } return 0; } @@ -387,7 +390,8 @@ int TestMemIoCtxImpl::selfmanaged_snap_rollback(const std::string& oid, RWLock::WLocker l(m_pool->file_lock); TestMemCluster::SharedFile file; - TestMemCluster::Files::iterator f_it = m_pool->files.find(oid); + TestMemCluster::Files::iterator f_it = m_pool->files.find( + {get_namespace(), oid}); if (f_it == m_pool->files.end()) { return 0; } @@ -672,7 +676,8 @@ int TestMemIoCtxImpl::xattr_get(const std::string& oid, TestMemCluster::SharedFile file; RWLock::RLocker l(m_pool->file_lock); - TestMemCluster::FileXAttrs::iterator it = m_pool->file_xattrs.find(oid); + TestMemCluster::FileXAttrs::iterator it = m_pool->file_xattrs.find( + {get_namespace(), oid}); if (it == m_pool->file_xattrs.end()) { return -ENODATA; } @@ -687,7 +692,7 @@ int TestMemIoCtxImpl::xattr_set(const std::string& oid, const std::string &name, } RWLock::WLocker l(m_pool->file_lock); - m_pool->file_xattrs[oid][name] = bl; + m_pool->file_xattrs[{get_namespace(), oid}][name] = bl; return 0; } @@ -756,7 +761,8 @@ TestMemCluster::SharedFile TestMemIoCtxImpl::get_file( assert(!write || m_pool->file_lock.is_wlocked()); TestMemCluster::SharedFile file; - TestMemCluster::Files::iterator it = m_pool->files.find(oid); + TestMemCluster::Files::iterator it = m_pool->files.find( + {get_namespace(), oid}); if (it != m_pool->files.end()) { file = it->second.back(); } else if (!write) { @@ -793,7 +799,7 @@ TestMemCluster::SharedFile TestMemIoCtxImpl::get_file( if (new_version) { file->snap_id = snapc.seq; file->mtime = ceph_clock_now().sec(); - m_pool->files[oid].push_back(file); + m_pool->files[{get_namespace(), oid}].push_back(file); } return file; } diff --git a/src/test/librados_test_stub/TestMemRadosClient.cc b/src/test/librados_test_stub/TestMemRadosClient.cc index 1962cc3b36290..93807acfffe55 100644 --- a/src/test/librados_test_stub/TestMemRadosClient.cc +++ b/src/test/librados_test_stub/TestMemRadosClient.cc @@ -35,7 +35,7 @@ void TestMemRadosClient::object_list(int64_t pool_id, RWLock::RLocker file_locker(pool->file_lock); for (auto &file_pair : pool->files) { Object obj; - obj.oid = file_pair.first; + obj.oid = file_pair.first.name; list->push_back(obj); } } @@ -105,12 +105,14 @@ int TestMemRadosClient::blacklist_add(const std::string& client_address, return 0; } -void TestMemRadosClient::transaction_start(const std::string &oid) { - m_mem_cluster->transaction_start(oid); +void TestMemRadosClient::transaction_start(const std::string& nspace, + const std::string &oid) { + m_mem_cluster->transaction_start({nspace, oid}); } -void TestMemRadosClient::transaction_finish(const std::string &oid) { - m_mem_cluster->transaction_finish(oid); +void TestMemRadosClient::transaction_finish(const std::string& nspace, + const std::string &oid) { + m_mem_cluster->transaction_finish({nspace, oid}); } } // namespace librados diff --git a/src/test/librados_test_stub/TestMemRadosClient.h b/src/test/librados_test_stub/TestMemRadosClient.h index 26db0795d69ba..f11c69affe836 100644 --- a/src/test/librados_test_stub/TestMemRadosClient.h +++ b/src/test/librados_test_stub/TestMemRadosClient.h @@ -66,8 +66,10 @@ protected: } protected: - void transaction_start(const std::string &oid) override; - void transaction_finish(const std::string &oid) override; + void transaction_start(const std::string& nspace, + const std::string &oid) override; + void transaction_finish(const std::string& nspace, + const std::string &oid) override; private: TestMemCluster *m_mem_cluster; diff --git a/src/test/librados_test_stub/TestRadosClient.h b/src/test/librados_test_stub/TestRadosClient.h index cf4cf3555f3b5..cefacace748f0 100644 --- a/src/test/librados_test_stub/TestRadosClient.h +++ b/src/test/librados_test_stub/TestRadosClient.h @@ -42,15 +42,17 @@ public: class Transaction { public: - Transaction(TestRadosClient *rados_client, const std::string &oid) - : rados_client(rados_client), oid(oid) { - rados_client->transaction_start(oid); + Transaction(TestRadosClient *rados_client, const std::string& nspace, + const std::string &oid) + : rados_client(rados_client), nspace(nspace), oid(oid) { + rados_client->transaction_start(nspace, oid); } ~Transaction() { - rados_client->transaction_finish(oid); + rados_client->transaction_finish(nspace, oid); } private: TestRadosClient *rados_client; + std::string nspace; std::string oid; }; @@ -117,8 +119,10 @@ public: protected: virtual ~TestRadosClient(); - virtual void transaction_start(const std::string &oid) = 0; - virtual void transaction_finish(const std::string &oid) = 0; + virtual void transaction_start(const std::string& nspace, + const std::string &oid) = 0; + virtual void transaction_finish(const std::string& nspace, + const std::string &oid) = 0; private: diff --git a/src/test/librados_test_stub/TestWatchNotify.cc b/src/test/librados_test_stub/TestWatchNotify.cc index 427c95f374541..7defa99d9d26a 100644 --- a/src/test/librados_test_stub/TestWatchNotify.cc +++ b/src/test/librados_test_stub/TestWatchNotify.cc @@ -26,21 +26,23 @@ std::ostream& operator<<(std::ostream& out, struct TestWatchNotify::ObjectHandler : public TestCluster::ObjectHandler { TestWatchNotify* test_watch_notify; int64_t pool_id; + std::string nspace; std::string oid; ObjectHandler(TestWatchNotify* test_watch_notify, int64_t pool_id, - const std::string& oid) + const std::string& nspace, const std::string& oid) : test_watch_notify(test_watch_notify), pool_id(pool_id), - oid(oid) { + nspace(nspace), oid(oid) { } void handle_removed(TestRadosClient* test_rados_client) override { // copy member variables since this object might be deleted auto _test_watch_notify = test_watch_notify; auto _pool_id = pool_id; + auto _nspace = nspace; auto _oid = oid; - auto ctx = new FunctionContext([_test_watch_notify, _pool_id, _oid](int r) { - _test_watch_notify->handle_object_removed(_pool_id, _oid); + auto ctx = new FunctionContext([_test_watch_notify, _pool_id, _nspace, _oid](int r) { + _test_watch_notify->handle_object_removed(_pool_id, _nspace, _oid); }); test_rados_client->get_aio_finisher()->queue(ctx); } @@ -60,10 +62,11 @@ void TestWatchNotify::flush(TestRadosClient *rados_client) { ctx.wait(); } -int TestWatchNotify::list_watchers(int64_t pool_id, const std::string& o, +int TestWatchNotify::list_watchers(int64_t pool_id, const std::string& nspace, + const std::string& o, std::list *out_watchers) { Mutex::Locker lock(m_lock); - SharedWatcher watcher = get_watcher(pool_id, o); + SharedWatcher watcher = get_watcher(pool_id, nspace, o); if (!watcher) { return -ENOENT; } @@ -88,21 +91,22 @@ void TestWatchNotify::aio_flush(TestRadosClient *rados_client, } int TestWatchNotify::watch(TestRadosClient *rados_client, int64_t pool_id, - const std::string& o, uint64_t gid, uint64_t *handle, + const std::string& nspace, const std::string& o, + uint64_t gid, uint64_t *handle, librados::WatchCtx *ctx, librados::WatchCtx2 *ctx2) { C_SaferCond cond; - aio_watch(rados_client, pool_id, o, gid, handle, ctx, ctx2, &cond); + aio_watch(rados_client, pool_id, nspace, o, gid, handle, ctx, ctx2, &cond); return cond.wait(); } void TestWatchNotify::aio_watch(TestRadosClient *rados_client, int64_t pool_id, - const std::string& o, uint64_t gid, - uint64_t *handle, + const std::string& nspace, const std::string& o, + uint64_t gid, uint64_t *handle, librados::WatchCtx *watch_ctx, librados::WatchCtx2 *watch_ctx2, Context *on_finish) { auto ctx = new FunctionContext([=](int) { - execute_watch(rados_client, pool_id, o, gid, handle, watch_ctx, + execute_watch(rados_client, pool_id, nspace, o, gid, handle, watch_ctx, watch_ctx2, on_finish); }); rados_client->get_aio_finisher()->queue(ctx); @@ -124,24 +128,27 @@ void TestWatchNotify::aio_unwatch(TestRadosClient *rados_client, } void TestWatchNotify::aio_notify(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& oid, const bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl, Context *on_notify) { auto ctx = new FunctionContext([=](int) { - execute_notify(rados_client, pool_id, oid, bl, pbl, on_notify); + execute_notify(rados_client, pool_id, nspace, oid, bl, pbl, on_notify); }); rados_client->get_aio_finisher()->queue(ctx); } int TestWatchNotify::notify(TestRadosClient *rados_client, int64_t pool_id, - const std::string& oid, bufferlist& bl, - uint64_t timeout_ms, bufferlist *pbl) { + const std::string& nspace, const std::string& oid, + bufferlist& bl, uint64_t timeout_ms, + bufferlist *pbl) { C_SaferCond cond; - aio_notify(rados_client, pool_id, oid, bl, timeout_ms, pbl, &cond); + aio_notify(rados_client, pool_id, nspace, oid, bl, timeout_ms, pbl, &cond); return cond.wait(); } void TestWatchNotify::notify_ack(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string& o, uint64_t notify_id, uint64_t handle, uint64_t gid, bufferlist& bl) { @@ -150,20 +157,20 @@ void TestWatchNotify::notify_ack(TestRadosClient *rados_client, int64_t pool_id, << ", gid=" << gid << dendl; Mutex::Locker lock(m_lock); WatcherID watcher_id = std::make_pair(gid, handle); - ack_notify(rados_client, pool_id, o, notify_id, watcher_id, bl); - finish_notify(rados_client, pool_id, o, notify_id); + ack_notify(rados_client, pool_id, nspace, o, notify_id, watcher_id, bl); + finish_notify(rados_client, pool_id, nspace, o, notify_id); } void TestWatchNotify::execute_watch(TestRadosClient *rados_client, - int64_t pool_id, const std::string& o, - uint64_t gid, uint64_t *handle, - librados::WatchCtx *ctx, + int64_t pool_id, const std::string& nspace, + const std::string& o, uint64_t gid, + uint64_t *handle, librados::WatchCtx *ctx, librados::WatchCtx2 *ctx2, Context* on_finish) { CephContext *cct = rados_client->cct(); m_lock.Lock(); - SharedWatcher watcher = get_watcher(pool_id, o); + SharedWatcher watcher = get_watcher(pool_id, nspace, o); if (!watcher) { m_lock.Unlock(); on_finish->complete(-ENOENT); @@ -212,21 +219,21 @@ void TestWatchNotify::execute_unwatch(TestRadosClient *rados_client, } TestWatchNotify::SharedWatcher TestWatchNotify::get_watcher( - int64_t pool_id, const std::string& oid) { + int64_t pool_id, const std::string& nspace, const std::string& oid) { assert(m_lock.is_locked()); - auto it = m_file_watchers.find({pool_id, oid}); + auto it = m_file_watchers.find({pool_id, nspace, oid}); if (it == m_file_watchers.end()) { - SharedWatcher watcher(new Watcher(pool_id, oid)); + SharedWatcher watcher(new Watcher(pool_id, nspace, oid)); watcher->object_handler.reset(new ObjectHandler( - this, pool_id, oid)); + this, pool_id, nspace, oid)); int r = m_test_cluster->register_object_handler( - pool_id, oid, watcher->object_handler.get()); + pool_id, {nspace, oid}, watcher->object_handler.get()); if (r < 0) { // object doesn't exist return SharedWatcher(); } - m_file_watchers[{pool_id, oid}] = watcher; + m_file_watchers[{pool_id, nspace, oid}] = watcher; return watcher; } @@ -239,19 +246,21 @@ void TestWatchNotify::maybe_remove_watcher(SharedWatcher watcher) { // TODO if (watcher->watch_handles.empty() && watcher->notify_handles.empty()) { auto pool_id = watcher->pool_id; + auto& nspace = watcher->nspace; auto& oid = watcher->oid; if (watcher->object_handler) { - m_test_cluster->unregister_object_handler(pool_id, oid, + m_test_cluster->unregister_object_handler(pool_id, {nspace, oid}, watcher->object_handler.get()); watcher->object_handler.reset(); } - m_file_watchers.erase({pool_id, oid}); + m_file_watchers.erase({pool_id, nspace, oid}); } } void TestWatchNotify::execute_notify(TestRadosClient *rados_client, - int64_t pool_id, const std::string &oid, + int64_t pool_id, const std::string& nspace, + const std::string &oid, const bufferlist &bl, bufferlist *pbl, Context *on_notify) { CephContext *cct = rados_client->cct(); @@ -259,7 +268,7 @@ void TestWatchNotify::execute_notify(TestRadosClient *rados_client, m_lock.Lock(); uint64_t notify_id = ++m_notify_id; - SharedWatcher watcher = get_watcher(pool_id, oid); + SharedWatcher watcher = get_watcher(pool_id, nspace, oid); if (!watcher) { ldout(cct, 1) << "oid=" << oid << ": not found" << dendl; m_lock.Unlock(); @@ -283,7 +292,7 @@ void TestWatchNotify::execute_notify(TestRadosClient *rados_client, m_async_op_tracker.start_op(); uint64_t notifier_id = rados_client->get_instance_id(); watch_handle.rados_client->get_aio_finisher()->queue(new FunctionContext( - [this, pool_id, oid, bl, notify_id, watch_handle, notifier_id](int r) { + [this, pool_id, nspace, oid, bl, notify_id, watch_handle, notifier_id](int r) { bufferlist notify_bl; notify_bl.append(bl); @@ -295,7 +304,7 @@ void TestWatchNotify::execute_notify(TestRadosClient *rados_client, watch_handle.watch_ctx->notify(0, 0, notify_bl); // auto ack old-style watch/notify clients - ack_notify(watch_handle.rados_client, pool_id, oid, notify_id, + ack_notify(watch_handle.rados_client, pool_id, nspace, oid, notify_id, {watch_handle.gid, watch_handle.handle}, bufferlist()); } @@ -304,18 +313,19 @@ void TestWatchNotify::execute_notify(TestRadosClient *rados_client, } watcher->notify_handles[notify_id] = notify_handle; - finish_notify(rados_client, pool_id, oid, notify_id); + finish_notify(rados_client, pool_id, nspace, oid, notify_id); m_lock.Unlock(); } void TestWatchNotify::ack_notify(TestRadosClient *rados_client, int64_t pool_id, + const std::string& nspace, const std::string &oid, uint64_t notify_id, const WatcherID &watcher_id, const bufferlist &bl) { CephContext *cct = rados_client->cct(); assert(m_lock.is_locked()); - SharedWatcher watcher = get_watcher(pool_id, oid); + SharedWatcher watcher = get_watcher(pool_id, nspace, oid); if (!watcher) { ldout(cct, 1) << "oid=" << oid << ": not found" << dendl; return; @@ -340,14 +350,15 @@ void TestWatchNotify::ack_notify(TestRadosClient *rados_client, int64_t pool_id, } void TestWatchNotify::finish_notify(TestRadosClient *rados_client, - int64_t pool_id, const std::string &oid, + int64_t pool_id, const std::string& nspace, + const std::string &oid, uint64_t notify_id) { CephContext *cct = rados_client->cct(); ldout(cct, 20) << "oid=" << oid << ", notify_id=" << notify_id << dendl; assert(m_lock.is_locked()); - SharedWatcher watcher = get_watcher(pool_id, oid); + SharedWatcher watcher = get_watcher(pool_id, nspace, oid); assert(watcher); NotifyHandles::iterator it = watcher->notify_handles.find(notify_id); @@ -399,9 +410,10 @@ void TestWatchNotify::blacklist(uint32_t nonce) { } void TestWatchNotify::handle_object_removed(int64_t pool_id, + const std::string& nspace, const std::string& oid) { Mutex::Locker locker(m_lock); - auto it = m_file_watchers.find({pool_id, oid}); + auto it = m_file_watchers.find({pool_id, nspace, oid}); if (it == m_file_watchers.end()) { return; } diff --git a/src/test/librados_test_stub/TestWatchNotify.h b/src/test/librados_test_stub/TestWatchNotify.h index 84adc4b36c639..4d381373f09e9 100644 --- a/src/test/librados_test_stub/TestWatchNotify.h +++ b/src/test/librados_test_stub/TestWatchNotify.h @@ -52,11 +52,12 @@ public: typedef boost::shared_ptr SharedObjectHandler; struct Watcher { - Watcher(int64_t pool_id, const std::string& oid) - : pool_id(pool_id), oid(oid) { + Watcher(int64_t pool_id, const std::string& nspace, const std::string& oid) + : pool_id(pool_id), nspace(nspace), oid(oid) { } int64_t pool_id; + std::string nspace; std::string oid; SharedObjectHandler object_handler; @@ -67,37 +68,40 @@ public: TestWatchNotify(TestCluster* test_cluster); - int list_watchers(int64_t pool_id, const std::string& o, - std::list *out_watchers); + int list_watchers(int64_t pool_id, const std::string& nspace, + const std::string& o, std::list *out_watchers); void aio_flush(TestRadosClient *rados_client, Context *on_finish); void aio_watch(TestRadosClient *rados_client, int64_t pool_id, - const std::string& o, uint64_t gid, uint64_t *handle, - librados::WatchCtx *watch_ctx, librados::WatchCtx2 *watch_ctx2, - Context *on_finish); + const std::string& nspace, const std::string& o, 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, int64_t pool_id, - const std::string& oid, const bufferlist& bl, - uint64_t timeout_ms, bufferlist *pbl, Context *on_notify); + const std::string& nspace, const std::string& oid, + const bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl, + Context *on_notify); void flush(TestRadosClient *rados_client); int notify(TestRadosClient *rados_client, int64_t pool_id, - const std::string& o, bufferlist& bl, uint64_t timeout_ms, - bufferlist *pbl); + const std::string& nspace, const std::string& o, bufferlist& bl, + uint64_t timeout_ms, bufferlist *pbl); void notify_ack(TestRadosClient *rados_client, int64_t pool_id, - const std::string& o, uint64_t notify_id, uint64_t handle, - uint64_t gid, bufferlist& bl); + const std::string& nspace, const std::string& o, + uint64_t notify_id, uint64_t handle, uint64_t gid, + bufferlist& bl); int watch(TestRadosClient *rados_client, int64_t pool_id, - const std::string& o, uint64_t gid, uint64_t *handle, - librados::WatchCtx *ctx, librados::WatchCtx2 *ctx2); + const std::string& nspace, const std::string& o, uint64_t gid, + uint64_t *handle, librados::WatchCtx *ctx, + librados::WatchCtx2 *ctx2); int unwatch(TestRadosClient *rados_client, uint64_t handle); void blacklist(uint32_t nonce); private: - typedef std::pair PoolFile; + typedef std::tuple PoolFile; typedef std::map FileWatchers; TestCluster *m_test_cluster; @@ -110,11 +114,13 @@ private: FileWatchers m_file_watchers; - SharedWatcher get_watcher(int64_t pool_id, const std::string& oid); + SharedWatcher get_watcher(int64_t pool_id, const std::string& nspace, + const std::string& oid); void maybe_remove_watcher(SharedWatcher shared_watcher); void execute_watch(TestRadosClient *rados_client, int64_t pool_id, - const std::string& o, uint64_t gid, uint64_t *handle, + const std::string& nspace, const std::string& o, + uint64_t gid, uint64_t *handle, librados::WatchCtx *watch_ctx, librados::WatchCtx2 *watch_ctx2, Context *on_finish); @@ -122,15 +128,19 @@ private: Context *on_finish); void execute_notify(TestRadosClient *rados_client, int64_t pool_id, - const std::string &oid, const bufferlist &bl, - bufferlist *pbl, Context *on_notify); + const std::string& nspace, const std::string &oid, + const bufferlist &bl, bufferlist *pbl, + Context *on_notify); void ack_notify(TestRadosClient *rados_client, int64_t pool_id, - const std::string &oid, uint64_t notify_id, - const WatcherID &watcher_id, const bufferlist &bl); + const std::string& nspace, const std::string &oid, + uint64_t notify_id, const WatcherID &watcher_id, + const bufferlist &bl); void finish_notify(TestRadosClient *rados_client, int64_t pool_id, - const std::string &oid, uint64_t notify_id); + const std::string& nspace, const std::string &oid, + uint64_t notify_id); - void handle_object_removed(int64_t pool_id, const std::string& oid); + void handle_object_removed(int64_t pool_id, const std::string& nspace, + const std::string& oid); }; } // namespace librados -- 2.39.5