// -*- 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;