From: shangdehao1 Date: Thu, 13 Jun 2019 01:08:18 +0000 (+0800) Subject: librbd: change init method of Parent cache to asynchronous X-Git-Tag: v15.1.0~2379^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=345020c063e3c464d8244d4e60e23166161acb87;p=ceph-ci.git librbd: change init method of Parent cache to asynchronous Signed-off-by: Dehao Shang --- diff --git a/src/librbd/cache/ParentCacheObjectDispatch.cc b/src/librbd/cache/ParentCacheObjectDispatch.cc index 238cf36f13c..a79168e2acf 100644 --- a/src/librbd/cache/ParentCacheObjectDispatch.cc +++ b/src/librbd/cache/ParentCacheObjectDispatch.cc @@ -28,7 +28,7 @@ namespace cache { template ParentCacheObjectDispatch::ParentCacheObjectDispatch( I* image_ctx) : m_image_ctx(image_ctx), m_cache_client(nullptr), - m_initialized(false), m_re_connecting(false), + m_initialized(false), m_connecting(false), m_lock("librbd::cache::ParentCacheObjectDispatch::m_lock") { std::string controller_path = ((CephContext*)(m_image_ctx->cct))->_conf.get_val("immutable_object_cache_sock"); @@ -50,13 +50,14 @@ void ParentCacheObjectDispatch::init() { return; } - C_SaferCond* cond = new C_SaferCond(); - Context* create_session_ctx = new FunctionContext([cond](int ret) { - cond->complete(0); + ceph_assert(m_connecting.load() == false); + m_connecting.store(true); + Context* create_session_ctx = new FunctionContext([this](int ret) { + Mutex::Locker locker(m_lock); + m_connecting.store(false); }); create_cache_session(create_session_ctx, false); - cond->wait(); m_image_ctx->io_object_dispatcher->register_object_dispatch(this); m_initialized = true; @@ -81,18 +82,18 @@ bool ParentCacheObjectDispatch::read( if (!m_cache_client->is_session_work()) { { Mutex::Locker locker(m_lock); - if (m_re_connecting.load()) { + if (m_connecting.load()) { ldout(cct, 5) << "Parent cache is re-connecting RO daemon, " << "dispatch current request to lower object layer " << dendl; return false; } - m_re_connecting.store(true); + m_connecting.store(true); } - ceph_assert(m_re_connecting.load()); + ceph_assert(m_connecting.load()); Context* on_finish = new FunctionContext([this](int ret) { - m_re_connecting.store(false); + m_connecting.store(false); }); create_cache_session(on_finish, true); diff --git a/src/librbd/cache/ParentCacheObjectDispatch.h b/src/librbd/cache/ParentCacheObjectDispatch.h index 012dcd8b88f..c41edef6239 100644 --- a/src/librbd/cache/ParentCacheObjectDispatch.h +++ b/src/librbd/cache/ParentCacheObjectDispatch.h @@ -133,7 +133,7 @@ private: ImageCtxT* m_image_ctx; CacheClient *m_cache_client; bool m_initialized; - std::atomic m_re_connecting; + std::atomic m_connecting; Mutex m_lock; }; diff --git a/src/librbd/image/OpenRequest.cc b/src/librbd/image/OpenRequest.cc index cba70212302..81b9a03b5fa 100644 --- a/src/librbd/image/OpenRequest.cc +++ b/src/librbd/image/OpenRequest.cc @@ -522,13 +522,14 @@ Context *OpenRequest::send_init_cache(int *result) { CephContext *cct = m_image_ctx->cct; if (!m_image_ctx->cache || m_image_ctx->child != nullptr) { - // enable Shared Read-only cache for parent image + // enable Parent cache for parent image bool parent_cache_enabled = m_image_ctx->config.template get_val( "rbd_parent_cache_enabled"); + if (m_image_ctx->child != nullptr && parent_cache_enabled ) { ldout(cct, 10) << this << " " << "setting up parent cache"<< dendl; - auto sro_cache = cache::ParentCacheObjectDispatch::create(m_image_ctx); - sro_cache->init(); + auto parent_cache = cache::ParentCacheObjectDispatch::create(m_image_ctx); + parent_cache->init(); } return send_register_watch(result); }