From 9ec1e4ec50a8ebd94a4d7f7df4eb01d63edbac2f Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 20 May 2020 16:09:53 -0400 Subject: [PATCH] librbd: moved parent image cache to its own plugin Signed-off-by: Jason Dillaman --- PendingReleaseNotes | 10 ++++ doc/rbd/rbd-persistent-cache.rst | 6 +-- src/librbd/CMakeLists.txt | 15 +++++- src/librbd/image/OpenRequest.cc | 36 --------------- src/librbd/image/OpenRequest.h | 6 --- src/librbd/plugin/ParentCache.cc | 79 ++++++++++++++++++++++++++++++++ src/librbd/plugin/ParentCache.h | 37 +++++++++++++++ src/test/librbd/CMakeLists.txt | 1 + 8 files changed, 143 insertions(+), 47 deletions(-) create mode 100644 src/librbd/plugin/ParentCache.cc create mode 100644 src/librbd/plugin/ParentCache.h diff --git a/PendingReleaseNotes b/PendingReleaseNotes index a9862214da27c..490e58bdb5731 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -385,3 +385,13 @@ or use any other convenient way to restore the schedule after the upgrade. + + +>=16.0.0 +--------- + +* librbd: The shared, read-only parent cache has been moved to a separate librbd + plugin. If the parent cache was previously in-use, you must also instruct + librbd to load the plugin by adding the following to your configuration:: + + rbd_plugins = parent_cache diff --git a/doc/rbd/rbd-persistent-cache.rst b/doc/rbd/rbd-persistent-cache.rst index 230e803945ca2..0bd395942838d 100644 --- a/doc/rbd/rbd-persistent-cache.rst +++ b/doc/rbd/rbd-persistent-cache.rst @@ -38,10 +38,10 @@ Enable RBD Shared Read-only Parent Image Cache ---------------------------------------------- To enable RBD shared read-only parent image cache, the following Ceph settings -need to added in the ``[client]`` `section`_ of your ``ceph.conf`` file. - -``rbd parent cache enabled = true`` +need to added in the ``[client]`` `section`_ of your ``ceph.conf`` file:: + rbd parent cache enabled = true + rbd plugins = parent_cache Immutable Object Cache Daemon ============================= diff --git a/src/librbd/CMakeLists.txt b/src/librbd/CMakeLists.txt index 57823cdbf678c..49952dc25cee6 100644 --- a/src/librbd/CMakeLists.txt +++ b/src/librbd/CMakeLists.txt @@ -38,7 +38,6 @@ set(librbd_internal_srcs api/Trash.cc cache/ImageWriteback.cc cache/ObjectCacherObjectDispatch.cc - cache/ParentCacheObjectDispatch.cc cache/ObjectCacherWriteback.cc cache/PassthroughImageCache.cc cache/WriteAroundObjectDispatch.cc @@ -170,6 +169,19 @@ set(librbd_internal_srcs add_custom_target(librbd_plugins) set(librbd_plugins_dir ${CEPH_INSTALL_PKGLIBDIR}/librbd) +set(rbd_plugin_parent_cache_srcs + cache/ParentCacheObjectDispatch.cc + plugin/ParentCache.cc) +add_library(librbd_plugin_parent_cache SHARED ${rbd_plugin_parent_cache_srcs}) +target_link_libraries(librbd_plugin_parent_cache PRIVATE + ceph_immutable_object_cache_lib) +set_target_properties(librbd_plugin_parent_cache PROPERTIES + OUTPUT_NAME ceph_librbd_parent_cache + VERSION 1.0.0 + SOVERSION 1) +install(TARGETS librbd_plugin_parent_cache DESTINATION ${librbd_plugins_dir}) +add_dependencies(librbd_plugins librbd_plugin_parent_cache) + if(WITH_EVENTTRACE) list(APPEND librbd_internal_srcs ../common/EventTrace.cc) endif() @@ -201,7 +213,6 @@ if(WITH_EVENTTRACE) add_dependencies(rbd_internal eventtrace_tp) endif() target_link_libraries(rbd_internal PRIVATE - ceph_immutable_object_cache_lib osdc) if(WITH_RBD_RWL) diff --git a/src/librbd/image/OpenRequest.cc b/src/librbd/image/OpenRequest.cc index f9e7696ec2aac..9f03857770fc9 100644 --- a/src/librbd/image/OpenRequest.cc +++ b/src/librbd/image/OpenRequest.cc @@ -10,7 +10,6 @@ #include "librbd/Utils.h" #include "librbd/cache/ObjectCacherObjectDispatch.h" #include "librbd/cache/WriteAroundObjectDispatch.h" -#include "librbd/cache/ParentCacheObjectDispatch.cc" #include "librbd/image/CloseRequest.h" #include "librbd/image/RefreshRequest.h" #include "librbd/image/SetSnapRequest.h" @@ -549,41 +548,6 @@ Context* OpenRequest::handle_init_plugin_registry(int *result) { return nullptr; } - return send_parent_cache(result); -} - -template -Context* OpenRequest::send_parent_cache(int *result) { - CephContext *cct = m_image_ctx->cct; - ldout(cct, 10) << __func__ << ": r=" << *result << dendl; - - bool parent_cache_enabled = m_image_ctx->config.template get_val( - "rbd_parent_cache_enabled"); - - if (m_image_ctx->child == nullptr || !parent_cache_enabled) { - return send_init_cache(result); - } - - auto parent_cache = cache::ParentCacheObjectDispatch::create(m_image_ctx); - using klass = OpenRequest; - Context *ctx = create_context_callback< - klass, &klass::handle_parent_cache>(this); - - parent_cache->init(ctx); - return nullptr; -} - -template -Context* OpenRequest::handle_parent_cache(int* result) { - CephContext *cct = m_image_ctx->cct; - ldout(cct, 10) << __func__ << ": r=" << *result << dendl; - - if (*result < 0) { - lderr(cct) << "failed to parent cache " << dendl; - send_close_image(*result); - return nullptr; - } - return send_init_cache(result); } diff --git a/src/librbd/image/OpenRequest.h b/src/librbd/image/OpenRequest.h index 9241ef0b64d4a..0fe218a398289 100644 --- a/src/librbd/image/OpenRequest.h +++ b/src/librbd/image/OpenRequest.h @@ -64,9 +64,6 @@ private: * INIT_PLUGIN_REGISTRY * | * v - * INIT_PARENT_CACHE(skip if - * | disable) - * v * INIT_CACHE * | * v @@ -129,9 +126,6 @@ private: void send_init_plugin_registry(); Context* handle_init_plugin_registry(int *result); - Context* send_parent_cache(int *result); - Context* handle_parent_cache(int *result); - Context *send_init_cache(int *result); Context *send_register_watch(int *result); diff --git a/src/librbd/plugin/ParentCache.cc b/src/librbd/plugin/ParentCache.cc new file mode 100644 index 0000000000000..b462d0e63b325 --- /dev/null +++ b/src/librbd/plugin/ParentCache.cc @@ -0,0 +1,79 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "librbd/plugin/ParentCache.h" +#include "ceph_ver.h" +#include "common/dout.h" +#include "common/errno.h" +#include "common/PluginRegistry.h" +#include "librbd/ImageCtx.h" +#include "librbd/cache/ParentCacheObjectDispatch.h" + +extern "C" { + +const char *__ceph_plugin_version() { + return CEPH_GIT_NICE_VER; +} + +int __ceph_plugin_init(CephContext *cct, const std::string& type, + const std::string& name) { + auto plugin_registry = cct->get_plugin_registry(); + return plugin_registry->add( + type, name, new librbd::plugin::ParentCache(cct)); +} + +} // extern "C" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::plugin::ParentCache: " \ + << this << " " << __func__ << ": " + +namespace librbd { +namespace plugin { + +template +void ParentCache::init(I* image_ctx, HookPoints* hook_points, + Context* on_finish) { + 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) { + on_finish->complete(0); + return; + } + + auto cct = m_image_ctx->cct; + ldout(cct, 5) << dendl; + + auto parent_cache = cache::ParentCacheObjectDispatch::create(m_image_ctx); + on_finish = new LambdaContext([this, on_finish, parent_cache](int r) { + if (r < 0) { + // the object dispatcher will handle cleanup if successfully initialized + delete parent_cache; + } + + handle_init_parent_cache(r, on_finish); + }); + parent_cache->init(on_finish); +} + +template +void ParentCache::handle_init_parent_cache(int r, Context* on_finish) { + auto cct = m_image_ctx->cct; + ldout(cct, 5) << "r=" << r << dendl; + + if (r < 0) { + lderr(cct) << "Failed to initialize parent cache object dispatch layer: " + << cpp_strerror(r) << dendl; + on_finish->complete(r); + return; + } + + on_finish->complete(0); +} + +} // namespace plugin +} // namespace librbd + +template class librbd::plugin::ParentCache; diff --git a/src/librbd/plugin/ParentCache.h b/src/librbd/plugin/ParentCache.h new file mode 100644 index 0000000000000..0bb639e3b380c --- /dev/null +++ b/src/librbd/plugin/ParentCache.h @@ -0,0 +1,37 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_PLUGIN_PARENT_CACHE_H +#define CEPH_LIBRBD_PLUGIN_PARENT_CACHE_H + +#include "librbd/plugin/Types.h" +#include "include/Context.h" + +namespace librbd { + +struct ImageCtx; + +namespace plugin { + +template +class ParentCache : public Interface { +public: + ParentCache(CephContext* cct) : Interface(cct) { + } + + void init(ImageCtxT* image_ctx, HookPoints* hook_points, + Context* on_finish) override; + +private: + ImageCtxT* m_image_ctx = nullptr; + + void handle_init_parent_cache(int r, Context* on_finish); + +}; + +} // namespace plugin +} // namespace librbd + +extern template class librbd::plugin::ParentCache; + +#endif // CEPH_LIBRBD_PLUGIN_PARENT_CACHE_H diff --git a/src/test/librbd/CMakeLists.txt b/src/test/librbd/CMakeLists.txt index 6a2e76fd1e1df..2cfd785935e02 100644 --- a/src/test/librbd/CMakeLists.txt +++ b/src/test/librbd/CMakeLists.txt @@ -142,6 +142,7 @@ target_link_libraries(unittest_librbd rbd_api rbd_internal rbd_types + ceph_immutable_object_cache_lib osdc ceph-common global -- 2.39.5