From 792d6c53fedc695199cc18916347c1b545fe42c2 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 7 Jul 2019 12:42:23 +0800 Subject: [PATCH] test/librbd: s/Mutex/ceph::mutex/ Signed-off-by: Kefu Chai --- src/test/librados_test_stub/TestMemCluster.cc | 56 +++++++------- src/test/librados_test_stub/TestMemCluster.h | 13 ++-- .../librados_test_stub/TestMemIoCtxImpl.cc | 76 +++++++++---------- .../librados_test_stub/TestMemRadosClient.cc | 2 +- .../librados_test_stub/TestWatchNotify.cc | 10 +-- .../deep_copy/test_mock_ImageCopyRequest.cc | 22 +++--- .../deep_copy/test_mock_ObjectCopyRequest.cc | 2 +- .../test_mock_PostAcquireRequest.cc | 2 +- src/test/librbd/io/test_mock_CopyupRequest.cc | 20 ++--- src/test/librbd/io/test_mock_ImageRequest.cc | 24 +++--- .../librbd/io/test_mock_ImageRequestWQ.cc | 8 +- ...test_mock_SimpleSchedulerObjectDispatch.cc | 10 +-- src/test/librbd/journal/test_Entries.cc | 19 +++-- src/test/librbd/journal/test_Replay.cc | 14 ++-- .../librbd/journal/test_mock_OpenRequest.cc | 7 +- .../journal/test_mock_PromoteRequest.cc | 2 +- src/test/librbd/journal/test_mock_Replay.cc | 17 ++--- .../librbd/journal/test_mock_ResetRequest.cc | 1 - .../librbd/mirror/test_mock_DisableRequest.cc | 1 - src/test/librbd/mock/MockImageCtx.cc | 6 +- src/test/librbd/mock/MockImageCtx.h | 22 +++--- src/test/librbd/mock/MockSafeTimer.h | 2 +- .../object_map/test_mock_InvalidateRequest.cc | 20 ++--- .../object_map/test_mock_RefreshRequest.cc | 20 ++--- .../object_map/test_mock_ResizeRequest.cc | 8 +- .../test_mock_SnapshotCreateRequest.cc | 22 +++--- .../test_mock_SnapshotRemoveRequest.cc | 54 ++++++------- .../test_mock_SnapshotRollbackRequest.cc | 4 +- .../object_map/test_mock_UpdateRequest.cc | 44 ++++++----- .../test_mock_DisableFeaturesRequest.cc | 10 +-- .../test_mock_EnableFeaturesRequest.cc | 14 ++-- .../librbd/operation/test_mock_Request.cc | 4 +- .../operation/test_mock_ResizeRequest.cc | 2 +- .../test_mock_SnapshotCreateRequest.cc | 12 +-- .../test_mock_SnapshotProtectRequest.cc | 10 +-- .../test_mock_SnapshotRemoveRequest.cc | 26 +++---- .../test_mock_SnapshotRollbackRequest.cc | 2 +- .../test_mock_SnapshotUnprotectRequest.cc | 12 +-- .../librbd/operation/test_mock_TrimRequest.cc | 12 +-- src/test/librbd/test_DeepCopy.cc | 10 +-- src/test/librbd/test_ImageWatcher.cc | 56 +++++++------- src/test/librbd/test_Migration.cc | 8 +- src/test/librbd/test_ObjectMap.cc | 12 +-- src/test/librbd/test_fixture.cc | 2 +- src/test/librbd/test_internal.cc | 23 +++--- src/test/librbd/test_mirroring.cc | 1 + src/test/librbd/test_mock_ExclusiveLock.cc | 11 ++- src/test/librbd/test_mock_Journal.cc | 44 +++++------ src/test/librbd/test_mock_ObjectMap.cc | 8 +- src/test/librbd/test_mock_Watcher.cc | 17 ++--- .../watcher/test_mock_RewatchRequest.cc | 18 ++--- 51 files changed, 401 insertions(+), 421 deletions(-) diff --git a/src/test/librados_test_stub/TestMemCluster.cc b/src/test/librados_test_stub/TestMemCluster.cc index 3779be75c9c..1177ec462ea 100644 --- a/src/test/librados_test_stub/TestMemCluster.cc +++ b/src/test/librados_test_stub/TestMemCluster.cc @@ -7,24 +7,20 @@ namespace librados { TestMemCluster::File::File() - : snap_id(), exists(true), lock("TestMemCluster::File::lock") { + : snap_id(), exists(true) { } TestMemCluster::File::File(const File &rhs) : data(rhs.data), mtime(rhs.mtime), snap_id(rhs.snap_id), - exists(rhs.exists), - lock("TestMemCluster::File::lock") { + exists(rhs.exists) { } -TestMemCluster::Pool::Pool() - : file_lock("TestMemCluster::Pool::file_lock") { -} +TestMemCluster::Pool::Pool() = default; TestMemCluster::TestMemCluster() - : m_lock("TestMemCluster::m_lock"), - m_next_nonce(static_cast(reinterpret_cast(this))) { + : m_next_nonce(static_cast(reinterpret_cast(this))) { } TestMemCluster::~TestMemCluster() { @@ -40,13 +36,13 @@ TestRadosClient *TestMemCluster::create_rados_client(CephContext *cct) { int TestMemCluster::register_object_handler(int64_t pool_id, const ObjectLocator& locator, ObjectHandler* object_handler) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; auto pool = get_pool(m_lock, pool_id); if (pool == nullptr) { return -ENOENT; } - RWLock::WLocker pool_locker(pool->file_lock); + std::unique_lock pool_locker{pool->file_lock}; auto file_it = pool->files.find(locator); if (file_it == pool->files.end()) { return -ENOENT; @@ -63,13 +59,13 @@ int TestMemCluster::register_object_handler(int64_t pool_id, void TestMemCluster::unregister_object_handler(int64_t pool_id, const ObjectLocator& locator, ObjectHandler* object_handler) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; auto pool = get_pool(m_lock, pool_id); if (pool == nullptr) { return; } - RWLock::WLocker pool_locker(pool->file_lock); + std::unique_lock pool_locker{pool->file_lock}; auto handlers_it = pool->file_handlers.find(locator); if (handlers_it == pool->file_handlers.end()) { return; @@ -80,7 +76,7 @@ void TestMemCluster::unregister_object_handler(int64_t pool_id, } int TestMemCluster::pool_create(const std::string &pool_name) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; if (m_pools.find(pool_name) != m_pools.end()) { return -EEXIST; } @@ -91,7 +87,7 @@ int TestMemCluster::pool_create(const std::string &pool_name) { } int TestMemCluster::pool_delete(const std::string &pool_name) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; Pools::iterator iter = m_pools.find(pool_name); if (iter == m_pools.end()) { return -ENOENT; @@ -108,7 +104,7 @@ int TestMemCluster::pool_get_base_tier(int64_t pool_id, int64_t* base_tier) { } int TestMemCluster::pool_list(std::list >& v) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; v.clear(); for (Pools::iterator iter = m_pools.begin(); iter != m_pools.end(); ++iter) { v.push_back(std::make_pair(iter->second->pool_id, iter->first)); @@ -117,7 +113,7 @@ int TestMemCluster::pool_list(std::list >& v) { } int64_t TestMemCluster::pool_lookup(const std::string &pool_name) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; Pools::iterator iter = m_pools.find(pool_name); if (iter == m_pools.end()) { return -ENOENT; @@ -126,7 +122,7 @@ int64_t TestMemCluster::pool_lookup(const std::string &pool_name) { } int TestMemCluster::pool_reverse_lookup(int64_t id, std::string *name) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; for (Pools::iterator iter = m_pools.begin(); iter != m_pools.end(); ++iter) { if (iter->second->pool_id == id) { *name = iter->first; @@ -137,11 +133,11 @@ int TestMemCluster::pool_reverse_lookup(int64_t id, std::string *name) { } TestMemCluster::Pool *TestMemCluster::get_pool(int64_t pool_id) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; return get_pool(m_lock, pool_id); } -TestMemCluster::Pool *TestMemCluster::get_pool(const Mutex& lock, +TestMemCluster::Pool *TestMemCluster::get_pool(const ceph::mutex& lock, int64_t pool_id) { for (auto &pool_pair : m_pools) { if (pool_pair.second->pool_id == pool_id) { @@ -152,7 +148,7 @@ TestMemCluster::Pool *TestMemCluster::get_pool(const Mutex& lock, } TestMemCluster::Pool *TestMemCluster::get_pool(const std::string &pool_name) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; Pools::iterator iter = m_pools.find(pool_name); if (iter != m_pools.end()) { return iter->second; @@ -161,42 +157,42 @@ TestMemCluster::Pool *TestMemCluster::get_pool(const std::string &pool_name) { } void TestMemCluster::allocate_client(uint32_t *nonce, uint64_t *global_id) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; *nonce = m_next_nonce++; *global_id = m_next_global_id++; } void TestMemCluster::deallocate_client(uint32_t nonce) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; m_blacklist.erase(nonce); } bool TestMemCluster::is_blacklisted(uint32_t nonce) const { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; return (m_blacklist.find(nonce) != m_blacklist.end()); } void TestMemCluster::blacklist(uint32_t nonce) { m_watch_notify.blacklist(nonce); - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; m_blacklist.insert(nonce); } void TestMemCluster::transaction_start(const ObjectLocator& locator) { - Mutex::Locker locker(m_lock); - while (m_transactions.count(locator)) { - m_transaction_cond.Wait(m_lock); - } + std::unique_lock locker{m_lock}; + m_transaction_cond.wait(locker, [&locator, this] { + return m_transactions.count(locator) == 0; + }); auto result = m_transactions.insert(locator); ceph_assert(result.second); } void TestMemCluster::transaction_finish(const ObjectLocator& locator) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; size_t count = m_transactions.erase(locator); ceph_assert(count == 1); - m_transaction_cond.Signal(); + m_transaction_cond.notify_all(); } } // namespace librados diff --git a/src/test/librados_test_stub/TestMemCluster.h b/src/test/librados_test_stub/TestMemCluster.h index af5c1af4fc6..4b9bb1cf1aa 100644 --- a/src/test/librados_test_stub/TestMemCluster.h +++ b/src/test/librados_test_stub/TestMemCluster.h @@ -42,7 +42,8 @@ public: interval_set snap_overlap; bool exists; - RWLock lock; + ceph::shared_mutex lock = + ceph::make_shared_mutex("TestMemCluster::File::lock"); }; typedef boost::shared_ptr SharedFile; @@ -58,7 +59,8 @@ public: SnapSeqs snap_seqs; uint64_t snap_id = 1; - RWLock file_lock; + ceph::shared_mutex file_lock = + ceph::make_shared_mutex("TestMemCluster::Pool::file_lock"); Files files; FileOMaps file_omaps; FileTMaps file_tmaps; @@ -100,7 +102,8 @@ private: typedef std::map Pools; typedef std::set Blacklist; - mutable Mutex m_lock; + mutable ceph::mutex m_lock = + ceph::make_mutex("TestMemCluster::m_lock"); Pools m_pools; int64_t m_pool_id = 0; @@ -110,10 +113,10 @@ private: Blacklist m_blacklist; - Cond m_transaction_cond; + ceph::condition_variable m_transaction_cond; std::set m_transactions; - Pool *get_pool(const Mutex& lock, int64_t pool_id); + Pool *get_pool(const ceph::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 3f135954394..e47f3f76018 100644 --- a/src/test/librados_test_stub/TestMemIoCtxImpl.cc +++ b/src/test/librados_test_stub/TestMemIoCtxImpl.cc @@ -75,11 +75,11 @@ int TestMemIoCtxImpl::append(const std::string& oid, const bufferlist &bl, TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, true, snapc); } - RWLock::WLocker l(file->lock); + std::unique_lock l{file->lock}; auto off = file->data.length(); ensure_minimum_length(off + bl.length(), &file->data); file->data.copy_in(off, bl.length(), bl); @@ -91,7 +91,7 @@ int TestMemIoCtxImpl::assert_exists(const std::string &oid) { return -EBLACKLISTED; } - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; TestMemCluster::SharedFile file = get_file(oid, false, get_snap_context()); if (file == NULL) { return -ENOENT; @@ -107,7 +107,7 @@ int TestMemIoCtxImpl::create(const std::string& oid, bool exclusive, return -EBLACKLISTED; } - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; get_file(oid, true, snapc); return 0; } @@ -120,7 +120,7 @@ int TestMemIoCtxImpl::list_snaps(const std::string& oid, snap_set_t *out_snaps) out_snaps->seq = 0; out_snaps->clones.clear(); - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; TestMemCluster::Files::iterator it = m_pool->files.find( {get_namespace(), oid}); if (it == m_pool->files.end()) { @@ -169,7 +169,7 @@ int TestMemIoCtxImpl::list_snaps(const std::string& oid, snap_set_t *out_snaps) // Include the SNAP_HEAD TestMemCluster::File &file = *file_snaps.back(); if (file.exists) { - RWLock::RLocker l2(file.lock); + std::shared_lock l2{file.lock}; if (out_snaps->seq == 0 && !include_head) { out_snaps->seq = file.snap_id; } @@ -197,7 +197,7 @@ int TestMemIoCtxImpl::omap_get_vals2(const std::string& oid, TestMemCluster::SharedFile file; { - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; file = get_file(oid, false, get_snap_context()); if (file == NULL) { return -ENOENT; @@ -206,7 +206,7 @@ int TestMemIoCtxImpl::omap_get_vals2(const std::string& oid, out_vals->clear(); - RWLock::RLocker l(file->lock); + std::shared_lock l{file->lock}; TestMemCluster::FileOMaps::iterator o_it = m_pool->file_omaps.find( {get_namespace(), oid}); if (o_it == m_pool->file_omaps.end()) { @@ -254,14 +254,14 @@ int TestMemIoCtxImpl::omap_rm_keys(const std::string& oid, TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, true, get_snap_context()); if (file == NULL) { return -ENOENT; } } - RWLock::WLocker l(file->lock); + std::unique_lock l{file->lock}; for (std::set::iterator it = keys.begin(); it != keys.end(); ++it) { m_pool->file_omaps[{get_namespace(), oid}].erase(*it); @@ -279,14 +279,14 @@ int TestMemIoCtxImpl::omap_set(const std::string& oid, TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, true, get_snap_context()); if (file == NULL) { return -ENOENT; } } - RWLock::WLocker l(file->lock); + std::unique_lock l{file->lock}; for (std::map::const_iterator it = map.begin(); it != map.end(); ++it) { bufferlist bl; @@ -305,14 +305,14 @@ int TestMemIoCtxImpl::read(const std::string& oid, size_t len, uint64_t off, TestMemCluster::SharedFile file; { - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; file = get_file(oid, false, get_snap_context()); if (file == NULL) { return -ENOENT; } } - RWLock::RLocker l(file->lock); + std::shared_lock l{file->lock}; if (len == 0) { len = file->data.length(); } @@ -332,7 +332,7 @@ int TestMemIoCtxImpl::remove(const std::string& oid, const SnapContext &snapc) { return -EBLACKLISTED; } - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; TestMemCluster::SharedFile file = get_file(oid, false, snapc); if (file == NULL) { return -ENOENT; @@ -340,7 +340,7 @@ int TestMemIoCtxImpl::remove(const std::string& oid, const SnapContext &snapc) { file = get_file(oid, true, snapc); { - RWLock::WLocker l2(file->lock); + std::unique_lock l2{file->lock}; file->exists = false; } @@ -370,7 +370,7 @@ int TestMemIoCtxImpl::selfmanaged_snap_create(uint64_t *snapid) { return -EBLACKLISTED; } - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; *snapid = ++m_pool->snap_id; m_pool->snap_seqs.insert(*snapid); return 0; @@ -381,7 +381,7 @@ int TestMemIoCtxImpl::selfmanaged_snap_remove(uint64_t snapid) { return -EBLACKLISTED; } - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; TestMemCluster::SnapSeqs::iterator it = m_pool->snap_seqs.find(snapid); if (it == m_pool->snap_seqs.end()) { @@ -399,7 +399,7 @@ int TestMemIoCtxImpl::selfmanaged_snap_rollback(const std::string& oid, return -EBLACKLISTED; } - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; TestMemCluster::SharedFile file; TestMemCluster::Files::iterator f_it = m_pool->files.find( @@ -453,7 +453,7 @@ int TestMemIoCtxImpl::set_alloc_hint(const std::string& oid, } { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; get_file(oid, true, snapc); } @@ -471,14 +471,14 @@ int TestMemIoCtxImpl::sparse_read(const std::string& oid, uint64_t off, // TODO verify correctness TestMemCluster::SharedFile file; { - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; file = get_file(oid, false, get_snap_context()); if (file == NULL) { return -ENOENT; } } - RWLock::RLocker l(file->lock); + std::shared_lock l{file->lock}; len = clip_io(off, len, file->data.length()); // TODO support sparse read if (m != NULL) { @@ -503,14 +503,14 @@ int TestMemIoCtxImpl::stat(const std::string& oid, uint64_t *psize, TestMemCluster::SharedFile file; { - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; file = get_file(oid, false, get_snap_context()); if (file == NULL) { return -ENOENT; } } - RWLock::RLocker l(file->lock); + std::shared_lock l{file->lock}; if (psize != NULL) { *psize = file->data.length(); } @@ -530,11 +530,11 @@ int TestMemIoCtxImpl::truncate(const std::string& oid, uint64_t size, TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, true, snapc); } - RWLock::WLocker l(file->lock); + std::unique_lock l{file->lock}; bufferlist bl(size); interval_set is; @@ -568,11 +568,11 @@ int TestMemIoCtxImpl::write(const std::string& oid, bufferlist& bl, size_t len, TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, true, snapc); } - RWLock::WLocker l(file->lock); + std::unique_lock l{file->lock}; if (len > 0) { interval_set is; is.insert(off, len); @@ -595,14 +595,14 @@ int TestMemIoCtxImpl::write_full(const std::string& oid, bufferlist& bl, TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, true, snapc); if (file == NULL) { return -ENOENT; } } - RWLock::WLocker l(file->lock); + std::unique_lock l{file->lock}; if (bl.length() > 0) { interval_set is; is.insert(0, bl.length()); @@ -630,11 +630,11 @@ int TestMemIoCtxImpl::writesame(const std::string& oid, bufferlist& bl, size_t l TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, true, snapc); } - RWLock::WLocker l(file->lock); + std::unique_lock l{file->lock}; if (len > 0) { interval_set is; is.insert(off, len); @@ -662,14 +662,14 @@ int TestMemIoCtxImpl::cmpext(const std::string& oid, uint64_t off, TestMemCluster::SharedFile file; { - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; file = get_file(oid, false, get_snap_context()); if (file == NULL) { return cmpext_compare(cmp_bl, read_bl); } } - RWLock::RLocker l(file->lock); + std::shared_lock l{file->lock}; if (off >= file->data.length()) { len = 0; } else if (off + len > file->data.length()) { @@ -686,7 +686,7 @@ int TestMemIoCtxImpl::xattr_get(const std::string& oid, } TestMemCluster::SharedFile file; - RWLock::RLocker l(m_pool->file_lock); + std::shared_lock l{m_pool->file_lock}; TestMemCluster::FileXAttrs::iterator it = m_pool->file_xattrs.find( {get_namespace(), oid}); if (it == m_pool->file_xattrs.end()) { @@ -702,7 +702,7 @@ int TestMemIoCtxImpl::xattr_set(const std::string& oid, const std::string &name, return -EBLACKLISTED; } - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; m_pool->file_xattrs[{get_namespace(), oid}][name] = bl; return 0; } @@ -716,14 +716,14 @@ int TestMemIoCtxImpl::zero(const std::string& oid, uint64_t off, uint64_t len, bool truncate_redirect = false; TestMemCluster::SharedFile file; { - RWLock::WLocker l(m_pool->file_lock); + std::unique_lock l{m_pool->file_lock}; file = get_file(oid, false, snapc); if (!file) { return 0; } file = get_file(oid, true, snapc); - RWLock::RLocker l2(file->lock); + std::shared_lock l2{file->lock}; if (len > 0 && off + len >= file->data.length()) { // Zero -> Truncate logic embedded in OSD truncate_redirect = true; diff --git a/src/test/librados_test_stub/TestMemRadosClient.cc b/src/test/librados_test_stub/TestMemRadosClient.cc index 93807acfffe..0435a8c7392 100644 --- a/src/test/librados_test_stub/TestMemRadosClient.cc +++ b/src/test/librados_test_stub/TestMemRadosClient.cc @@ -32,7 +32,7 @@ void TestMemRadosClient::object_list(int64_t pool_id, auto pool = m_mem_cluster->get_pool(pool_id); if (pool != nullptr) { - RWLock::RLocker file_locker(pool->file_lock); + std::shared_lock file_locker{pool->file_lock}; for (auto &file_pair : pool->files) { Object obj; obj.oid = file_pair.first.name; diff --git a/src/test/librados_test_stub/TestWatchNotify.cc b/src/test/librados_test_stub/TestWatchNotify.cc index 71b1c8d4280..bc2121f0c5a 100644 --- a/src/test/librados_test_stub/TestWatchNotify.cc +++ b/src/test/librados_test_stub/TestWatchNotify.cc @@ -66,7 +66,7 @@ void TestWatchNotify::flush(TestRadosClient *rados_client) { 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); + std::lock_guard lock{m_lock}; SharedWatcher watcher = get_watcher(pool_id, nspace, o); if (!watcher) { return -ENOENT; @@ -157,7 +157,7 @@ void TestWatchNotify::notify_ack(TestRadosClient *rados_client, int64_t pool_id, CephContext *cct = rados_client->cct(); ldout(cct, 20) << "notify_id=" << notify_id << ", handle=" << handle << ", gid=" << gid << dendl; - Mutex::Locker lock(m_lock); + std::lock_guard lock{m_lock}; WatcherID watcher_id = std::make_pair(gid, handle); ack_notify(rados_client, pool_id, nspace, o, notify_id, watcher_id, bl); finish_notify(rados_client, pool_id, nspace, o, notify_id); @@ -204,7 +204,7 @@ void TestWatchNotify::execute_unwatch(TestRadosClient *rados_client, ldout(cct, 20) << "handle=" << handle << dendl; { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; for (FileWatchers::iterator it = m_file_watchers.begin(); it != m_file_watchers.end(); ++it) { SharedWatcher watcher = it->second; @@ -395,7 +395,7 @@ void TestWatchNotify::finish_notify(TestRadosClient *rados_client, } void TestWatchNotify::blacklist(uint32_t nonce) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; for (auto file_it = m_file_watchers.begin(); file_it != m_file_watchers.end(); ) { @@ -417,7 +417,7 @@ 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); + std::lock_guard locker{m_lock}; auto it = m_file_watchers.find({pool_id, nspace, oid}); if (it == m_file_watchers.end()) { return; diff --git a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc index a3e5effd998..cfe3228686f 100644 --- a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc +++ b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc @@ -52,22 +52,22 @@ struct ObjectCopyRequest { librbd::MockTestImageCtx *dst_image_ctx, const SnapMap &snap_map, uint64_t object_number, bool flatten, Context *on_finish) { ceph_assert(s_instance != nullptr); - Mutex::Locker locker(s_instance->lock); + std::lock_guard locker{s_instance->lock}; s_instance->snap_map = &snap_map; s_instance->object_contexts[object_number] = on_finish; - s_instance->cond.Signal(); + s_instance->cond.notify_all(); return s_instance; } MOCK_METHOD0(send, void()); - Mutex lock; - Cond cond; + ceph::mutex lock = ceph::make_mutex("lock"); + ceph::condition_variable cond; const SnapMap *snap_map = nullptr; std::map object_contexts; - ObjectCopyRequest() : lock("lock") { + ObjectCopyRequest() { s_instance = this; } }; @@ -170,10 +170,10 @@ public: bool complete_object_copy(MockObjectCopyRequest &mock_object_copy_request, uint64_t object_num, Context **object_ctx, int r) { - Mutex::Locker locker(mock_object_copy_request.lock); + std::unique_lock locker{mock_object_copy_request.lock}; while (mock_object_copy_request.object_contexts.count(object_num) == 0) { - if (mock_object_copy_request.cond.WaitInterval(mock_object_copy_request.lock, - utime_t(10, 0)) != 0) { + if (mock_object_copy_request.cond.wait_for(locker, 10s) == + std::cv_status::timeout) { return false; } } @@ -188,10 +188,10 @@ public: } SnapMap wait_for_snap_map(MockObjectCopyRequest &mock_object_copy_request) { - Mutex::Locker locker(mock_object_copy_request.lock); + std::unique_lock locker{mock_object_copy_request.lock}; while (mock_object_copy_request.snap_map == nullptr) { - if (mock_object_copy_request.cond.WaitInterval(mock_object_copy_request.lock, - utime_t(10, 0)) != 0) { + if (mock_object_copy_request.cond.wait_for(locker, 10s) == + std::cv_status::timeout) { return SnapMap(); } } diff --git a/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc b/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc index 883f4b46833..d4cfa7f8491 100644 --- a/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc +++ b/src/test/librbd/deep_copy/test_mock_ObjectCopyRequest.cc @@ -291,7 +291,7 @@ public: Return(true))); } else { expect.WillOnce(DoAll(WithArg<7>(Invoke([&mock_image_ctx, snap_id, state](Context *ctx) { - ceph_assert(mock_image_ctx.image_ctx->image_lock.is_locked()); + ceph_assert(ceph_mutex_is_locked(mock_image_ctx.image_ctx->image_lock)); mock_image_ctx.image_ctx->object_map->aio_update( snap_id, 0, 1, state, boost::none, {}, false, ctx); })), diff --git a/src/test/librbd/exclusive_lock/test_mock_PostAcquireRequest.cc b/src/test/librbd/exclusive_lock/test_mock_PostAcquireRequest.cc index e1b1547de4c..cd84c21fba4 100644 --- a/src/test/librbd/exclusive_lock/test_mock_PostAcquireRequest.cc +++ b/src/test/librbd/exclusive_lock/test_mock_PostAcquireRequest.cc @@ -96,7 +96,7 @@ public: } void expect_test_features(MockTestImageCtx &mock_image_ctx, uint64_t features, - RWLock &lock, bool enabled) { + ceph::shared_mutex &lock, bool enabled) { EXPECT_CALL(mock_image_ctx, test_features(features, _)) .WillOnce(Return(enabled)); } diff --git a/src/test/librbd/io/test_mock_CopyupRequest.cc b/src/test/librbd/io/test_mock_CopyupRequest.cc index d5d1ca36b86..e5659418653 100644 --- a/src/test/librbd/io/test_mock_CopyupRequest.cc +++ b/src/test/librbd/io/test_mock_CopyupRequest.cc @@ -391,7 +391,7 @@ TEST_F(TestMockIoCopyupRequest, StandardWithSnaps) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); - ictx->image_lock.get_write(); + ictx->image_lock.lock(); ictx->add_snap(cls::rbd::UserSnapshotNamespace(), "2", 2, ictx->size, ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); @@ -399,7 +399,7 @@ TEST_F(TestMockIoCopyupRequest, StandardWithSnaps) { ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); ictx->snapc = {2, {2, 1}}; - ictx->image_lock.put_write(); + ictx->image_lock.unlock(); MockTestImageCtx mock_parent_image_ctx(*ictx->parent); MockTestImageCtx mock_image_ctx(*ictx, &mock_parent_image_ctx); @@ -488,12 +488,12 @@ TEST_F(TestMockIoCopyupRequest, CopyOnReadWithSnaps) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); - ictx->image_lock.get_write(); + ictx->image_lock.lock(); ictx->add_snap(cls::rbd::UserSnapshotNamespace(), "1", 1, ictx->size, ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); ictx->snapc = {1, {1}}; - ictx->image_lock.put_write(); + ictx->image_lock.unlock(); MockTestImageCtx mock_parent_image_ctx(*ictx->parent); MockTestImageCtx mock_image_ctx(*ictx, &mock_parent_image_ctx); @@ -621,7 +621,7 @@ TEST_F(TestMockIoCopyupRequest, DeepCopyWithPostSnaps) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); - ictx->image_lock.get_write(); + ictx->image_lock.lock(); ictx->add_snap(cls::rbd::UserSnapshotNamespace(), "3", 3, ictx->size, ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); @@ -632,7 +632,7 @@ TEST_F(TestMockIoCopyupRequest, DeepCopyWithPostSnaps) { ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); ictx->snapc = {3, {3, 2, 1}}; - ictx->image_lock.put_write(); + ictx->image_lock.unlock(); MockTestImageCtx mock_parent_image_ctx(*ictx->parent); MockTestImageCtx mock_image_ctx(*ictx, &mock_parent_image_ctx); @@ -690,7 +690,7 @@ TEST_F(TestMockIoCopyupRequest, DeepCopyWithPreAndPostSnaps) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); - ictx->image_lock.get_write(); + ictx->image_lock.lock(); ictx->add_snap(cls::rbd::UserSnapshotNamespace(), "4", 4, ictx->size, ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); @@ -704,7 +704,7 @@ TEST_F(TestMockIoCopyupRequest, DeepCopyWithPreAndPostSnaps) { ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); ictx->snapc = {4, {4, 3, 2, 1}}; - ictx->image_lock.put_write(); + ictx->image_lock.unlock(); MockTestImageCtx mock_parent_image_ctx(*ictx->parent); MockTestImageCtx mock_image_ctx(*ictx, &mock_parent_image_ctx); @@ -1046,12 +1046,12 @@ TEST_F(TestMockIoCopyupRequest, CopyupError) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); - ictx->image_lock.get_write(); + ictx->image_lock.lock(); ictx->add_snap(cls::rbd::UserSnapshotNamespace(), "1", 1, ictx->size, ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, {}); ictx->snapc = {1, {1}}; - ictx->image_lock.put_write(); + ictx->image_lock.unlock(); MockTestImageCtx mock_parent_image_ctx(*ictx->parent); MockTestImageCtx mock_image_ctx(*ictx, &mock_parent_image_ctx); diff --git a/src/test/librbd/io/test_mock_ImageRequest.cc b/src/test/librbd/io/test_mock_ImageRequest.cc index 03405802851..c63e2c99540 100644 --- a/src/test/librbd/io/test_mock_ImageRequest.cc +++ b/src/test/librbd/io/test_mock_ImageRequest.cc @@ -155,7 +155,7 @@ TEST_F(TestMockIoImageRequest, AioWriteModifyTimestamp) { MockImageWriteRequest mock_aio_image_write_1(mock_image_ctx, aio_comp_1, {{0, 1}}, std::move(bl), 0, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_write_1.send(); } ASSERT_EQ(0, aio_comp_ctx_1.wait()); @@ -167,7 +167,7 @@ TEST_F(TestMockIoImageRequest, AioWriteModifyTimestamp) { MockImageWriteRequest mock_aio_image_write_2(mock_image_ctx, aio_comp_2, {{0, 1}}, std::move(bl), 0, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_write_2.send(); } ASSERT_EQ(0, aio_comp_ctx_2.wait()); @@ -209,7 +209,7 @@ TEST_F(TestMockIoImageRequest, AioReadAccessTimestamp) { MockImageReadRequest mock_aio_image_read_1(mock_image_ctx, aio_comp_1, {{0, 1}}, std::move(rr), 0, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_read_1.send(); } ASSERT_EQ(1, aio_comp_ctx_1.wait()); @@ -221,7 +221,7 @@ TEST_F(TestMockIoImageRequest, AioReadAccessTimestamp) { MockImageReadRequest mock_aio_image_read_2(mock_image_ctx, aio_comp_2, {{0, 1}}, std::move(rr), 0, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_read_2.send(); } ASSERT_EQ(1, aio_comp_ctx_2.wait()); @@ -247,7 +247,7 @@ TEST_F(TestMockIoImageRequest, PartialDiscard) { mock_image_ctx, aio_comp, {{16, 63}, {84, 100}}, ictx->discard_granularity_bytes, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_discard.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); @@ -275,7 +275,7 @@ TEST_F(TestMockIoImageRequest, TailDiscard) { {{ictx->layout.object_size - 1024, 1024}}, ictx->discard_granularity_bytes, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_discard.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); @@ -305,7 +305,7 @@ TEST_F(TestMockIoImageRequest, DiscardGranularity) { {{16, 63}, {96, 31}, {84, 100}, {ictx->layout.object_size - 33, 33}}, ictx->discard_granularity_bytes, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_discard.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); @@ -335,7 +335,7 @@ TEST_F(TestMockIoImageRequest, AioWriteJournalAppendDisabled) { MockImageWriteRequest mock_aio_image_write(mock_image_ctx, aio_comp, {{0, 1}}, std::move(bl), 0, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_write.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); @@ -363,7 +363,7 @@ TEST_F(TestMockIoImageRequest, AioDiscardJournalAppendDisabled) { MockImageDiscardRequest mock_aio_image_discard( mock_image_ctx, aio_comp, {{0, 1}}, ictx->discard_granularity_bytes, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_discard.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); @@ -391,7 +391,7 @@ TEST_F(TestMockIoImageRequest, AioFlushJournalAppendDisabled) { MockImageFlushRequest mock_aio_image_flush(mock_image_ctx, aio_comp, FLUSH_SOURCE_USER, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_flush.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); @@ -422,7 +422,7 @@ TEST_F(TestMockIoImageRequest, AioWriteSameJournalAppendDisabled) { {{0, 1}}, std::move(bl), 0, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_writesame.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); @@ -458,7 +458,7 @@ TEST_F(TestMockIoImageRequest, AioCompareAndWriteJournalAppendDisabled) { &mismatch_offset, 0, {}); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_aio_image_write.send(); } ASSERT_EQ(0, aio_comp_ctx.wait()); diff --git a/src/test/librbd/io/test_mock_ImageRequestWQ.cc b/src/test/librbd/io/test_mock_ImageRequestWQ.cc index 19b3e9465a6..c2e86b10434 100644 --- a/src/test/librbd/io/test_mock_ImageRequestWQ.cc +++ b/src/test/librbd/io/test_mock_ImageRequestWQ.cc @@ -88,10 +88,10 @@ struct ThreadPool::PointerWQ ImageDispatchSpec; static PointerWQ* s_instance; - Mutex m_lock; + ceph::mutex m_lock; PointerWQ(const std::string &name, time_t, int, ThreadPool *) - : m_lock(name) { + : m_lock(ceph::make_mutex(name)) { s_instance = this; } virtual ~PointerWQ() { @@ -113,12 +113,12 @@ struct ThreadPool::PointerWQ MockSimpleSchedulerObjectDispatch; MockSafeTimer m_mock_timer; - Mutex m_mock_timer_lock; + ceph::mutex m_mock_timer_lock = + ceph::make_mutex("TestMockIoSimpleSchedulerObjectDispatch::Mutex"); - TestMockIoSimpleSchedulerObjectDispatch() - : m_mock_timer_lock("TestMockIoSimpleSchedulerObjectDispatch::Mutex") { + TestMockIoSimpleSchedulerObjectDispatch() { MockTestImageCtx::set_timer_instance(&m_mock_timer, &m_mock_timer_lock); EXPECT_EQ(0, _rados.conf_set("rbd_io_scheduler_simple_max_delay", "1")); } @@ -80,7 +80,7 @@ struct TestMockIoSimpleSchedulerObjectDispatch : public TestMockFixture { void expect_add_timer_task(Context **timer_task) { EXPECT_CALL(m_mock_timer, add_event_at(_, _)) - .WillOnce(Invoke([timer_task](utime_t, Context *task) { + .WillOnce(Invoke([timer_task](ceph::real_clock::time_point, Context *task) { *timer_task = task; return task; })); @@ -97,7 +97,7 @@ struct TestMockIoSimpleSchedulerObjectDispatch : public TestMockFixture { } void run_timer_task(Context *timer_task) { - Mutex::Locker timer_locker(m_mock_timer_lock); + std::lock_guard timer_locker{m_mock_timer_lock}; timer_task->complete(0); } }; diff --git a/src/test/librbd/journal/test_Entries.cc b/src/test/librbd/journal/test_Entries.cc index 7ee8174b412..a79d2c0cbc8 100644 --- a/src/test/librbd/journal/test_Entries.cc +++ b/src/test/librbd/journal/test_Entries.cc @@ -23,13 +23,13 @@ public: typedef std::list Journalers; struct ReplayHandler : public journal::ReplayHandler { - Mutex lock; - Cond cond; + ceph::mutex lock = ceph::make_mutex("ReplayHandler::lock"); + ceph::condition_variable cond; bool entries_available; bool complete; ReplayHandler() - : lock("ReplayHandler::lock"), entries_available(false), complete(false) { + : entries_available(false), complete(false) { } void get() override { @@ -38,15 +38,15 @@ public: } void handle_entries_available() override { - Mutex::Locker locker(lock); + std::lock_guard locker{lock}; entries_available = true; - cond.Signal(); + cond.notify_all(); } void handle_complete(int r) override { - Mutex::Locker locker(lock); + std::lock_guard locker{lock}; complete = true; - cond.Signal(); + cond.notify_all(); } }; @@ -91,10 +91,9 @@ public: } bool wait_for_entries_available(librbd::ImageCtx *ictx) { - Mutex::Locker locker(m_replay_handler.lock); + std::unique_lock locker{m_replay_handler.lock}; while (!m_replay_handler.entries_available) { - if (m_replay_handler.cond.WaitInterval(m_replay_handler.lock, - utime_t(10, 0)) != 0) { + if (m_replay_handler.cond.wait_for(locker, 10s) == std::cv_status::timeout) { return false; } } diff --git a/src/test/librbd/journal/test_Replay.cc b/src/test/librbd/journal/test_Replay.cc index df181babfce..019eb4d5424 100644 --- a/src/test/librbd/journal/test_Replay.cc +++ b/src/test/librbd/journal/test_Replay.cc @@ -30,7 +30,7 @@ public: int when_acquired_lock(librbd::ImageCtx *ictx) { C_SaferCond lock_ctx; { - RWLock::WLocker owner_locker(ictx->owner_lock); + std::unique_lock owner_locker{ictx->owner_lock}; ictx->exclusive_lock->acquire_lock(&lock_ctx); } int r = lock_ctx.wait(); @@ -48,7 +48,7 @@ public: C_SaferCond ctx; librbd::journal::EventEntry event_entry(event); { - RWLock::RLocker owner_locker(ictx->owner_lock); + std::shared_lock owner_locker{ictx->owner_lock}; uint64_t tid = ictx->journal->append_io_event(std::move(event_entry),0, 0, true, 0); ictx->journal->wait_event(tid, &ctx); @@ -328,7 +328,7 @@ TEST_F(TestJournalReplay, SnapCreate) { ASSERT_EQ(1, current_entry); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; ASSERT_NE(CEPH_NOSNAP, ictx->get_snap_id(cls::rbd::UserSnapshotNamespace(), "snap")); } @@ -395,7 +395,7 @@ TEST_F(TestJournalReplay, SnapUnprotect) { "snap")); uint64_t snap_id; { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; snap_id = ictx->get_snap_id(cls::rbd::UserSnapshotNamespace(), "snap"); ASSERT_NE(CEPH_NOSNAP, snap_id); } @@ -450,7 +450,7 @@ TEST_F(TestJournalReplay, SnapRename) { "snap")); uint64_t snap_id; { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; snap_id = ictx->get_snap_id(cls::rbd::UserSnapshotNamespace(), "snap"); ASSERT_NE(CEPH_NOSNAP, snap_id); } @@ -478,7 +478,7 @@ TEST_F(TestJournalReplay, SnapRename) { ASSERT_EQ(0, ictx->state->refresh()); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; snap_id = ictx->get_snap_id(cls::rbd::UserSnapshotNamespace(), "snap2"); ASSERT_NE(CEPH_NOSNAP, snap_id); } @@ -563,7 +563,7 @@ TEST_F(TestJournalReplay, SnapRemove) { ASSERT_EQ(initial_entry + 2, current_entry); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; uint64_t snap_id = ictx->get_snap_id(cls::rbd::UserSnapshotNamespace(), "snap"); ASSERT_EQ(CEPH_NOSNAP, snap_id); diff --git a/src/test/librbd/journal/test_mock_OpenRequest.cc b/src/test/librbd/journal/test_mock_OpenRequest.cc index 866ab5bea83..bb07c77afad 100644 --- a/src/test/librbd/journal/test_mock_OpenRequest.cc +++ b/src/test/librbd/journal/test_mock_OpenRequest.cc @@ -5,7 +5,7 @@ #include "test/librbd/test_support.h" #include "test/librbd/mock/MockImageCtx.h" #include "test/journal/mock/MockJournaler.h" -#include "common/Mutex.h" +#include "common/ceph_mutex.h" #include "cls/journal/cls_journal_types.h" #include "librbd/journal/OpenRequest.h" #include "librbd/journal/Types.h" @@ -49,8 +49,7 @@ class TestMockJournalOpenRequest : public TestMockFixture { public: typedef OpenRequest MockOpenRequest; - TestMockJournalOpenRequest() : m_lock("m_lock") { - } + TestMockJournalOpenRequest() = default; void expect_init_journaler(::journal::MockJournaler &mock_journaler, int r) { EXPECT_CALL(mock_journaler, init(_)) @@ -88,7 +87,7 @@ public: WithArg<2>(CompleteContext(r, mock_image_ctx.image_ctx->op_work_queue)))); } - Mutex m_lock; + ceph::mutex m_lock = ceph::make_mutex("m_lock"); ImageClientMeta m_client_meta; uint64_t m_tag_tid = 0; TagData m_tag_data; diff --git a/src/test/librbd/journal/test_mock_PromoteRequest.cc b/src/test/librbd/journal/test_mock_PromoteRequest.cc index 68a627a79a8..345bcdcb1a7 100644 --- a/src/test/librbd/journal/test_mock_PromoteRequest.cc +++ b/src/test/librbd/journal/test_mock_PromoteRequest.cc @@ -33,7 +33,7 @@ struct OpenRequest { static OpenRequest *s_instance; static OpenRequest *create(MockTestImageCtx *image_ctx, ::journal::MockJournalerProxy *journaler, - Mutex *lock, ImageClientMeta *client_meta, + ceph::mutex *lock, ImageClientMeta *client_meta, uint64_t *tag_tid, journal::TagData *tag_data, Context *on_finish) { ceph_assert(s_instance != nullptr); diff --git a/src/test/librbd/journal/test_mock_Replay.cc b/src/test/librbd/journal/test_mock_Replay.cc index 8447131c97e..7f935bbcd76 100644 --- a/src/test/librbd/journal/test_mock_Replay.cc +++ b/src/test/librbd/journal/test_mock_Replay.cc @@ -117,8 +117,8 @@ MATCHER_P(CStrEq, str, "") { } ACTION_P2(NotifyInvoke, lock, cond) { - Mutex::Locker locker(*lock); - cond->Signal(); + std::lock_guard locker{*lock}; + cond->notify_all(); } ACTION_P2(CompleteAioCompletion, r, image_ctx) { @@ -138,8 +138,7 @@ public: typedef io::ImageRequest MockIoImageRequest; typedef Replay MockJournalReplay; - TestMockJournalReplay() : m_invoke_lock("m_invoke_lock") { - } + TestMockJournalReplay() = default; void expect_accept_ops(MockExclusiveLock &mock_exclusive_lock, bool accept) { EXPECT_CALL(mock_exclusive_lock, accept_ops()).WillRepeatedly( @@ -341,10 +340,8 @@ public: void wait_for_op_invoked(Context **on_finish, int r) { { - Mutex::Locker locker(m_invoke_lock); - while (*on_finish == nullptr) { - m_invoke_cond.Wait(m_invoke_lock); - } + std::unique_lock locker{m_invoke_lock}; + m_invoke_cond.wait(locker, [on_finish] { return *on_finish != nullptr; }); } (*on_finish)->complete(r); } @@ -355,8 +352,8 @@ public: return bl; } - Mutex m_invoke_lock; - Cond m_invoke_cond; + ceph::mutex m_invoke_lock = ceph::make_mutex("m_invoke_lock"); + ceph::condition_variable m_invoke_cond; }; TEST_F(TestMockJournalReplay, AioDiscard) { diff --git a/src/test/librbd/journal/test_mock_ResetRequest.cc b/src/test/librbd/journal/test_mock_ResetRequest.cc index 446acdaa8b8..57c0583eb11 100644 --- a/src/test/librbd/journal/test_mock_ResetRequest.cc +++ b/src/test/librbd/journal/test_mock_ResetRequest.cc @@ -5,7 +5,6 @@ #include "test/librbd/test_support.h" #include "test/librbd/mock/MockImageCtx.h" #include "test/journal/mock/MockJournaler.h" -#include "common/Mutex.h" #include "cls/journal/cls_journal_types.h" #include "librbd/journal/CreateRequest.h" #include "librbd/journal/RemoveRequest.h" diff --git a/src/test/librbd/mirror/test_mock_DisableRequest.cc b/src/test/librbd/mirror/test_mock_DisableRequest.cc index 5af4e1c5a99..7001c0dffc0 100644 --- a/src/test/librbd/mirror/test_mock_DisableRequest.cc +++ b/src/test/librbd/mirror/test_mock_DisableRequest.cc @@ -7,7 +7,6 @@ #include "test/librbd/mock/MockOperations.h" #include "test/librados_test_stub/MockTestMemIoCtxImpl.h" #include "test/librados_test_stub/MockTestMemRadosClient.h" -#include "common/Mutex.h" #include "librbd/MirroringWatcher.h" #include "librbd/journal/PromoteRequest.h" #include "librbd/mirror/DisableRequest.h" diff --git a/src/test/librbd/mock/MockImageCtx.cc b/src/test/librbd/mock/MockImageCtx.cc index 74062f7329a..dd8612ec900 100644 --- a/src/test/librbd/mock/MockImageCtx.cc +++ b/src/test/librbd/mock/MockImageCtx.cc @@ -5,20 +5,20 @@ #include "test/librbd/mock/MockSafeTimer.h" static MockSafeTimer *s_timer; -static Mutex *s_timer_lock; +static ceph::mutex *s_timer_lock; namespace librbd { MockImageCtx* MockImageCtx::s_instance = nullptr; void MockImageCtx::set_timer_instance(MockSafeTimer *timer, - Mutex *timer_lock) { + ceph::mutex *timer_lock) { s_timer = timer; s_timer_lock = timer_lock; } void MockImageCtx::get_timer_instance(CephContext *cct, MockSafeTimer **timer, - Mutex **timer_lock) { + ceph::mutex **timer_lock) { *timer = s_timer; *timer_lock = s_timer_lock; } diff --git a/src/test/librbd/mock/MockImageCtx.h b/src/test/librbd/mock/MockImageCtx.h index 6e46042e53b..0b8a9345c27 100644 --- a/src/test/librbd/mock/MockImageCtx.h +++ b/src/test/librbd/mock/MockImageCtx.h @@ -126,15 +126,15 @@ struct MockImageCtx { } void wait_for_async_requests() { - async_ops_lock.Lock(); + async_ops_lock.lock(); if (async_requests.empty()) { - async_ops_lock.Unlock(); + async_ops_lock.unlock(); return; } C_SaferCond ctx; async_requests_waiters.push_back(&ctx); - async_ops_lock.Unlock(); + async_ops_lock.unlock(); ctx.wait(); } @@ -190,7 +190,7 @@ struct MockImageCtx { MOCK_CONST_METHOD1(test_features, bool(uint64_t test_features)); MOCK_CONST_METHOD2(test_features, bool(uint64_t test_features, - const RWLock &in_image_lock)); + const ceph::shared_mutex &in_image_lock)); MOCK_CONST_METHOD1(test_op_features, bool(uint64_t op_features)); @@ -213,9 +213,9 @@ struct MockImageCtx { MOCK_CONST_METHOD0(get_stripe_count, uint64_t()); MOCK_CONST_METHOD0(get_stripe_period, uint64_t()); - static void set_timer_instance(MockSafeTimer *timer, Mutex *timer_lock); + static void set_timer_instance(MockSafeTimer *timer, ceph::mutex *timer_lock); static void get_timer_instance(CephContext *cct, MockSafeTimer **timer, - Mutex **timer_lock); + ceph::mutex **timer_lock); ImageCtx *image_ctx; CephContext *cct; @@ -244,11 +244,11 @@ struct MockImageCtx { librados::IoCtx md_ctx; librados::IoCtx data_ctx; - RWLock &owner_lock; - RWLock &image_lock; - RWLock ×tamp_lock; - Mutex &async_ops_lock; - Mutex ©up_list_lock; + ceph::shared_mutex &owner_lock; + ceph::shared_mutex &image_lock; + ceph::shared_mutex ×tamp_lock; + ceph::mutex &async_ops_lock; + ceph::mutex ©up_list_lock; uint8_t order; uint64_t size; diff --git a/src/test/librbd/mock/MockSafeTimer.h b/src/test/librbd/mock/MockSafeTimer.h index afece59ca31..9f6be1960e6 100644 --- a/src/test/librbd/mock/MockSafeTimer.h +++ b/src/test/librbd/mock/MockSafeTimer.h @@ -13,7 +13,7 @@ struct MockSafeTimer { } MOCK_METHOD2(add_event_after, Context*(double, Context *)); - MOCK_METHOD2(add_event_at, Context*(utime_t, Context *)); + MOCK_METHOD2(add_event_at, Context*(ceph::real_clock::time_point, Context *)); MOCK_METHOD1(cancel_event, bool(Context *)); }; diff --git a/src/test/librbd/object_map/test_mock_InvalidateRequest.cc b/src/test/librbd/object_map/test_mock_InvalidateRequest.cc index c6ecce1a28e..5cefe6fae0f 100644 --- a/src/test/librbd/object_map/test_mock_InvalidateRequest.cc +++ b/src/test/librbd/object_map/test_mock_InvalidateRequest.cc @@ -40,8 +40,8 @@ TEST_F(TestMockObjectMapInvalidateRequest, UpdatesInMemoryFlag) { .Times(0); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -66,8 +66,8 @@ TEST_F(TestMockObjectMapInvalidateRequest, UpdatesHeadOnDiskFlag) { .WillOnce(DoDefault()); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -95,8 +95,8 @@ TEST_F(TestMockObjectMapInvalidateRequest, UpdatesSnapOnDiskFlag) { .WillOnce(DoDefault()); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -116,8 +116,8 @@ TEST_F(TestMockObjectMapInvalidateRequest, SkipOnDiskUpdateWithoutLock) { .Times(0); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -140,8 +140,8 @@ TEST_F(TestMockObjectMapInvalidateRequest, IgnoresOnDiskUpdateFailure) { .WillOnce(Return(-EINVAL)); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); diff --git a/src/test/librbd/object_map/test_mock_RefreshRequest.cc b/src/test/librbd/object_map/test_mock_RefreshRequest.cc index 68997a93a83..f7dffb61eeb 100644 --- a/src/test/librbd/object_map/test_mock_RefreshRequest.cc +++ b/src/test/librbd/object_map/test_mock_RefreshRequest.cc @@ -156,7 +156,7 @@ TEST_F(TestMockObjectMapRefreshRequest, SuccessHead) { init_object_map(mock_image_ctx, &on_disk_object_map); C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockLockRequest mock_lock_request; MockRefreshRequest *req = new MockRefreshRequest( @@ -187,7 +187,7 @@ TEST_F(TestMockObjectMapRefreshRequest, SuccessSnapshot) { init_object_map(mock_image_ctx, &on_disk_object_map); C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -216,7 +216,7 @@ TEST_F(TestMockObjectMapRefreshRequest, LoadError) { init_object_map(mock_image_ctx, &on_disk_object_map); C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -247,7 +247,7 @@ TEST_F(TestMockObjectMapRefreshRequest, LoadInvalidateError) { init_object_map(mock_image_ctx, &on_disk_object_map); C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -278,7 +278,7 @@ TEST_F(TestMockObjectMapRefreshRequest, LoadCorrupt) { init_object_map(mock_image_ctx, &on_disk_object_map); C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -313,7 +313,7 @@ TEST_F(TestMockObjectMapRefreshRequest, TooSmall) { ceph::BitVector<2> small_object_map; C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -347,7 +347,7 @@ TEST_F(TestMockObjectMapRefreshRequest, TooSmallInvalidateError) { ceph::BitVector<2> small_object_map; C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -381,7 +381,7 @@ TEST_F(TestMockObjectMapRefreshRequest, TooLarge) { large_object_map.resize(on_disk_object_map.size() * 2); C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -410,7 +410,7 @@ TEST_F(TestMockObjectMapRefreshRequest, ResizeError) { ceph::BitVector<2> small_object_map; C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); @@ -442,7 +442,7 @@ TEST_F(TestMockObjectMapRefreshRequest, LargeImageError) { init_object_map(mock_image_ctx, &on_disk_object_map); C_SaferCond ctx; - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; MockRefreshRequest *req = new MockRefreshRequest( mock_image_ctx, &object_map_lock, &object_map, TEST_SNAP_ID, &ctx); diff --git a/src/test/librbd/object_map/test_mock_ResizeRequest.cc b/src/test/librbd/object_map/test_mock_ResizeRequest.cc index dfa4f7f8123..1ca85258848 100644 --- a/src/test/librbd/object_map/test_mock_ResizeRequest.cc +++ b/src/test/librbd/object_map/test_mock_ResizeRequest.cc @@ -55,7 +55,7 @@ TEST_F(TestMockObjectMapResizeRequest, UpdateInMemory) { ASSERT_EQ(0, open_image(m_image_name, &ictx)); ASSERT_EQ(0, acquire_exclusive_lock(*ictx)); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -81,7 +81,7 @@ TEST_F(TestMockObjectMapResizeRequest, UpdateHeadOnDisk) { expect_resize(ictx, CEPH_NOSNAP, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -108,7 +108,7 @@ TEST_F(TestMockObjectMapResizeRequest, UpdateSnapOnDisk) { uint64_t snap_id = ictx->snap_id; expect_resize(ictx, snap_id, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -132,7 +132,7 @@ TEST_F(TestMockObjectMapResizeRequest, UpdateOnDiskError) { expect_resize(ictx, CEPH_NOSNAP, -EINVAL); expect_invalidate(ictx); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); diff --git a/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc b/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc index 37a7ed3e7b7..74ac7732b90 100644 --- a/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc +++ b/src/test/librbd/object_map/test_mock_SnapshotCreateRequest.cc @@ -23,7 +23,7 @@ using ::testing::StrEq; class TestMockObjectMapSnapshotCreateRequest : public TestMockFixture { public: void inject_snap_info(librbd::ImageCtx *ictx, uint64_t snap_id) { - RWLock::WLocker image_locker(ictx->image_lock); + std::unique_lock image_locker{ictx->image_lock}; ictx->add_snap(cls::rbd::UserSnapshotNamespace(), "snap name", snap_id, ictx->size, ictx->parent_md, RBD_PROTECTION_STATUS_UNPROTECTED, 0, utime_t()); @@ -85,7 +85,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, Success) { ASSERT_EQ(0, open_image(m_image_name, &ictx)); ASSERT_EQ(0, acquire_exclusive_lock(*ictx)); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; uint64_t snap_id = 1; @@ -100,7 +100,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, Success) { AsyncRequest<> *request = new SnapshotCreateRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -115,7 +115,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, ReadMapError) { ASSERT_EQ(0, open_image(m_image_name, &ictx)); ASSERT_EQ(0, acquire_exclusive_lock(*ictx)); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; uint64_t snap_id = 1; @@ -127,7 +127,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, ReadMapError) { AsyncRequest<> *request = new SnapshotCreateRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -142,7 +142,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, WriteMapError) { ASSERT_EQ(0, open_image(m_image_name, &ictx)); ASSERT_EQ(0, acquire_exclusive_lock(*ictx)); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; uint64_t snap_id = 1; @@ -155,7 +155,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, WriteMapError) { AsyncRequest<> *request = new SnapshotCreateRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -170,7 +170,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, AddSnapshotError) { ASSERT_EQ(0, open_image(m_image_name, &ictx)); ASSERT_EQ(0, acquire_exclusive_lock(*ictx)); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; uint64_t snap_id = 1; @@ -184,7 +184,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, AddSnapshotError) { AsyncRequest<> *request = new SnapshotCreateRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -199,7 +199,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, FlagCleanObjects) { ASSERT_EQ(0, open_image(m_image_name, &ictx)); ASSERT_EQ(0, acquire_exclusive_lock(*ictx)); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1024); for (uint64_t i = 0; i < object_map.size(); ++i) { @@ -213,7 +213,7 @@ TEST_F(TestMockObjectMapSnapshotCreateRequest, FlagCleanObjects) { AsyncRequest<> *request = new SnapshotCreateRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); diff --git a/src/test/librbd/object_map/test_mock_SnapshotRemoveRequest.cc b/src/test/librbd/object_map/test_mock_SnapshotRemoveRequest.cc index 9e4233dfb3c..a4d79240aa0 100644 --- a/src/test/librbd/object_map/test_mock_SnapshotRemoveRequest.cc +++ b/src/test/librbd/object_map/test_mock_SnapshotRemoveRequest.cc @@ -84,14 +84,14 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, Success) { } expect_remove_map(ictx, snap_id, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; C_SaferCond cond_ctx; AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -114,14 +114,14 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, LoadMapMissing) { expect_load_map(ictx, snap_id, -ENOENT); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; C_SaferCond cond_ctx; AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -129,7 +129,7 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, LoadMapMissing) { { // shouldn't invalidate the HEAD revision when we fail to load // the already deleted snapshot - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; uint64_t flags; ASSERT_EQ(0, ictx->get_flags(CEPH_NOSNAP, &flags)); ASSERT_EQ(0U, flags & RBD_FLAG_OBJECT_MAP_INVALID); @@ -151,14 +151,14 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, LoadMapError) { expect_invalidate(ictx); expect_remove_map(ictx, snap_id, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; C_SaferCond cond_ctx; AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -179,14 +179,14 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, RemoveSnapshotMissing) { expect_remove_snapshot(ictx, -ENOENT); expect_remove_map(ictx, snap_id, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; C_SaferCond cond_ctx; AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -208,14 +208,14 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, RemoveSnapshotError) { expect_invalidate(ictx); expect_remove_map(ictx, snap_id, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; C_SaferCond cond_ctx; AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -238,14 +238,14 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, RemoveMapMissing) { } expect_remove_map(ictx, snap_id, -ENOENT); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; C_SaferCond cond_ctx; AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -268,14 +268,14 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, RemoveMapError) { } expect_remove_map(ictx, snap_id, -EINVAL); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; C_SaferCond cond_ctx; AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -293,7 +293,7 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, ScrubCleanObjects) { ASSERT_EQ(0, resize(ictx, size)); // update image objectmap for snap inherit - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1024); for (uint64_t i = 512; i < object_map.size(); ++i) { @@ -303,8 +303,8 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, ScrubCleanObjects) { C_SaferCond cond_ctx1; { librbd::ObjectMap om(*ictx, ictx->snap_id); - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; om.set_object_map(object_map); om.aio_save(&cond_ctx1); } @@ -322,8 +322,8 @@ TEST_F(TestMockObjectMapSnapshotRemoveRequest, ScrubCleanObjects) { AsyncRequest<> *request = new SnapshotRemoveRequest( *ictx, &object_map_lock, &object_map, snap_id, &cond_ctx2); { - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::WLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::unique_lock image_locker{ictx->image_lock}; request->send(); } ASSERT_EQ(0, cond_ctx2.wait()); diff --git a/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc b/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc index e27993fbe2c..92f3847ca07 100644 --- a/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc +++ b/src/test/librbd/object_map/test_mock_SnapshotRollbackRequest.cc @@ -99,7 +99,7 @@ TEST_F(TestMockObjectMapSnapshotRollbackRequest, ReadMapError) { ASSERT_EQ(0, cond_ctx.wait()); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; uint64_t flags; ASSERT_EQ(0, ictx->get_flags(snap_id, &flags)); ASSERT_NE(0U, flags & RBD_FLAG_OBJECT_MAP_INVALID); @@ -131,7 +131,7 @@ TEST_F(TestMockObjectMapSnapshotRollbackRequest, WriteMapError) { ASSERT_EQ(0, cond_ctx.wait()); { - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock image_locker{ictx->image_lock}; uint64_t flags; ASSERT_EQ(0, ictx->get_flags(snap_id, &flags)); ASSERT_EQ(0U, flags & RBD_FLAG_OBJECT_MAP_INVALID); diff --git a/src/test/librbd/object_map/test_mock_UpdateRequest.cc b/src/test/librbd/object_map/test_mock_UpdateRequest.cc index 60628c0b9f9..42b3a5360bf 100644 --- a/src/test/librbd/object_map/test_mock_UpdateRequest.cc +++ b/src/test/librbd/object_map/test_mock_UpdateRequest.cc @@ -72,7 +72,7 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateInMemory) { ASSERT_EQ(0, ictx->operations->resize(4 << ictx->order, true, no_progress)); ASSERT_EQ(0, acquire_exclusive_lock(*ictx)); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(4); for (uint64_t i = 0; i < object_map.size(); ++i) { @@ -84,8 +84,8 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateInMemory) { *ictx, &object_map_lock, &object_map, CEPH_NOSNAP, 0, object_map.size(), OBJECT_NONEXISTENT, OBJECT_EXISTS, {}, false, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); - RWLock::WLocker object_map_locker(object_map_lock); + std::shared_lock image_locker{ictx->image_lock}; + std::unique_lock object_map_locker{object_map_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -108,7 +108,8 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateHeadOnDisk) { expect_update(ictx, CEPH_NOSNAP, 0, 1, OBJECT_NONEXISTENT, OBJECT_EXISTS, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = + ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -117,8 +118,8 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateHeadOnDisk) { *ictx, &object_map_lock, &object_map, CEPH_NOSNAP, 0, object_map.size(), OBJECT_NONEXISTENT, OBJECT_EXISTS, {}, false, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); - RWLock::WLocker object_map_locker(object_map_lock); + std::shared_lock image_locker{ictx->image_lock}; + std::unique_lock object_map_locker{object_map_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -139,7 +140,8 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateSnapOnDisk) { uint64_t snap_id = ictx->snap_id; expect_update(ictx, snap_id, 0, 1, OBJECT_NONEXISTENT, OBJECT_EXISTS, 0); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = + ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -148,8 +150,8 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateSnapOnDisk) { *ictx, &object_map_lock, &object_map, snap_id, 0, object_map.size(), OBJECT_NONEXISTENT, OBJECT_EXISTS, {}, false, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); - RWLock::WLocker object_map_locker(object_map_lock); + std::shared_lock image_locker{ictx->image_lock}; + std::unique_lock object_map_locker{object_map_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -168,7 +170,7 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateOnDiskError) { -EINVAL); expect_invalidate(ictx); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -177,8 +179,8 @@ TEST_F(TestMockObjectMapUpdateRequest, UpdateOnDiskError) { *ictx, &object_map_lock, &object_map, CEPH_NOSNAP, 0, object_map.size(), OBJECT_NONEXISTENT, OBJECT_EXISTS, {}, false, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); - RWLock::WLocker object_map_locker(object_map_lock); + std::shared_lock image_locker{ictx->image_lock}; + std::unique_lock object_map_locker{object_map_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -200,7 +202,7 @@ TEST_F(TestMockObjectMapUpdateRequest, RebuildSnapOnDisk) { boost::optional(), 0); expect_unlock_exclusive_lock(*ictx); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -209,8 +211,8 @@ TEST_F(TestMockObjectMapUpdateRequest, RebuildSnapOnDisk) { *ictx, &object_map_lock, &object_map, snap_id, 0, object_map.size(), OBJECT_EXISTS_CLEAN, boost::optional(), {}, false, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); - RWLock::WLocker object_map_locker(object_map_lock); + std::shared_lock image_locker{ictx->image_lock}; + std::unique_lock object_map_locker{object_map_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -239,7 +241,7 @@ TEST_F(TestMockObjectMapUpdateRequest, BatchUpdate) { OBJECT_EXISTS, 0); expect_unlock_exclusive_lock(*ictx); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(712312); @@ -248,8 +250,8 @@ TEST_F(TestMockObjectMapUpdateRequest, BatchUpdate) { *ictx, &object_map_lock, &object_map, CEPH_NOSNAP, 0, object_map.size(), OBJECT_NONEXISTENT, OBJECT_EXISTS, {}, false, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); - RWLock::WLocker object_map_locker(object_map_lock); + std::shared_lock image_locker{ictx->image_lock}; + std::unique_lock object_map_locker{object_map_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -265,7 +267,7 @@ TEST_F(TestMockObjectMapUpdateRequest, IgnoreMissingObjectMap) { expect_update(ictx, CEPH_NOSNAP, 0, 1, OBJECT_NONEXISTENT, OBJECT_EXISTS, -ENOENT); - RWLock object_map_lock("lock"); + ceph::shared_mutex object_map_lock = ceph::make_shared_mutex("lock"); ceph::BitVector<2> object_map; object_map.resize(1); @@ -274,8 +276,8 @@ TEST_F(TestMockObjectMapUpdateRequest, IgnoreMissingObjectMap) { *ictx, &object_map_lock, &object_map, CEPH_NOSNAP, 0, object_map.size(), OBJECT_NONEXISTENT, OBJECT_EXISTS, {}, true, &cond_ctx); { - RWLock::RLocker image_locker(ictx->image_lock); - RWLock::WLocker object_map_locker(object_map_lock); + std::shared_lock image_locker{ictx->image_lock}; + std::unique_lock object_map_locker{object_map_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); diff --git a/src/test/librbd/operation/test_mock_DisableFeaturesRequest.cc b/src/test/librbd/operation/test_mock_DisableFeaturesRequest.cc index e78435869fc..a880a54afdc 100644 --- a/src/test/librbd/operation/test_mock_DisableFeaturesRequest.cc +++ b/src/test/librbd/operation/test_mock_DisableFeaturesRequest.cc @@ -339,7 +339,7 @@ TEST_F(TestMockOperationDisableFeaturesRequest, All) { MockDisableFeaturesRequest *req = new MockDisableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, features_to_disable, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -386,7 +386,7 @@ TEST_F(TestMockOperationDisableFeaturesRequest, ObjectMap) { mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_OBJECT_MAP | RBD_FEATURE_FAST_DIFF, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -430,7 +430,7 @@ TEST_F(TestMockOperationDisableFeaturesRequest, ObjectMapError) { mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_OBJECT_MAP | RBD_FEATURE_FAST_DIFF, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -473,7 +473,7 @@ TEST_F(TestMockOperationDisableFeaturesRequest, Mirroring) { MockDisableFeaturesRequest *req = new MockDisableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_JOURNALING, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -516,7 +516,7 @@ TEST_F(TestMockOperationDisableFeaturesRequest, MirroringError) { MockDisableFeaturesRequest *req = new MockDisableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_JOURNALING, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); diff --git a/src/test/librbd/operation/test_mock_EnableFeaturesRequest.cc b/src/test/librbd/operation/test_mock_EnableFeaturesRequest.cc index 1bb9bdbde1d..86458c75ac8 100644 --- a/src/test/librbd/operation/test_mock_EnableFeaturesRequest.cc +++ b/src/test/librbd/operation/test_mock_EnableFeaturesRequest.cc @@ -324,7 +324,7 @@ TEST_F(TestMockOperationEnableFeaturesRequest, All) { MockEnableFeaturesRequest *req = new MockEnableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, features_to_enable); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -376,7 +376,7 @@ TEST_F(TestMockOperationEnableFeaturesRequest, ObjectMap) { MockEnableFeaturesRequest *req = new MockEnableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_OBJECT_MAP); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -427,7 +427,7 @@ TEST_F(TestMockOperationEnableFeaturesRequest, ObjectMapError) { MockEnableFeaturesRequest *req = new MockEnableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_OBJECT_MAP); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -476,7 +476,7 @@ TEST_F(TestMockOperationEnableFeaturesRequest, SetFlagsError) { MockEnableFeaturesRequest *req = new MockEnableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_OBJECT_MAP); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -524,7 +524,7 @@ TEST_F(TestMockOperationEnableFeaturesRequest, Mirroring) { MockEnableFeaturesRequest *req = new MockEnableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_JOURNALING); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -569,7 +569,7 @@ TEST_F(TestMockOperationEnableFeaturesRequest, JournalingError) { MockEnableFeaturesRequest *req = new MockEnableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_JOURNALING); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -617,7 +617,7 @@ TEST_F(TestMockOperationEnableFeaturesRequest, MirroringError) { MockEnableFeaturesRequest *req = new MockEnableFeaturesRequest( mock_image_ctx, &cond_ctx, 0, RBD_FEATURE_JOURNALING); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); diff --git a/src/test/librbd/operation/test_mock_Request.cc b/src/test/librbd/operation/test_mock_Request.cc index df0e38d11f8..81215e1ca90 100644 --- a/src/test/librbd/operation/test_mock_Request.cc +++ b/src/test/librbd/operation/test_mock_Request.cc @@ -136,7 +136,7 @@ TEST_F(TestMockOperationRequest, SendJournalDisabled) { expect_send_op(*mock_request, 0); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_request->send(); } @@ -164,7 +164,7 @@ TEST_F(TestMockOperationRequest, SendAffectsIOJournalDisabled) { expect_is_journal_appending(mock_journal, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; mock_request->send(); } diff --git a/src/test/librbd/operation/test_mock_ResizeRequest.cc b/src/test/librbd/operation/test_mock_ResizeRequest.cc index 3cc211b36c3..95d31d1bc31 100644 --- a/src/test/librbd/operation/test_mock_ResizeRequest.cc +++ b/src/test/librbd/operation/test_mock_ResizeRequest.cc @@ -186,7 +186,7 @@ public: mock_image_ctx, &cond_ctx, new_size, allow_shrink, prog_ctx, journal_op_tid, disable_journal); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } return cond_ctx.wait(); diff --git a/src/test/librbd/operation/test_mock_SnapshotCreateRequest.cc b/src/test/librbd/operation/test_mock_SnapshotCreateRequest.cc index 64d995d43fc..52fcd080dfc 100644 --- a/src/test/librbd/operation/test_mock_SnapshotCreateRequest.cc +++ b/src/test/librbd/operation/test_mock_SnapshotCreateRequest.cc @@ -135,7 +135,7 @@ TEST_F(TestMockOperationSnapshotCreateRequest, Success) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", 0, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -165,7 +165,7 @@ TEST_F(TestMockOperationSnapshotCreateRequest, AllocateSnapIdError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", 0, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -204,7 +204,7 @@ TEST_F(TestMockOperationSnapshotCreateRequest, CreateSnapStale) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", 0, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -235,7 +235,7 @@ TEST_F(TestMockOperationSnapshotCreateRequest, CreateSnapError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", 0, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -266,7 +266,7 @@ TEST_F(TestMockOperationSnapshotCreateRequest, ReleaseSnapIdError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", 0, false); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -303,7 +303,7 @@ TEST_F(TestMockOperationSnapshotCreateRequest, SkipObjectMap) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", 0, true); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); diff --git a/src/test/librbd/operation/test_mock_SnapshotProtectRequest.cc b/src/test/librbd/operation/test_mock_SnapshotProtectRequest.cc index c583f03a91f..b2d56912ee3 100644 --- a/src/test/librbd/operation/test_mock_SnapshotProtectRequest.cc +++ b/src/test/librbd/operation/test_mock_SnapshotProtectRequest.cc @@ -78,7 +78,7 @@ TEST_F(TestMockOperationSnapshotProtectRequest, Success) { MockSnapshotProtectRequest *req = new MockSnapshotProtectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -103,7 +103,7 @@ TEST_F(TestMockOperationSnapshotProtectRequest, GetSnapIdMissing) { MockSnapshotProtectRequest *req = new MockSnapshotProtectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-ENOENT, cond_ctx.wait()); @@ -129,7 +129,7 @@ TEST_F(TestMockOperationSnapshotProtectRequest, IsSnapProtectedError) { MockSnapshotProtectRequest *req = new MockSnapshotProtectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -155,7 +155,7 @@ TEST_F(TestMockOperationSnapshotProtectRequest, SnapAlreadyProtected) { MockSnapshotProtectRequest *req = new MockSnapshotProtectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EBUSY, cond_ctx.wait()); @@ -182,7 +182,7 @@ TEST_F(TestMockOperationSnapshotProtectRequest, SetProtectionStateError) { MockSnapshotProtectRequest *req = new MockSnapshotProtectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); diff --git a/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc b/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc index 87e1f287922..3590c7c1eb8 100644 --- a/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc +++ b/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc @@ -205,7 +205,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, Success) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -248,7 +248,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, SuccessCloneParent) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -297,7 +297,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, SuccessTrash) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -362,7 +362,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, FlattenedCloneRemovesChild) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -404,7 +404,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, TrashCloneParent) { mock_image_ctx, &cond_ctx, cls::rbd::TrashSnapshotNamespace{}, "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EBUSY, cond_ctx.wait()); @@ -447,7 +447,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, SnapshotTrashAddNotSupported) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -473,7 +473,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, SnapshotTrashAddError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -503,7 +503,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, SnapshotGetError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EOPNOTSUPP, cond_ctx.wait()); @@ -540,7 +540,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, ObjectMapSnapRemoveError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -578,7 +578,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, RemoveChildParentError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-ENOENT, cond_ctx.wait()); @@ -629,7 +629,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, RemoveChildError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -673,7 +673,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, RemoveSnapError) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-ENOENT, cond_ctx.wait()); @@ -705,7 +705,7 @@ TEST_F(TestMockOperationSnapshotRemoveRequest, MissingSnap) { mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1", snap_id); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-ENOENT, cond_ctx.wait()); diff --git a/src/test/librbd/operation/test_mock_SnapshotRollbackRequest.cc b/src/test/librbd/operation/test_mock_SnapshotRollbackRequest.cc index 1727180e63d..96552c4cdb6 100644 --- a/src/test/librbd/operation/test_mock_SnapshotRollbackRequest.cc +++ b/src/test/librbd/operation/test_mock_SnapshotRollbackRequest.cc @@ -200,7 +200,7 @@ public: mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), snap_name, snap_id, snap_size, prog_ctx); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } return cond_ctx.wait(); diff --git a/src/test/librbd/operation/test_mock_SnapshotUnprotectRequest.cc b/src/test/librbd/operation/test_mock_SnapshotUnprotectRequest.cc index da344dcb964..cad664486d6 100644 --- a/src/test/librbd/operation/test_mock_SnapshotUnprotectRequest.cc +++ b/src/test/librbd/operation/test_mock_SnapshotUnprotectRequest.cc @@ -128,7 +128,7 @@ TEST_F(TestMockOperationSnapshotUnprotectRequest, Success) { MockSnapshotUnprotectRequest *req = new MockSnapshotUnprotectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -153,7 +153,7 @@ TEST_F(TestMockOperationSnapshotUnprotectRequest, GetSnapIdMissing) { MockSnapshotUnprotectRequest *req = new MockSnapshotUnprotectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-ENOENT, cond_ctx.wait()); @@ -179,7 +179,7 @@ TEST_F(TestMockOperationSnapshotUnprotectRequest, IsSnapUnprotectedError) { MockSnapshotUnprotectRequest *req = new MockSnapshotUnprotectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EBADMSG, cond_ctx.wait()); @@ -205,7 +205,7 @@ TEST_F(TestMockOperationSnapshotUnprotectRequest, SnapAlreadyUnprotected) { MockSnapshotUnprotectRequest *req = new MockSnapshotUnprotectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -234,7 +234,7 @@ TEST_F(TestMockOperationSnapshotUnprotectRequest, SetProtectionStatusError) { MockSnapshotUnprotectRequest *req = new MockSnapshotUnprotectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -267,7 +267,7 @@ TEST_F(TestMockOperationSnapshotUnprotectRequest, ChildrenExist) { MockSnapshotUnprotectRequest *req = new MockSnapshotUnprotectRequest( mock_image_ctx, &cond_ctx, cls::rbd::UserSnapshotNamespace(), "snap1"); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EBUSY, cond_ctx.wait()); diff --git a/src/test/librbd/operation/test_mock_TrimRequest.cc b/src/test/librbd/operation/test_mock_TrimRequest.cc index 39b54f9708b..cd18f1306e9 100644 --- a/src/test/librbd/operation/test_mock_TrimRequest.cc +++ b/src/test/librbd/operation/test_mock_TrimRequest.cc @@ -237,7 +237,7 @@ TEST_F(TestMockOperationTrimRequest, SuccessRemove) { MockTrimRequest *req = new MockTrimRequest( mock_image_ctx, &cond_ctx, m_image_size, 0, progress_ctx); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -296,7 +296,7 @@ TEST_F(TestMockOperationTrimRequest, SuccessCopyUp) { MockTrimRequest *req = new MockTrimRequest( mock_image_ctx, &cond_ctx, 2 * ictx->get_object_size(), 0, progress_ctx); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -329,7 +329,7 @@ TEST_F(TestMockOperationTrimRequest, SuccessBoundary) { MockTrimRequest *req = new MockTrimRequest( mock_image_ctx, &cond_ctx, ictx->get_object_size(), 1, progress_ctx); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(0, cond_ctx.wait()); @@ -381,7 +381,7 @@ TEST_F(TestMockOperationTrimRequest, RemoveError) { MockTrimRequest *req = new MockTrimRequest( mock_image_ctx, &cond_ctx, m_image_size, 0, progress_ctx); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EPERM, cond_ctx.wait()); @@ -431,7 +431,7 @@ TEST_F(TestMockOperationTrimRequest, CopyUpError) { MockTrimRequest *req = new MockTrimRequest( mock_image_ctx, &cond_ctx, 2 * ictx->get_object_size(), 0, progress_ctx); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); @@ -464,7 +464,7 @@ TEST_F(TestMockOperationTrimRequest, BoundaryError) { MockTrimRequest *req = new MockTrimRequest( mock_image_ctx, &cond_ctx, ictx->get_object_size(), 1, progress_ctx); { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; req->send(); } ASSERT_EQ(-EINVAL, cond_ctx.wait()); diff --git a/src/test/librbd/test_DeepCopy.cc b/src/test/librbd/test_DeepCopy.cc index 06494933a98..f188d01b422 100644 --- a/src/test/librbd/test_DeepCopy.cc +++ b/src/test/librbd/test_DeepCopy.cc @@ -78,8 +78,8 @@ struct TestDeepCopy : public TestFixture { dst_snap_name)); uint64_t src_size, dst_size; { - RWLock::RLocker src_locker(m_src_ictx->image_lock); - RWLock::RLocker dst_locker(m_dst_ictx->image_lock); + std::shared_lock src_locker{m_src_ictx->image_lock}; + std::shared_lock dst_locker{m_dst_ictx->image_lock}; src_size = m_src_ictx->get_image_size(m_src_ictx->snap_id); dst_size = m_dst_ictx->get_image_size(m_dst_ictx->snap_id); } @@ -87,7 +87,7 @@ struct TestDeepCopy : public TestFixture { if (m_dst_ictx->test_features(RBD_FEATURE_LAYERING)) { bool flags_set; - RWLock::RLocker dst_locker(m_dst_ictx->image_lock); + std::shared_lock dst_locker{m_dst_ictx->image_lock}; EXPECT_EQ(0, m_dst_ictx->test_flags(m_dst_ictx->snap_id, RBD_FLAG_OBJECT_MAP_INVALID, m_dst_ictx->image_lock, &flags_set)); @@ -357,7 +357,7 @@ struct TestDeepCopy : public TestFixture { void test_stress() { uint64_t initial_size, size; { - RWLock::RLocker src_locker(m_src_ictx->image_lock); + std::shared_lock src_locker{m_src_ictx->image_lock}; size = initial_size = m_src_ictx->get_image_size(CEPH_NOSNAP); } @@ -429,7 +429,7 @@ struct TestDeepCopy : public TestFixture { std::cout << "resize: " << new_size << std::endl; ASSERT_EQ(0, m_src_ictx->operations->resize(new_size, true, no_op)); { - RWLock::RLocker src_locker(m_src_ictx->image_lock); + std::shared_lock src_locker{m_src_ictx->image_lock}; size = m_src_ictx->get_image_size(CEPH_NOSNAP); } ASSERT_EQ(new_size, size); diff --git a/src/test/librbd/test_ImageWatcher.cc b/src/test/librbd/test_ImageWatcher.cc index 9343f74d78d..1351eb919ad 100644 --- a/src/test/librbd/test_ImageWatcher.cc +++ b/src/test/librbd/test_ImageWatcher.cc @@ -7,9 +7,8 @@ #include "include/rados/librados.h" #include "include/rbd/librbd.hpp" #include "common/Cond.h" +#include "common/ceph_mutex.h" #include "common/errno.h" -#include "common/Mutex.h" -#include "common/RWLock.h" #include "cls/lock/cls_lock_client.h" #include "cls/lock/cls_lock_types.h" #include "librbd/internal.h" @@ -41,7 +40,7 @@ void register_test_image_watcher() { class TestImageWatcher : public TestFixture { public: - TestImageWatcher() : m_watch_ctx(NULL), m_callback_lock("m_callback_lock") + TestImageWatcher() : m_watch_ctx(NULL) { } @@ -77,14 +76,14 @@ public: << ", " << cookie << ", " << notifier_id << std::endl; */ - Mutex::Locker l(m_parent.m_callback_lock); + std::lock_guard l{m_parent.m_callback_lock}; m_parent.m_notify_payloads[notify_op] = payload; bufferlist reply; if (m_parent.m_notify_acks.count(notify_op) > 0) { reply = m_parent.m_notify_acks[notify_op]; m_parent.m_notifies += notify_op; - m_parent.m_callback_cond.Signal(); + m_parent.m_callback_cond.notify_all(); } m_parent.m_ioctx.notify_ack(m_header_oid, notify_id, cookie, reply); @@ -133,11 +132,9 @@ public: } bool wait_for_notifies(librbd::ImageCtx &ictx) { - Mutex::Locker l(m_callback_lock); + std::unique_lock l{m_callback_lock}; while (m_notifies.size() < m_notify_acks.size()) { - int r = m_callback_cond.WaitInterval(m_callback_lock, - utime_t(10, 0)); - if (r != 0) { + if (m_callback_cond.wait_for(l, 10s) == std::cv_status::timeout) { break; } } @@ -211,35 +208,34 @@ public: AsyncRequestId m_async_request_id; - Mutex m_callback_lock; - Cond m_callback_cond; + ceph::mutex m_callback_lock = ceph::make_mutex("m_callback_lock"); + ceph::condition_variable m_callback_cond; }; struct ProgressContext : public librbd::ProgressContext { - Mutex mutex; - Cond cond; + ceph::mutex mutex = ceph::make_mutex("ProgressContext::mutex"); + ceph::condition_variable cond; bool received; uint64_t offset; uint64_t total; - ProgressContext() : mutex("ProgressContext::mutex"), received(false), + ProgressContext() : received(false), offset(0), total(0) {} int update_progress(uint64_t offset_, uint64_t total_) override { - Mutex::Locker l(mutex); + std::lock_guard l{mutex}; offset = offset_; total = total_; received = true; - cond.Signal(); + cond.notify_all(); return 0; } bool wait(librbd::ImageCtx *ictx, uint64_t offset_, uint64_t total_) { - Mutex::Locker l(mutex); + std::unique_lock l{mutex}; while (!received) { - int r = cond.WaitInterval(mutex, utime_t(10, 0)); - if (r != 0) { + if (cond.wait_for(l, 10s) == std::cv_status::timeout) { break; } } @@ -256,7 +252,7 @@ struct FlattenTask { : ictx(ictx_), progress_context(ctx), result(0) {} void operator()() { - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond ctx; ictx->image_watcher->notify_flatten(0, *progress_context, &ctx); result = ctx.wait(); @@ -272,7 +268,7 @@ struct ResizeTask { : ictx(ictx_), progress_context(ctx), result(0) {} void operator()() { - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond ctx; ictx->image_watcher->notify_resize(0, 0, true, *progress_context, &ctx); result = ctx.wait(); @@ -288,7 +284,7 @@ struct RebuildObjectMapTask { : ictx(ictx_), progress_context(ctx), result(0) {} void operator()() { - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond ctx; ictx->image_watcher->notify_rebuild_object_map(0, *progress_context, &ctx); result = ctx.wait(); @@ -428,7 +424,7 @@ TEST_F(TestImageWatcher, NotifySnapCreate) { m_notify_acks = {{NOTIFY_OP_SNAP_CREATE, create_response_message(0)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_snap_create(cls::rbd::UserSnapshotNamespace(), "snap", ¬ify_ctx); @@ -451,7 +447,7 @@ TEST_F(TestImageWatcher, NotifySnapCreateError) { m_notify_acks = {{NOTIFY_OP_SNAP_CREATE, create_response_message(-EEXIST)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_snap_create(cls::rbd::UserSnapshotNamespace(), "snap", ¬ify_ctx); @@ -474,7 +470,7 @@ TEST_F(TestImageWatcher, NotifySnapRename) { m_notify_acks = {{NOTIFY_OP_SNAP_RENAME, create_response_message(0)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_snap_rename(1, "snap-rename", ¬ify_ctx); ASSERT_EQ(0, notify_ctx.wait()); @@ -496,7 +492,7 @@ TEST_F(TestImageWatcher, NotifySnapRenameError) { m_notify_acks = {{NOTIFY_OP_SNAP_RENAME, create_response_message(-EEXIST)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_snap_rename(1, "snap-rename", ¬ify_ctx); ASSERT_EQ(-EEXIST, notify_ctx.wait()); @@ -518,7 +514,7 @@ TEST_F(TestImageWatcher, NotifySnapRemove) { m_notify_acks = {{NOTIFY_OP_SNAP_REMOVE, create_response_message(0)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_snap_remove(cls::rbd::UserSnapshotNamespace(), "snap", @@ -542,7 +538,7 @@ TEST_F(TestImageWatcher, NotifySnapProtect) { m_notify_acks = {{NOTIFY_OP_SNAP_PROTECT, create_response_message(0)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_snap_protect(cls::rbd::UserSnapshotNamespace(), "snap", @@ -566,7 +562,7 @@ TEST_F(TestImageWatcher, NotifySnapUnprotect) { m_notify_acks = {{NOTIFY_OP_SNAP_UNPROTECT, create_response_message(0)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_snap_unprotect(cls::rbd::UserSnapshotNamespace(), "snap", @@ -590,7 +586,7 @@ TEST_F(TestImageWatcher, NotifyRename) { m_notify_acks = {{NOTIFY_OP_RENAME, create_response_message(0)}}; - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; C_SaferCond notify_ctx; ictx->image_watcher->notify_rename("new_name", ¬ify_ctx); ASSERT_EQ(0, notify_ctx.wait()); diff --git a/src/test/librbd/test_Migration.cc b/src/test/librbd/test_Migration.cc index dacfdac6657..0a395cba43e 100644 --- a/src/test/librbd/test_Migration.cc +++ b/src/test/librbd/test_Migration.cc @@ -16,7 +16,7 @@ #include "librbd/internal.h" #include "librbd/io/ImageRequestWQ.h" #include "librbd/io/ReadResult.h" - +#include "common/Cond.h" #include void register_test_migration() { @@ -97,8 +97,8 @@ struct TestMigration : public TestFixture { librbd::ImageCtx *dst_ictx) { uint64_t src_size, dst_size; { - RWLock::RLocker src_locker(src_ictx->image_lock); - RWLock::RLocker dst_locker(dst_ictx->image_lock); + std::shared_lock src_locker{src_ictx->image_lock}; + std::shared_lock dst_locker{dst_ictx->image_lock}; src_size = src_ictx->get_image_size(src_ictx->snap_id); dst_size = dst_ictx->get_image_size(dst_ictx->snap_id); } @@ -109,7 +109,7 @@ struct TestMigration : public TestFixture { if (dst_ictx->test_features(RBD_FEATURE_LAYERING)) { bool flags_set; - RWLock::RLocker dst_locker(dst_ictx->image_lock); + std::shared_lock dst_locker{dst_ictx->image_lock}; EXPECT_EQ(0, dst_ictx->test_flags(dst_ictx->snap_id, RBD_FLAG_OBJECT_MAP_INVALID, dst_ictx->image_lock, &flags_set)); diff --git a/src/test/librbd/test_ObjectMap.cc b/src/test/librbd/test_ObjectMap.cc index fe309206592..c5d636559cb 100644 --- a/src/test/librbd/test_ObjectMap.cc +++ b/src/test/librbd/test_ObjectMap.cc @@ -43,7 +43,7 @@ TEST_F(TestObjectMap, RefreshInvalidatesWhenCorrupt) { C_SaferCond lock_ctx; { - RWLock::WLocker owner_locker(ictx->owner_lock); + std::unique_lock owner_locker{ictx->owner_lock}; ictx->exclusive_lock->try_acquire_lock(&lock_ctx); } ASSERT_EQ(0, lock_ctx.wait()); @@ -71,7 +71,7 @@ TEST_F(TestObjectMap, RefreshInvalidatesWhenTooSmall) { C_SaferCond lock_ctx; { - RWLock::WLocker owner_locker(ictx->owner_lock); + std::unique_lock owner_locker{ictx->owner_lock}; ictx->exclusive_lock->try_acquire_lock(&lock_ctx); } ASSERT_EQ(0, lock_ctx.wait()); @@ -100,7 +100,7 @@ TEST_F(TestObjectMap, InvalidateFlagOnDisk) { C_SaferCond lock_ctx; { - RWLock::WLocker owner_locker(ictx->owner_lock); + std::unique_lock owner_locker{ictx->owner_lock}; ictx->exclusive_lock->try_acquire_lock(&lock_ctx); } ASSERT_EQ(0, lock_ctx.wait()); @@ -139,7 +139,7 @@ TEST_F(TestObjectMap, AcquireLockInvalidatesWhenTooSmall) { C_SaferCond lock_ctx; { - RWLock::WLocker owner_locker(ictx->owner_lock); + std::unique_lock owner_locker{ictx->owner_lock}; ictx->exclusive_lock->try_acquire_lock(&lock_ctx); } ASSERT_EQ(0, lock_ctx.wait()); @@ -198,8 +198,8 @@ TEST_F(TestObjectMap, DISABLED_StressTest) { throttle.end_op(r); }); - RWLock::RLocker owner_locker(ictx->owner_lock); - RWLock::RLocker image_locker(ictx->image_lock); + std::shared_lock owner_locker{ictx->owner_lock}; + std::shared_lock image_locker{ictx->image_lock}; ASSERT_TRUE(ictx->object_map != nullptr); if (!ictx->object_map->aio_update< diff --git a/src/test/librbd/test_fixture.cc b/src/test/librbd/test_fixture.cc index e9ea63d4d24..4e9d2b6497f 100644 --- a/src/test/librbd/test_fixture.cc +++ b/src/test/librbd/test_fixture.cc @@ -139,7 +139,7 @@ int TestFixture::acquire_exclusive_lock(librbd::ImageCtx &ictx) { return r; } - RWLock::RLocker owner_locker(ictx.owner_lock); + std::shared_lock owner_locker{ictx.owner_lock}; ceph_assert(ictx.exclusive_lock != nullptr); return ictx.exclusive_lock->is_lock_owner() ? 0 : -EINVAL; } diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index 193a4d39038..84b4d1c3c29 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -21,6 +21,7 @@ #include "librbd/io/ImageRequest.h" #include "librbd/io/ImageRequestWQ.h" #include "osdc/Striper.h" +#include "common/Cond.h" #include #include #include @@ -198,7 +199,7 @@ TEST_F(TestInternal, IsExclusiveLockOwner) { C_SaferCond ctx; { - RWLock::WLocker l(ictx->owner_lock); + std::unique_lock l{ictx->owner_lock}; ictx->exclusive_lock->try_acquire_lock(&ctx); } ASSERT_EQ(0, ctx.wait()); @@ -426,13 +427,13 @@ TEST_F(TestInternal, CancelAsyncResize) { C_SaferCond ctx; { - RWLock::WLocker l(ictx->owner_lock); + std::unique_lock l{ictx->owner_lock}; ictx->exclusive_lock->try_acquire_lock(&ctx); } ASSERT_EQ(0, ctx.wait()); { - RWLock::RLocker owner_locker(ictx->owner_lock); + std::shared_lock owner_locker{ictx->owner_lock}; ASSERT_TRUE(ictx->exclusive_lock->is_lock_owner()); } @@ -446,7 +447,7 @@ TEST_F(TestInternal, CancelAsyncResize) { size -= std::min(size, 1 << 18); { - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; ictx->operations->execute_resize(size, true, prog_ctx, &ctx, 0); } @@ -469,11 +470,11 @@ TEST_F(TestInternal, MultipleResize) { if (ictx->exclusive_lock != nullptr) { C_SaferCond ctx; { - RWLock::WLocker l(ictx->owner_lock); + std::unique_lock l{ictx->owner_lock}; ictx->exclusive_lock->try_acquire_lock(&ctx); } - RWLock::RLocker owner_locker(ictx->owner_lock); + std::shared_lock owner_locker{ictx->owner_lock}; ASSERT_EQ(0, ctx.wait()); ASSERT_TRUE(ictx->exclusive_lock->is_lock_owner()); } @@ -493,7 +494,7 @@ TEST_F(TestInternal, MultipleResize) { new_size = size; } - RWLock::RLocker l(ictx->owner_lock); + std::shared_lock l{ictx->owner_lock}; contexts.push_back(new C_SaferCond()); ictx->operations->execute_resize(new_size, true, prog_ctx, contexts.back(), 0); } @@ -803,7 +804,7 @@ TEST_F(TestInternal, SnapshotCopyupZeros) object_map.open(&ctx); ASSERT_EQ(0, ctx.wait()); - RWLock::RLocker image_locker(ictx2->image_lock); + std::shared_lock image_locker{ictx2->image_lock}; ASSERT_EQ(state, object_map[0]); } } @@ -890,7 +891,7 @@ TEST_F(TestInternal, SnapshotCopyupZerosMigration) object_map.open(&ctx); ASSERT_EQ(0, ctx.wait()); - RWLock::RLocker image_locker(ictx2->image_lock); + std::shared_lock image_locker{ictx2->image_lock}; ASSERT_EQ(state, object_map[0]); } } @@ -949,7 +950,7 @@ TEST_F(TestInternal, ResizeCopyup) { // hide the parent from the snapshot - RWLock::WLocker image_locker(ictx2->image_lock); + std::unique_lock image_locker{ictx2->image_lock}; ictx2->snap_info.begin()->second.parent = librbd::ParentImageInfo(); } @@ -1016,7 +1017,7 @@ TEST_F(TestInternal, DiscardCopyup) { // hide the parent from the snapshot - RWLock::WLocker image_locker(ictx2->image_lock); + std::unique_lock image_locker{ictx2->image_lock}; ictx2->snap_info.begin()->second.parent = librbd::ParentImageInfo(); } diff --git a/src/test/librbd/test_mirroring.cc b/src/test/librbd/test_mirroring.cc index 29f734b3b7e..65c1e979d06 100644 --- a/src/test/librbd/test_mirroring.cc +++ b/src/test/librbd/test_mirroring.cc @@ -26,6 +26,7 @@ #include "librbd/api/Image.h" #include "journal/Journaler.h" #include "journal/Settings.h" +#include "common/Cond.h" #include #include #include diff --git a/src/test/librbd/test_mock_ExclusiveLock.cc b/src/test/librbd/test_mock_ExclusiveLock.cc index b867fcfc4b7..da7a63ea4fc 100644 --- a/src/test/librbd/test_mock_ExclusiveLock.cc +++ b/src/test/librbd/test_mock_ExclusiveLock.cc @@ -40,12 +40,11 @@ struct ManagedLock { const std::string& oid, librbd::MockImageWatcher *watcher, managed_lock::Mode mode, bool blacklist_on_break_lock, uint32_t blacklist_expire_seconds) - : m_lock("ManagedLock::m_lock") { - } + {} virtual ~ManagedLock() = default; - mutable Mutex m_lock; + mutable ceph::mutex m_lock = ceph::make_mutex("ManagedLock::m_lock"); virtual void shutdown_handler(int r, Context *) = 0; virtual void pre_acquire_lock_handler(Context *) = 0; @@ -294,7 +293,7 @@ public: MockExclusiveLock &exclusive_lock) { C_SaferCond ctx; { - RWLock::WLocker owner_locker(mock_image_ctx.owner_lock); + std::unique_lock owner_locker{mock_image_ctx.owner_lock}; exclusive_lock.init(mock_image_ctx.features, &ctx); } return ctx.wait(); @@ -336,7 +335,7 @@ public: MockExclusiveLock &exclusive_lock) { C_SaferCond ctx; { - RWLock::WLocker owner_locker(mock_image_ctx.owner_lock); + std::unique_lock owner_locker{mock_image_ctx.owner_lock}; exclusive_lock.shut_down(&ctx); } return ctx.wait(); @@ -344,7 +343,7 @@ public: bool is_lock_owner(MockExclusiveLockImageCtx &mock_image_ctx, MockExclusiveLock &exclusive_lock) { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; return exclusive_lock.is_lock_owner(); } }; diff --git a/src/test/librbd/test_mock_Journal.cc b/src/test/librbd/test_mock_Journal.cc index 86e31f905d7..d124b236a5d 100644 --- a/src/test/librbd/test_mock_Journal.cc +++ b/src/test/librbd/test_mock_Journal.cc @@ -8,7 +8,7 @@ #include "test/librbd/mock/MockJournalPolicy.h" #include "test/librbd/mock/io/MockObjectDispatch.h" #include "common/Cond.h" -#include "common/Mutex.h" +#include "common/ceph_mutex.h" #include "cls/journal/cls_journal_types.h" #include "journal/Journaler.h" #include "librbd/Journal.h" @@ -167,7 +167,7 @@ public: static OpenRequest *s_instance; static OpenRequest *create(MockJournalImageCtx *image_ctx, ::journal::MockJournalerProxy *journaler, - Mutex *lock, journal::ImageClientMeta *client_meta, + ceph::mutex *lock, journal::ImageClientMeta *client_meta, uint64_t *tag_tid, journal::TagData *tag_data, Context *on_finish) { ceph_assert(s_instance != nullptr); @@ -250,15 +250,13 @@ public: typedef std::function ReplayAction; typedef std::list Contexts; - TestMockJournal() : m_lock("lock") { - } - + TestMockJournal() = default; ~TestMockJournal() override { ceph_assert(m_commit_contexts.empty()); } - Mutex m_lock; - Cond m_cond; + ceph::mutex m_lock = ceph::make_mutex("lock"); + ceph::condition_variable m_cond; Contexts m_commit_contexts; struct C_ReplayAction : public Context { @@ -460,28 +458,28 @@ public: bufferlist bl; bl.append_zero(length); - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; return mock_journal.append_write_event(0, length, bl, false); } uint64_t when_append_io_event(MockJournalImageCtx &mock_image_ctx, MockJournal &mock_journal, int filter_ret_val) { - RWLock::RLocker owner_locker(mock_image_ctx.owner_lock); + std::shared_lock owner_locker{mock_image_ctx.owner_lock}; return mock_journal.append_io_event( journal::EventEntry{journal::AioFlushEvent{}}, 0, 0, false, filter_ret_val); } void save_commit_context(Context *ctx) { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; m_commit_contexts.push_back(ctx); - m_cond.Signal(); + m_cond.notify_all(); } void wake_up() { - Mutex::Locker locker(m_lock); - m_cond.Signal(); + std::lock_guard locker{m_lock}; + m_cond.notify_all(); } void commit_replay(MockJournalImageCtx &mock_image_ctx, Context *on_flush, @@ -898,10 +896,8 @@ TEST_F(TestMockJournal, ReplayOnDiskPreFlushError) { // wait for the process callback { - Mutex::Locker locker(m_lock); - while (m_commit_contexts.empty()) { - m_cond.Wait(m_lock); - } + std::unique_lock locker{m_lock}; + m_cond.wait(locker, [this] { return !m_commit_contexts.empty(); }); } on_ready->complete(0); @@ -982,18 +978,14 @@ TEST_F(TestMockJournal, ReplayOnDiskPostFlushError) { // proceed with the flush { // wait for on_flush callback - Mutex::Locker locker(m_lock); - while (on_flush == nullptr) { - m_cond.Wait(m_lock); - } + std::unique_lock locker{m_lock}; + m_cond.wait(locker, [&] {return on_flush != nullptr;}); } { // wait for the on_safe process callback - Mutex::Locker locker(m_lock); - while (m_commit_contexts.empty()) { - m_cond.Wait(m_lock); - } + std::unique_lock locker{m_lock}; + m_cond.wait(locker, [this] {return !m_commit_contexts.empty();}); } m_commit_contexts.front()->complete(-EINVAL); m_commit_contexts.clear(); @@ -1351,7 +1343,7 @@ TEST_F(TestMockJournal, AppendDisabled) { }; InSequence seq; - RWLock::RLocker image_locker(mock_image_ctx.image_lock); + std::shared_lock image_locker{mock_image_ctx.image_lock}; EXPECT_CALL(mock_image_ctx, get_journal_policy()).WillOnce( Return(ictx->get_journal_policy())); ASSERT_TRUE(mock_journal.is_journal_appending()); diff --git a/src/test/librbd/test_mock_ObjectMap.cc b/src/test/librbd/test_mock_ObjectMap.cc index 88331a82576..a96a1588a79 100644 --- a/src/test/librbd/test_mock_ObjectMap.cc +++ b/src/test/librbd/test_mock_ObjectMap.cc @@ -27,7 +27,7 @@ struct RefreshRequest { Context *on_finish = nullptr; ceph::BitVector<2u> *object_map = nullptr; static RefreshRequest *s_instance; - static RefreshRequest *create(MockTestImageCtx &image_ctx, RWLock*, + static RefreshRequest *create(MockTestImageCtx &image_ctx, ceph::shared_mutex*, ceph::BitVector<2u> *object_map, uint64_t snap_id, Context *on_finish) { ceph_assert(s_instance != nullptr); @@ -64,7 +64,7 @@ template <> struct UpdateRequest { Context *on_finish = nullptr; static UpdateRequest *s_instance; - static UpdateRequest *create(MockTestImageCtx &image_ctx, RWLock*, + static UpdateRequest *create(MockTestImageCtx &image_ctx, ceph::shared_mutex*, ceph::BitVector<2u> *object_map, uint64_t snap_id, uint64_t start_object_no, uint64_t end_object_no, @@ -180,7 +180,7 @@ TEST_F(TestMockObjectMap, NonDetainedUpdate) { C_SaferCond update_ctx1; C_SaferCond update_ctx2; { - RWLock::RLocker image_locker(mock_image_ctx.image_lock); + std::shared_lock image_locker{mock_image_ctx.image_lock}; mock_object_map.aio_update(CEPH_NOSNAP, 0, 1, {}, {}, false, &update_ctx1); mock_object_map.aio_update(CEPH_NOSNAP, 1, 1, {}, {}, false, &update_ctx2); } @@ -237,7 +237,7 @@ TEST_F(TestMockObjectMap, DetainedUpdate) { C_SaferCond update_ctx3; C_SaferCond update_ctx4; { - RWLock::RLocker image_locker(mock_image_ctx.image_lock); + std::shared_lock image_locker{mock_image_ctx.image_lock}; mock_object_map.aio_update(CEPH_NOSNAP, 1, 4, 1, {}, {}, false, &update_ctx1); mock_object_map.aio_update(CEPH_NOSNAP, 1, 3, 1, {}, {}, false, diff --git a/src/test/librbd/test_mock_Watcher.cc b/src/test/librbd/test_mock_Watcher.cc index bacbead0ff4..ce052022799 100644 --- a/src/test/librbd/test_mock_Watcher.cc +++ b/src/test/librbd/test_mock_Watcher.cc @@ -7,7 +7,7 @@ #include "test/librados_test_stub/MockTestMemIoCtxImpl.h" #include "test/librados_test_stub/MockTestMemRadosClient.h" #include "common/Cond.h" -#include "common/Mutex.h" +#include "common/ceph_mutex.h" #include "librados/AioCompletionImpl.h" #include "librbd/Watcher.h" #include "librbd/watcher/RewatchRequest.h" @@ -49,8 +49,7 @@ using ::testing::WithArgs; class TestMockWatcher : public TestMockFixture { public: - TestMockWatcher() : m_lock("TestMockWatcher::m_lock") { - } + TestMockWatcher() = default; virtual void SetUp() { TestMockFixture::SetUp(); @@ -113,15 +112,15 @@ public: librados::WatchCtx2 *m_watch_ctx = nullptr; void notify_watch() { - Mutex::Locker locker(m_lock); + std::lock_guard locker{m_lock}; ++m_watch_count; - m_cond.Signal(); + m_cond.notify_all(); } bool wait_for_watch(MockImageCtx &mock_image_ctx, size_t count) { - Mutex::Locker locker(m_lock); + std::unique_lock locker{m_lock}; while (m_watch_count < count) { - if (m_cond.WaitInterval(m_lock, utime_t(10, 0)) != 0) { + if (m_cond.wait_for(locker, 10s) == std::cv_status::timeout) { return false; } } @@ -129,8 +128,8 @@ public: return true; } - Mutex m_lock; - Cond m_cond; + ceph::mutex m_lock = ceph::make_mutex("TestMockWatcher::m_lock"); + ceph::condition_variable m_cond; size_t m_watch_count = 0; }; diff --git a/src/test/librbd/watcher/test_mock_RewatchRequest.cc b/src/test/librbd/watcher/test_mock_RewatchRequest.cc index 58069d0a201..1ff059a0ed4 100644 --- a/src/test/librbd/watcher/test_mock_RewatchRequest.cc +++ b/src/test/librbd/watcher/test_mock_RewatchRequest.cc @@ -24,9 +24,7 @@ using ::testing::WithArgs; struct TestMockWatcherRewatchRequest : public TestMockFixture { typedef RewatchRequest MockRewatchRequest; - TestMockWatcherRewatchRequest() - : m_watch_lock("watch_lock") { - } + TestMockWatcherRewatchRequest() = default; void expect_aio_watch(MockImageCtx &mock_image_ctx, int r) { librados::MockTestMemIoCtxImpl &mock_io_ctx(get_mock_io_ctx( @@ -68,7 +66,7 @@ struct TestMockWatcherRewatchRequest : public TestMockFixture { } }; - RWLock m_watch_lock; + ceph::shared_mutex m_watch_lock = ceph::make_shared_mutex("watch_lock"); WatchCtx m_watch_ctx; uint64_t m_watch_handle = 123; }; @@ -91,7 +89,7 @@ TEST_F(TestMockWatcherRewatchRequest, Success) { &m_watch_handle, &ctx); { - RWLock::WLocker watch_locker(m_watch_lock); + std::unique_lock watch_locker{m_watch_lock}; req->send(); } ASSERT_EQ(0, ctx.wait()); @@ -116,7 +114,7 @@ TEST_F(TestMockWatcherRewatchRequest, UnwatchError) { &m_watch_handle, &ctx); { - RWLock::WLocker watch_locker(m_watch_lock); + std::unique_lock watch_locker{m_watch_lock}; req->send(); } ASSERT_EQ(0, ctx.wait()); @@ -141,7 +139,7 @@ TEST_F(TestMockWatcherRewatchRequest, WatchBlacklist) { &m_watch_handle, &ctx); { - RWLock::WLocker watch_locker(m_watch_lock); + std::unique_lock watch_locker{m_watch_lock}; req->send(); } ASSERT_EQ(-EBLACKLISTED, ctx.wait()); @@ -166,7 +164,7 @@ TEST_F(TestMockWatcherRewatchRequest, WatchDNE) { &m_watch_handle, &ctx); { - RWLock::WLocker watch_locker(m_watch_lock); + std::unique_lock watch_locker{m_watch_lock}; req->send(); } ASSERT_EQ(-ENOENT, ctx.wait()); @@ -191,7 +189,7 @@ TEST_F(TestMockWatcherRewatchRequest, WatchError) { &m_watch_handle, &ctx); { - RWLock::WLocker watch_locker(m_watch_lock); + std::unique_lock watch_locker{m_watch_lock}; req->send(); } ASSERT_EQ(-EINVAL, ctx.wait()); @@ -217,7 +215,7 @@ TEST_F(TestMockWatcherRewatchRequest, InvalidWatchHandler) { &m_watch_handle, &ctx); { - RWLock::WLocker watch_locker(m_watch_lock); + std::unique_lock watch_locker{m_watch_lock}; req->send(); } -- 2.39.5