]>
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 "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 | ||
12 | extern "C" { | |
13 | ||
14 | const char *__ceph_plugin_version() { | |
15 | return CEPH_GIT_NICE_VER; | |
16 | } | |
17 | ||
18 | int __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 | ||
32 | namespace librbd { | |
33 | namespace plugin { | |
34 | ||
35 | template <typename I> | |
36 | void 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 | ||
64 | template <typename I> | |
65 | void 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 | ||
81 | template class librbd::plugin::ParentCache<librbd::ImageCtx>; |