From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/librbd/PluginRegistry.cc | 101 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/librbd/PluginRegistry.cc (limited to 'src/librbd/PluginRegistry.cc') diff --git a/src/librbd/PluginRegistry.cc b/src/librbd/PluginRegistry.cc new file mode 100644 index 000000000..6ddf0a414 --- /dev/null +++ b/src/librbd/PluginRegistry.cc @@ -0,0 +1,101 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "librbd/PluginRegistry.h" +#include "include/Context.h" +#include "common/dout.h" +#include "librbd/cache/ImageWriteback.h" +#include "librbd/ImageCtx.h" +#include "librbd/plugin/Api.h" +#include + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::PluginRegistry: " \ + << this << " " << __func__ << ": " + +namespace librbd { + +template +PluginRegistry::PluginRegistry(I* image_ctx) + : m_image_ctx(image_ctx), m_plugin_api(std::make_unique>()), + m_image_writeback(std::make_unique>(*image_ctx)) { +} + +template +PluginRegistry::~PluginRegistry() { +} + +template +void PluginRegistry::init(const std::string& plugins, Context* on_finish) { + auto cct = m_image_ctx->cct; + auto plugin_registry = cct->get_plugin_registry(); + + auto gather_ctx = new C_Gather(cct, on_finish); + + boost::tokenizer> tokenizer(plugins); + for (auto token : tokenizer) { + ldout(cct, 5) << "attempting to load plugin: " << token << dendl; + + auto ctx = gather_ctx->new_sub(); + + auto plugin = dynamic_cast*>( + plugin_registry->get_with_load("librbd", "librbd_" + token)); + if (plugin == nullptr) { + lderr(cct) << "failed to load plugin: " << token << dendl; + ctx->complete(-ENOSYS); + break; + } + + plugin->init( + m_image_ctx, *m_plugin_api, *m_image_writeback, m_plugin_hook_points, ctx); + } + + gather_ctx->activate(); +} + +template +void PluginRegistry::acquired_exclusive_lock(Context* on_finish) { + auto cct = m_image_ctx->cct; + ldout(cct, 20) << dendl; + + auto gather_ctx = new C_Gather(cct, on_finish); + + for (auto &hook : m_plugin_hook_points) { + auto ctx = gather_ctx->new_sub(); + hook->acquired_exclusive_lock(ctx); + } + gather_ctx->activate(); +} + +template +void PluginRegistry::prerelease_exclusive_lock(Context* on_finish) { + auto cct = m_image_ctx->cct; + ldout(cct, 20) << dendl; + + auto gather_ctx = new C_Gather(cct, on_finish); + + for (auto &hook : m_plugin_hook_points) { + auto ctx = gather_ctx->new_sub(); + hook->prerelease_exclusive_lock(ctx); + } + gather_ctx->activate(); +} + +template +void PluginRegistry::discard(Context* on_finish) { + auto cct = m_image_ctx->cct; + ldout(cct, 20) << dendl; + + auto gather_ctx = new C_Gather(cct, on_finish); + + for (auto &hook : m_plugin_hook_points) { + auto ctx = gather_ctx->new_sub(); + hook->discard(ctx); + } + gather_ctx->activate(); +} + +} // namespace librbd + +template class librbd::PluginRegistry; -- cgit v1.2.3