From ad1016b014d4c33dee3be66376bf9f3394160501 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 21 Sep 2020 14:05:17 -0400 Subject: [PATCH] librbd: skip cache initialization if data IoCtx is invalid This resolves the potential for an assertion failure in the cache constructors that occurs when the data IoCtx is not valid. Errors are deferred until actual IOs are issued against the invalid data pool. Signed-off-by: Jason Dillaman --- src/librbd/image/OpenRequest.cc | 4 ++-- src/librbd/plugin/ParentCache.cc | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librbd/image/OpenRequest.cc b/src/librbd/image/OpenRequest.cc index 046d37d4ba7ca..9b8e098108339 100644 --- a/src/librbd/image/OpenRequest.cc +++ b/src/librbd/image/OpenRequest.cc @@ -558,8 +558,8 @@ Context* OpenRequest::handle_init_plugin_registry(int *result) { template Context *OpenRequest::send_init_cache(int *result) { - // cache is disabled or parent image context - if (!m_image_ctx->cache || m_image_ctx->child != nullptr) { + if (!m_image_ctx->cache || m_image_ctx->child != nullptr || + !m_image_ctx->data_ctx.is_valid()) { return send_register_watch(result); } diff --git a/src/librbd/plugin/ParentCache.cc b/src/librbd/plugin/ParentCache.cc index 9e1197933f59e..0c50c8e719705 100644 --- a/src/librbd/plugin/ParentCache.cc +++ b/src/librbd/plugin/ParentCache.cc @@ -38,7 +38,8 @@ void ParentCache::init(I* image_ctx, Api& api, HookPoints* hook_points, m_image_ctx = image_ctx; bool parent_cache_enabled = m_image_ctx->config.template get_val( "rbd_parent_cache_enabled"); - if (m_image_ctx->child == nullptr || !parent_cache_enabled) { + if (m_image_ctx->child == nullptr || !parent_cache_enabled || + !m_image_ctx->data_ctx.is_valid()) { on_finish->complete(0); return; } -- 2.39.5