]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #include "ceph_ver.h" | |
5 | #include "common/dout.h" | |
6 | #include "common/errno.h" | |
7 | #include "common/PluginRegistry.h" | |
8 | #include "librbd/ImageCtx.h" | |
9 | #include "librbd/cache/WriteLogImageDispatch.h" | |
10 | #include "librbd/cache/ImageWriteback.h" | |
11 | #include "librbd/cache/Utils.h" | |
12 | #include "librbd/cache/pwl/DiscardRequest.h" | |
13 | #include "librbd/cache/pwl/InitRequest.h" | |
14 | #include "librbd/io/ImageDispatcherInterface.h" | |
15 | #include "librbd/plugin/WriteLogImageCache.h" | |
16 | ||
17 | extern "C" { | |
18 | ||
19 | const char *__ceph_plugin_version() { | |
20 | return CEPH_GIT_NICE_VER; | |
21 | } | |
22 | ||
23 | int __ceph_plugin_init(CephContext *cct, const std::string& type, | |
24 | const std::string& name) { | |
25 | auto plugin_registry = cct->get_plugin_registry(); | |
26 | return plugin_registry->add( | |
27 | type, name, new librbd::plugin::WriteLogImageCache<librbd::ImageCtx>(cct)); | |
28 | } | |
29 | ||
30 | } // extern "C" | |
31 | ||
32 | #define dout_subsys ceph_subsys_rbd | |
33 | #undef dout_prefix | |
34 | #define dout_prefix *_dout << "librbd::plugin::WriteLogImageCache: " \ | |
35 | << this << " " << __func__ << ": " | |
36 | ||
37 | namespace librbd { | |
38 | namespace plugin { | |
39 | ||
40 | template <typename I> | |
41 | void WriteLogImageCache<I>::init(I* image_ctx, Api<I>& api, | |
42 | cache::ImageWritebackInterface& image_writeback, | |
43 | PluginHookPoints& hook_points_list, | |
44 | Context* on_finish) { | |
45 | bool pwl_enabled = librbd::cache::util::is_pwl_enabled(*image_ctx); | |
46 | if (!pwl_enabled || !image_ctx->data_ctx.is_valid()) { | |
47 | on_finish->complete(0); | |
48 | return; | |
49 | } | |
50 | ||
51 | auto cct = image_ctx->cct; | |
52 | ldout(cct, 5) << dendl; | |
53 | ||
54 | auto hook_points = std::make_unique<WriteLogImageCache::HookPoints>( | |
55 | image_ctx, image_writeback, api); | |
56 | hook_points_list.emplace_back(std::move(hook_points)); | |
57 | ||
58 | on_finish->complete(0); | |
59 | } | |
60 | ||
61 | template <typename I> | |
62 | WriteLogImageCache<I>::~WriteLogImageCache() { | |
63 | } | |
64 | ||
65 | template <typename I> | |
66 | WriteLogImageCache<I>::HookPoints::HookPoints( | |
67 | I* image_ctx, cache::ImageWritebackInterface& image_writeback, | |
68 | plugin::Api<I>& plugin_api) | |
69 | : m_image_ctx(image_ctx), m_image_writeback(image_writeback), | |
70 | m_plugin_api(plugin_api) | |
71 | { | |
72 | } | |
73 | ||
74 | template <typename I> | |
75 | WriteLogImageCache<I>::HookPoints::~HookPoints() { | |
76 | } | |
77 | ||
78 | template <typename I> | |
79 | void WriteLogImageCache<I>::HookPoints::acquired_exclusive_lock( | |
80 | Context* on_finish) { | |
81 | cache::pwl::InitRequest<I> *req = cache::pwl::InitRequest<I>::create( | |
82 | *m_image_ctx, m_image_writeback, m_plugin_api, on_finish); | |
83 | req->send(); | |
84 | } | |
85 | ||
86 | template <typename I> | |
87 | void WriteLogImageCache<I>::HookPoints::prerelease_exclusive_lock( | |
88 | Context* on_finish) { | |
89 | m_image_ctx->io_image_dispatcher->shut_down_dispatch( | |
90 | io::IMAGE_DISPATCH_LAYER_WRITEBACK_CACHE, on_finish); | |
91 | } | |
92 | ||
93 | template <typename I> | |
94 | void WriteLogImageCache<I>::HookPoints::discard( | |
95 | Context* on_finish) { | |
96 | cache::pwl::DiscardRequest<I> *req = cache::pwl::DiscardRequest<I>::create( | |
97 | *m_image_ctx, m_plugin_api, on_finish); | |
98 | req->send(); | |
99 | } | |
100 | ||
101 | } // namespace plugin | |
102 | } // namespace librbd | |
103 | ||
104 | template class librbd::plugin::WriteLogImageCache<librbd::ImageCtx>; |