From ab1c146ad6d937662098088ea4ac3ba116dd4130 Mon Sep 17 00:00:00 2001 From: shangdehao1 Date: Thu, 23 May 2019 07:01:12 +0800 Subject: [PATCH] librbd: cleanup RO cache - cleanup invalid comments - cleanup useless method and data member - fix spelling mistake - change naming from SharedReadOnlyCache to ParentCache - change file name from SharedReadOnlyObjectDispatch to ParentCacheObjectDispath Signed-off-by: Dehao Shang --- src/librbd/CMakeLists.txt | 2 +- ...spatch.cc => ParentCacheObjectDispatch.cc} | 34 +++++++------------ ...Dispatch.h => ParentCacheObjectDispatch.h} | 25 +++++++------- .../cache/SharedPersistentObjectCacher.cc | 3 +- .../cache/SharedPersistentObjectCacher.h | 2 -- src/librbd/image/OpenRequest.cc | 4 +-- src/librbd/io/Types.h | 2 +- .../cache/test_mock_ParentImageCache.cc | 16 ++++----- 8 files changed, 38 insertions(+), 50 deletions(-) rename src/librbd/cache/{SharedReadOnlyObjectDispatch.cc => ParentCacheObjectDispatch.cc} (81%) rename src/librbd/cache/{SharedReadOnlyObjectDispatch.h => ParentCacheObjectDispatch.h} (82%) diff --git a/src/librbd/CMakeLists.txt b/src/librbd/CMakeLists.txt index 4150ef604d8..ca82d11b0f7 100644 --- a/src/librbd/CMakeLists.txt +++ b/src/librbd/CMakeLists.txt @@ -36,7 +36,7 @@ set(librbd_internal_srcs api/Trash.cc cache/ImageWriteback.cc cache/ObjectCacherObjectDispatch.cc - cache/SharedReadOnlyObjectDispatch.cc + cache/ParentCacheObjectDispatch.cc cache/SharedPersistentObjectCacher.cc cache/ObjectCacherWriteback.cc cache/PassthroughImageCache.cc diff --git a/src/librbd/cache/SharedReadOnlyObjectDispatch.cc b/src/librbd/cache/ParentCacheObjectDispatch.cc similarity index 81% rename from src/librbd/cache/SharedReadOnlyObjectDispatch.cc rename to src/librbd/cache/ParentCacheObjectDispatch.cc index d763439e3ea..251e8b5505e 100644 --- a/src/librbd/cache/SharedReadOnlyObjectDispatch.cc +++ b/src/librbd/cache/ParentCacheObjectDispatch.cc @@ -8,7 +8,7 @@ #include "librbd/io/ObjectDispatchSpec.h" #include "librbd/io/ObjectDispatcher.h" #include "librbd/io/Utils.h" -#include "librbd/cache/SharedReadOnlyObjectDispatch.h" +#include "librbd/cache/ParentCacheObjectDispatch.h" #include "osd/osd_types.h" #include "osdc/WritebackHandler.h" @@ -16,27 +16,27 @@ #define dout_subsys ceph_subsys_rbd #undef dout_prefix -#define dout_prefix *_dout << "librbd::cache::SharedReadOnlyObjectDispatch: " \ +#define dout_prefix *_dout << "librbd::cache::ParentCacheObjectDispatch: " \ << this << " " << __func__ << ": " namespace librbd { namespace cache { template -SharedReadOnlyObjectDispatch::SharedReadOnlyObjectDispatch( +ParentCacheObjectDispatch::ParentCacheObjectDispatch( I* image_ctx) : m_image_ctx(image_ctx), m_cache_client(nullptr), - m_initialzed(false), m_object_store(nullptr) { + m_initialized(false), m_object_store(nullptr) { } template -SharedReadOnlyObjectDispatch::~SharedReadOnlyObjectDispatch() { +ParentCacheObjectDispatch::~ParentCacheObjectDispatch() { delete m_object_store; delete m_cache_client; } // TODO if connect fails, init will return error to high layer. template -void SharedReadOnlyObjectDispatch::init() { +void ParentCacheObjectDispatch::init() { auto cct = m_image_ctx->cct; ldout(cct, 5) << dendl; @@ -73,13 +73,13 @@ void SharedReadOnlyObjectDispatch::init() { if (ret >= 0) { // add ourself to the IO object dispatcher chain m_image_ctx->io_object_dispatcher->register_object_dispatch(this); - m_initialzed = true; + m_initialized = true; } } } template -bool SharedReadOnlyObjectDispatch::read( +bool ParentCacheObjectDispatch::read( const std::string &oid, uint64_t object_no, uint64_t object_off, uint64_t object_len, librados::snap_t snap_id, int op_flags, const ZTracer::Trace &parent_trace, ceph::bufferlist* read_data, @@ -91,8 +91,8 @@ bool SharedReadOnlyObjectDispatch::read( << object_len << dendl; // if any failse, reads will go to rados - if(!m_cache_client->is_session_work() || m_cache_client == nullptr || - m_object_store == nullptr || !m_initialzed) { + if(m_cache_client == nullptr || !m_cache_client->is_session_work() || + m_object_store == nullptr || !m_initialized) { ldout(cct, 5) << "SRO cache client session failed " << dendl; return false; } @@ -112,7 +112,7 @@ bool SharedReadOnlyObjectDispatch::read( } template -void SharedReadOnlyObjectDispatch::handle_read_cache( +void ParentCacheObjectDispatch::handle_read_cache( ObjectCacheRequest* ack, uint64_t read_off, uint64_t read_len, ceph::bufferlist* read_data, io::DispatchResult* dispatch_result, Context* on_dispatched) { @@ -139,12 +139,11 @@ void SharedReadOnlyObjectDispatch::handle_read_cache( } *dispatch_result = io::DISPATCH_RESULT_COMPLETE; - //TODO(): complete in syncfile on_dispatched->complete(r); } template -int SharedReadOnlyObjectDispatch::handle_register_client(bool reg) { +int ParentCacheObjectDispatch::handle_register_client(bool reg) { auto cct = m_image_ctx->cct; ldout(cct, 20) << dendl; @@ -155,14 +154,7 @@ int SharedReadOnlyObjectDispatch::handle_register_client(bool reg) { return 0; } -template -void SharedReadOnlyObjectDispatch::client_handle_request(std::string msg) { - auto cct = m_image_ctx->cct; - ldout(cct, 20) << dendl; - -} - } // namespace cache } // namespace librbd -template class librbd::cache::SharedReadOnlyObjectDispatch; +template class librbd::cache::ParentCacheObjectDispatch; diff --git a/src/librbd/cache/SharedReadOnlyObjectDispatch.h b/src/librbd/cache/ParentCacheObjectDispatch.h similarity index 82% rename from src/librbd/cache/SharedReadOnlyObjectDispatch.h rename to src/librbd/cache/ParentCacheObjectDispatch.h index cd1d566c332..5a10d5754e9 100644 --- a/src/librbd/cache/SharedReadOnlyObjectDispatch.h +++ b/src/librbd/cache/ParentCacheObjectDispatch.h @@ -1,8 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#ifndef CEPH_LIBRBD_CACHE_SHARED_PERSISTENT_OBJECT_CACHER_OBJECT_DISPATCH_H -#define CEPH_LIBRBD_CACHE_SHARED_PERSISTENT_OBJECT_CACHER_OBJECT_DISPATCH_H +#ifndef CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H +#define CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H #include "common/Mutex.h" #include "SharedPersistentObjectCacher.h" @@ -19,17 +19,17 @@ class ImageCtx; namespace cache { template -class SharedReadOnlyObjectDispatch : public io::ObjectDispatchInterface { +class ParentCacheObjectDispatch : public io::ObjectDispatchInterface { public: - static SharedReadOnlyObjectDispatch* create(ImageCtxT* image_ctx) { - return new SharedReadOnlyObjectDispatch(image_ctx); + static ParentCacheObjectDispatch* create(ImageCtxT* image_ctx) { + return new ParentCacheObjectDispatch(image_ctx); } - SharedReadOnlyObjectDispatch(ImageCtxT* image_ctx); - ~SharedReadOnlyObjectDispatch() override; + ParentCacheObjectDispatch(ImageCtxT* image_ctx); + ~ParentCacheObjectDispatch() override; io::ObjectDispatchLayer get_object_dispatch_layer() const override { - return io::OBJECT_DISPATCH_LAYER_SHARED_PERSISTENT_CACHE; + return io::OBJECT_DISPATCH_LAYER_PARENT_CACHE; } void init(); @@ -105,7 +105,7 @@ public: } bool get_state() { - return m_initialzed; + return m_initialized; } CacheClientT *m_cache_client = nullptr; @@ -119,15 +119,14 @@ private: io::DispatchResult* dispatch_result, Context* on_dispatched); int handle_register_client(bool reg); - void client_handle_request(std::string msg); SharedPersistentObjectCacher *m_object_store = nullptr; - bool m_initialzed; + bool m_initialized; }; } // namespace cache } // namespace librbd -extern template class librbd::cache::SharedReadOnlyObjectDispatch; +extern template class librbd::cache::ParentCacheObjectDispatch; -#endif // CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H +#endif // CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H diff --git a/src/librbd/cache/SharedPersistentObjectCacher.cc b/src/librbd/cache/SharedPersistentObjectCacher.cc index ac0bbf50969..3abc4df3606 100644 --- a/src/librbd/cache/SharedPersistentObjectCacher.cc +++ b/src/librbd/cache/SharedPersistentObjectCacher.cc @@ -16,8 +16,7 @@ namespace cache { template SharedPersistentObjectCacher::SharedPersistentObjectCacher(I *image_ctx, std::string cache_path) - : m_image_ctx(image_ctx), m_cache_path(cache_path), - m_file_map_lock("librbd::cache::SharedObjectCacher::filemaplock") { + : m_image_ctx(image_ctx) { auto *cct = m_image_ctx->cct; ldout(cct, 20) << dendl; } diff --git a/src/librbd/cache/SharedPersistentObjectCacher.h b/src/librbd/cache/SharedPersistentObjectCacher.h index f9f7fc245d3..c7457000d31 100644 --- a/src/librbd/cache/SharedPersistentObjectCacher.h +++ b/src/librbd/cache/SharedPersistentObjectCacher.h @@ -30,8 +30,6 @@ public: private: ImageCtxT *m_image_ctx; - std::string m_cache_path; - Mutex m_file_map_lock; }; } // namespace cache diff --git a/src/librbd/image/OpenRequest.cc b/src/librbd/image/OpenRequest.cc index f4cf7a7bf63..83d94cf36b9 100644 --- a/src/librbd/image/OpenRequest.cc +++ b/src/librbd/image/OpenRequest.cc @@ -9,7 +9,7 @@ #include "librbd/Utils.h" #include "librbd/cache/ObjectCacherObjectDispatch.h" #include "librbd/cache/WriteAroundObjectDispatch.h" -#include "librbd/cache/SharedReadOnlyObjectDispatch.cc" +#include "librbd/cache/ParentCacheObjectDispatch.cc" #include "librbd/image/CloseRequest.h" #include "librbd/image/RefreshRequest.h" #include "librbd/image/SetSnapRequest.h" @@ -525,7 +525,7 @@ Context *OpenRequest::send_init_cache(int *result) { // enable Shared Read-only cache for parent image if (m_image_ctx->child != nullptr && m_image_ctx->parent_cache_enabled ) { ldout(cct, 10) << this << " " << "setting up parent cache"<< dendl; - auto sro_cache = cache::SharedReadOnlyObjectDispatch::create(m_image_ctx); + auto sro_cache = cache::ParentCacheObjectDispatch::create(m_image_ctx); sro_cache->init(); } return send_register_watch(result); diff --git a/src/librbd/io/Types.h b/src/librbd/io/Types.h index 69605433c56..53c8f4d74f7 100644 --- a/src/librbd/io/Types.h +++ b/src/librbd/io/Types.h @@ -61,7 +61,7 @@ enum ObjectDispatchLayer { OBJECT_DISPATCH_LAYER_NONE = 0, OBJECT_DISPATCH_LAYER_CACHE, OBJECT_DISPATCH_LAYER_JOURNAL, - OBJECT_DISPATCH_LAYER_SHARED_PERSISTENT_CACHE, + OBJECT_DISPATCH_LAYER_PARENT_CACHE, OBJECT_DISPATCH_LAYER_SCHEDULER, OBJECT_DISPATCH_LAYER_CORE, OBJECT_DISPATCH_LAYER_LAST diff --git a/src/test/librbd/cache/test_mock_ParentImageCache.cc b/src/test/librbd/cache/test_mock_ParentImageCache.cc index 68e53e58061..d37e48e2ed4 100644 --- a/src/test/librbd/cache/test_mock_ParentImageCache.cc +++ b/src/test/librbd/cache/test_mock_ParentImageCache.cc @@ -9,7 +9,7 @@ #include "include/Context.h" #include "tools/immutable_object_cache/CacheClient.h" #include "test/immutable_object_cache/MockCacheDaemon.h" -#include "librbd/cache/SharedReadOnlyObjectDispatch.h" +#include "librbd/cache/ParentCacheObjectDispatch.h" #include "librbd/cache/SharedPersistentObjectCacher.h" #include "test/librbd/test_mock_fixture.h" #include "test/librbd/mock/MockImageCtx.h" @@ -33,9 +33,9 @@ struct MockParentImageCacheImageCtx : public MockImageCtx { }; -#include "librbd/cache/SharedReadOnlyObjectDispatch.cc" +#include "librbd/cache/ParentCacheObjectDispatch.cc" #include "librbd/cache/SharedPersistentObjectCacher.cc" -template class librbd::cache::SharedReadOnlyObjectDispatch; +template class librbd::cache::ParentCacheObjectDispatch; template class librbd::cache::SharedPersistentObjectCacher; namespace librbd { @@ -50,7 +50,7 @@ using ::testing::WithArgs; class TestMockParentImageCache : public TestMockFixture { public : - typedef cache::SharedReadOnlyObjectDispatch MockParentImageCache; + typedef cache::ParentCacheObjectDispatch MockParentImageCache; // ====== mock cache client ==== void expect_cache_run(MockParentImageCache& mparent_image_cache, bool ret_val) { @@ -150,7 +150,7 @@ TEST_F(TestMockParentImageCache, test_initialization_success) { mock_parent_image_cache->init(); ASSERT_EQ(mock_parent_image_cache->get_object_dispatch_layer(), - io::OBJECT_DISPATCH_LAYER_SHARED_PERSISTENT_CACHE); + io::OBJECT_DISPATCH_LAYER_PARENT_CACHE); ASSERT_EQ(mock_parent_image_cache->get_state(), true); ASSERT_EQ(mock_parent_image_cache->m_cache_client->is_session_work(), true); @@ -179,7 +179,7 @@ TEST_F(TestMockParentImageCache, test_initialization_fail_at_connect) { // initialization fails. ASSERT_EQ(mock_parent_image_cache->get_object_dispatch_layer(), - io::OBJECT_DISPATCH_LAYER_SHARED_PERSISTENT_CACHE); + io::OBJECT_DISPATCH_LAYER_PARENT_CACHE); ASSERT_EQ(mock_parent_image_cache->get_state(), false); ASSERT_EQ(mock_parent_image_cache->m_cache_client->is_session_work(), false); @@ -212,7 +212,7 @@ TEST_F(TestMockParentImageCache, test_initialization_fail_at_register) { mock_parent_image_cache->init(); ASSERT_EQ(mock_parent_image_cache->get_object_dispatch_layer(), - io::OBJECT_DISPATCH_LAYER_SHARED_PERSISTENT_CACHE); + io::OBJECT_DISPATCH_LAYER_PARENT_CACHE); ASSERT_EQ(mock_parent_image_cache->get_state(), false); ASSERT_EQ(mock_parent_image_cache->m_cache_client->is_session_work(), false); @@ -288,7 +288,7 @@ TEST_F(TestMockParentImageCache, test_read) { mock_parent_image_cache->init(); ASSERT_EQ(mock_parent_image_cache->get_object_dispatch_layer(), - io::OBJECT_DISPATCH_LAYER_SHARED_PERSISTENT_CACHE); + io::OBJECT_DISPATCH_LAYER_PARENT_CACHE); ASSERT_EQ(mock_parent_image_cache->get_state(), true); ASSERT_EQ(mock_parent_image_cache->m_cache_client->is_session_work(), true); -- 2.39.5