]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/plugin/WriteLogImageCache.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / plugin / WriteLogImageCache.cc
CommitLineData
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
17extern "C" {
18
19const char *__ceph_plugin_version() {
20 return CEPH_GIT_NICE_VER;
21}
22
23int __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
37namespace librbd {
38namespace plugin {
39
40template <typename I>
41void 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
61template <typename I>
62WriteLogImageCache<I>::~WriteLogImageCache() {
63}
64
65template <typename I>
66WriteLogImageCache<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
74template <typename I>
75WriteLogImageCache<I>::HookPoints::~HookPoints() {
76}
77
78template <typename I>
79void 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
86template <typename I>
87void 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
93template <typename I>
94void 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
104template class librbd::plugin::WriteLogImageCache<librbd::ImageCtx>;