]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/plugin/ParentCache.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / plugin / ParentCache.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 "librbd/plugin/ParentCache.h"
5#include "ceph_ver.h"
6#include "common/dout.h"
7#include "common/errno.h"
8#include "common/PluginRegistry.h"
9#include "librbd/ImageCtx.h"
10#include "librbd/cache/ParentCacheObjectDispatch.h"
11
12extern "C" {
13
14const char *__ceph_plugin_version() {
15 return CEPH_GIT_NICE_VER;
16}
17
18int __ceph_plugin_init(CephContext *cct, const std::string& type,
19 const std::string& name) {
20 auto plugin_registry = cct->get_plugin_registry();
21 return plugin_registry->add(
22 type, name, new librbd::plugin::ParentCache<librbd::ImageCtx>(cct));
23}
24
25} // extern "C"
26
27#define dout_subsys ceph_subsys_rbd
28#undef dout_prefix
29#define dout_prefix *_dout << "librbd::plugin::ParentCache: " \
30 << this << " " << __func__ << ": "
31
32namespace librbd {
33namespace plugin {
34
35template <typename I>
36void ParentCache<I>::init(I* image_ctx, Api<I>& api,
37 cache::ImageWritebackInterface& image_writeback,
38 PluginHookPoints& hook_points_list,
39 Context* on_finish) {
40 bool parent_cache_enabled = image_ctx->config.template get_val<bool>(
41 "rbd_parent_cache_enabled");
42 if (image_ctx->child == nullptr || !parent_cache_enabled ||
43 !image_ctx->data_ctx.is_valid()) {
44 on_finish->complete(0);
45 return;
46 }
47
48 auto cct = image_ctx->cct;
49 ldout(cct, 5) << dendl;
50
51 auto parent_cache = cache::ParentCacheObjectDispatch<I>::create(
52 image_ctx, api);
53 on_finish = new LambdaContext([this, on_finish, parent_cache](int r) {
54 if (r < 0) {
55 // the object dispatcher will handle cleanup if successfully initialized
56 delete parent_cache;
57 }
58
59 handle_init_parent_cache(r, on_finish);
60 });
61 parent_cache->init(on_finish);
62}
63
64template <typename I>
65void ParentCache<I>::handle_init_parent_cache(int r, Context* on_finish) {
66 ldout(cct, 5) << "r=" << r << dendl;
67
68 if (r < 0) {
69 lderr(cct) << "Failed to initialize parent cache object dispatch layer: "
70 << cpp_strerror(r) << dendl;
71 on_finish->complete(r);
72 return;
73 }
74
75 on_finish->complete(0);
76}
77
78} // namespace plugin
79} // namespace librbd
80
81template class librbd::plugin::ParentCache<librbd::ImageCtx>;