From: shangdehao1 Date: Wed, 17 Apr 2019 05:28:07 +0000 (+0800) Subject: librbd: template CacheClient at RO hook X-Git-Tag: v15.1.0~2379^2~26 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=18ab659ae4a900499a8cad7787a33fa70acb3052;p=ceph.git librbd: template CacheClient at RO hook Signed-off-by: Dehao Shang --- diff --git a/src/librbd/cache/SharedReadOnlyObjectDispatch.cc b/src/librbd/cache/SharedReadOnlyObjectDispatch.cc index 24eb72e7bb46..f2523b69e41a 100644 --- a/src/librbd/cache/SharedReadOnlyObjectDispatch.cc +++ b/src/librbd/cache/SharedReadOnlyObjectDispatch.cc @@ -19,25 +19,25 @@ #undef dout_prefix #define dout_prefix *_dout << "librbd::cache::SharedReadOnlyObjectDispatch: " \ << this << " " << __func__ << ": " -using namespace ceph::immutable_obj_cache; namespace librbd { namespace cache { -template -SharedReadOnlyObjectDispatch::SharedReadOnlyObjectDispatch( - I* image_ctx) : m_image_ctx(image_ctx) { +template +SharedReadOnlyObjectDispatch::SharedReadOnlyObjectDispatch( + I* image_ctx) : m_image_ctx(image_ctx), m_cache_client(nullptr), + m_initialzed(false) { } -template -SharedReadOnlyObjectDispatch::~SharedReadOnlyObjectDispatch() { +template +SharedReadOnlyObjectDispatch::~SharedReadOnlyObjectDispatch() { delete m_object_store; delete m_cache_client; } // TODO if connect fails, init will return error to high layer. -template -void SharedReadOnlyObjectDispatch::init() { +template +void SharedReadOnlyObjectDispatch::init() { auto cct = m_image_ctx->cct; ldout(cct, 5) << dendl; @@ -49,7 +49,9 @@ void SharedReadOnlyObjectDispatch::init() { ldout(cct, 5) << "parent image: setup SRO cache client" << dendl; std::string controller_path = ((CephContext*)cct)->_conf.get_val("immutable_object_cache_sock"); - m_cache_client = new ceph::immutable_obj_cache::CacheClient(controller_path.c_str(), m_image_ctx->cct); + if(m_cache_client == nullptr) { + m_cache_client = new C(controller_path.c_str(), m_image_ctx->cct); + } m_cache_client->run(); int ret = m_cache_client->connect(); @@ -66,17 +68,19 @@ void SharedReadOnlyObjectDispatch::init() { auto ctx = new FunctionContext([this](bool reg) { handle_register_client(reg); }); + ret = m_cache_client->register_client(ctx); if (ret >= 0) { // add ourself to the IO object dispatcher chain m_image_ctx->io_object_dispatcher->register_object_dispatch(this); + m_initialzed = true; } } } -template -bool SharedReadOnlyObjectDispatch::read( +template +bool SharedReadOnlyObjectDispatch::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, @@ -120,8 +124,8 @@ bool SharedReadOnlyObjectDispatch::read( return true; } -template -int SharedReadOnlyObjectDispatch::handle_read_cache( +template +int SharedReadOnlyObjectDispatch::handle_read_cache( const std::string file_path, uint64_t read_off, uint64_t read_len, ceph::bufferlist* read_data, io::DispatchResult* dispatch_result, Context* on_dispatched) { @@ -144,8 +148,8 @@ int SharedReadOnlyObjectDispatch::handle_read_cache( return false; } -template -int SharedReadOnlyObjectDispatch::handle_register_client(bool reg) { +template +int SharedReadOnlyObjectDispatch::handle_register_client(bool reg) { auto cct = m_image_ctx->cct; ldout(cct, 20) << dendl; @@ -156,8 +160,8 @@ int SharedReadOnlyObjectDispatch::handle_register_client(bool reg) { return 0; } -template -void SharedReadOnlyObjectDispatch::client_handle_request(std::string msg) { +template +void SharedReadOnlyObjectDispatch::client_handle_request(std::string msg) { auto cct = m_image_ctx->cct; ldout(cct, 20) << dendl; @@ -166,4 +170,4 @@ void SharedReadOnlyObjectDispatch::client_handle_request(std::string msg) { } // namespace cache } // namespace librbd -template class librbd::cache::SharedReadOnlyObjectDispatch; +template class librbd::cache::SharedReadOnlyObjectDispatch; diff --git a/src/librbd/cache/SharedReadOnlyObjectDispatch.h b/src/librbd/cache/SharedReadOnlyObjectDispatch.h index 319599627e23..4b1771a99a0a 100644 --- a/src/librbd/cache/SharedReadOnlyObjectDispatch.h +++ b/src/librbd/cache/SharedReadOnlyObjectDispatch.h @@ -10,6 +10,7 @@ #include "tools/immutable_object_cache/CacheClient.h" #include "tools/immutable_object_cache/Types.h" +using namespace ceph::immutable_obj_cache; namespace librbd { @@ -17,7 +18,7 @@ class ImageCtx; namespace cache { -template +template class SharedReadOnlyObjectDispatch : public io::ObjectDispatchInterface { public: static SharedReadOnlyObjectDispatch* create(ImageCtxT* image_ctx) { @@ -103,6 +104,13 @@ public: uint64_t journal_tid, uint64_t new_journal_tid) { } + bool get_state() { + return m_initialzed; + } + + CacheClientT *m_cache_client = nullptr; + ImageCtxT* m_image_ctx; + private: int handle_read_cache( @@ -113,15 +121,13 @@ private: int handle_register_client(bool reg); void client_handle_request(std::string msg); - ImageCtxT* m_image_ctx; - - ceph::immutable_obj_cache::CacheClient *m_cache_client = nullptr; SharedPersistentObjectCacher *m_object_store = nullptr; + bool m_initialzed; }; } // namespace cache } // namespace librbd -extern template class librbd::cache::SharedReadOnlyObjectDispatch; +extern template class librbd::cache::SharedReadOnlyObjectDispatch; #endif // CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H