]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: moved parent image cache to its own plugin
authorJason Dillaman <dillaman@redhat.com>
Wed, 20 May 2020 20:09:53 +0000 (16:09 -0400)
committerJason Dillaman <dillaman@redhat.com>
Thu, 21 May 2020 18:50:33 +0000 (14:50 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
PendingReleaseNotes
doc/rbd/rbd-persistent-cache.rst
src/librbd/CMakeLists.txt
src/librbd/image/OpenRequest.cc
src/librbd/image/OpenRequest.h
src/librbd/plugin/ParentCache.cc [new file with mode: 0644]
src/librbd/plugin/ParentCache.h [new file with mode: 0644]
src/test/librbd/CMakeLists.txt

index a9862214da27cc42013fa76767b2325fa7aeccf7..490e58bdb5731d222b6a5f43a4573c5f99c04e9f 100644 (file)
 
   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
index 230e803945ca24f2d6abbe7e5ba55847297777b6..0bd395942838d5592a52a7836eaeedc5c940368c 100644 (file)
@@ -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
 =============================
index 57823cdbf678c49f1c08a815f74f381c13fdc05d..49952dc25cee6c2dc2cf51ec284ccf25e0f9c25c 100644 (file)
@@ -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)
index f9e7696ec2aac91d04df49de3559e244ad19ae77..9f03857770fc9091c6bb788acdff478559db2bf0 100644 (file)
@@ -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<I>::handle_init_plugin_registry(int *result) {
     return nullptr;
   }
 
-  return send_parent_cache(result);
-}
-
-template <typename I>
-Context* OpenRequest<I>::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<bool>(
-    "rbd_parent_cache_enabled");
-
-  if (m_image_ctx->child == nullptr || !parent_cache_enabled) {
-    return send_init_cache(result);
-  }
-
-  auto parent_cache = cache::ParentCacheObjectDispatch<I>::create(m_image_ctx);
-  using klass = OpenRequest<I>;
-  Context *ctx = create_context_callback<
-    klass, &klass::handle_parent_cache>(this);
-
-  parent_cache->init(ctx);
-  return nullptr;
-}
-
-template <typename I>
-Context* OpenRequest<I>::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);
 }
 
index 9241ef0b64d4ad2f9ef0a169151cd5de70ec5e14..0fe218a3982892705667b4e8ea6ee454f4ca4189 100644 (file)
@@ -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 (file)
index 0000000..b462d0e
--- /dev/null
@@ -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<librbd::ImageCtx>(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 <typename I>
+void ParentCache<I>::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<bool>(
+    "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<I>::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 <typename I>
+void ParentCache<I>::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<librbd::ImageCtx>;
diff --git a/src/librbd/plugin/ParentCache.h b/src/librbd/plugin/ParentCache.h
new file mode 100644 (file)
index 0000000..0bb639e
--- /dev/null
@@ -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 <typename ImageCtxT>
+class ParentCache : public Interface<ImageCtxT> {
+public:
+  ParentCache(CephContext* cct) : Interface<ImageCtxT>(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<librbd::ImageCtx>;
+
+#endif // CEPH_LIBRBD_PLUGIN_PARENT_CACHE_H
index 6a2e76fd1e1dfcbf18c615367720f815362f2f61..2cfd785935e02516741a4b1f8282818262242f8c 100644 (file)
@@ -142,6 +142,7 @@ target_link_libraries(unittest_librbd
   rbd_api
   rbd_internal
   rbd_types
+  ceph_immutable_object_cache_lib
   osdc
   ceph-common
   global