]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/PluginRegistry.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "librbd/PluginRegistry.h"
5 #include "include/Context.h"
6 #include "common/dout.h"
7 #include "librbd/cache/ImageWriteback.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/plugin/Api.h"
10 #include <boost/tokenizer.hpp>
12 #define dout_subsys ceph_subsys_rbd
14 #define dout_prefix *_dout << "librbd::PluginRegistry: " \
15 << this << " " << __func__ << ": "
20 PluginRegistry
<I
>::PluginRegistry(I
* image_ctx
)
21 : m_image_ctx(image_ctx
), m_plugin_api(std::make_unique
<plugin::Api
<I
>>()),
22 m_image_writeback(std::make_unique
<cache::ImageWriteback
<I
>>(*image_ctx
)) {
26 PluginRegistry
<I
>::~PluginRegistry() {
30 void PluginRegistry
<I
>::init(const std::string
& plugins
, Context
* on_finish
) {
31 auto cct
= m_image_ctx
->cct
;
32 auto plugin_registry
= cct
->get_plugin_registry();
34 auto gather_ctx
= new C_Gather(cct
, on_finish
);
36 boost::tokenizer
<boost::escaped_list_separator
<char>> tokenizer(plugins
);
37 for (auto token
: tokenizer
) {
38 ldout(cct
, 5) << "attempting to load plugin: " << token
<< dendl
;
40 auto ctx
= gather_ctx
->new_sub();
42 auto plugin
= dynamic_cast<plugin::Interface
<I
>*>(
43 plugin_registry
->get_with_load("librbd", "librbd_" + token
));
44 if (plugin
== nullptr) {
45 lderr(cct
) << "failed to load plugin: " << token
<< dendl
;
46 ctx
->complete(-ENOSYS
);
51 m_image_ctx
, *m_plugin_api
, *m_image_writeback
, m_plugin_hook_points
, ctx
);
54 gather_ctx
->activate();
58 void PluginRegistry
<I
>::acquired_exclusive_lock(Context
* on_finish
) {
59 auto cct
= m_image_ctx
->cct
;
60 ldout(cct
, 20) << dendl
;
62 auto gather_ctx
= new C_Gather(cct
, on_finish
);
64 for (auto &hook
: m_plugin_hook_points
) {
65 auto ctx
= gather_ctx
->new_sub();
66 hook
->acquired_exclusive_lock(ctx
);
68 gather_ctx
->activate();
72 void PluginRegistry
<I
>::prerelease_exclusive_lock(Context
* on_finish
) {
73 auto cct
= m_image_ctx
->cct
;
74 ldout(cct
, 20) << dendl
;
76 auto gather_ctx
= new C_Gather(cct
, on_finish
);
78 for (auto &hook
: m_plugin_hook_points
) {
79 auto ctx
= gather_ctx
->new_sub();
80 hook
->prerelease_exclusive_lock(ctx
);
82 gather_ctx
->activate();
86 void PluginRegistry
<I
>::discard(Context
* on_finish
) {
87 auto cct
= m_image_ctx
->cct
;
88 ldout(cct
, 20) << dendl
;
90 auto gather_ctx
= new C_Gather(cct
, on_finish
);
92 for (auto &hook
: m_plugin_hook_points
) {
93 auto ctx
= gather_ctx
->new_sub();
96 gather_ctx
->activate();
101 template class librbd::PluginRegistry
<librbd::ImageCtx
>;