]>
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 "LoadRequest.h" | |
5 | ||
6 | #include "common/dout.h" | |
7 | #include "common/errno.h" | |
8 | #include "librbd/Utils.h" | |
9 | #include "librbd/ImageCtx.h" | |
10 | #include "librbd/crypto/Utils.h" | |
11 | ||
12 | #define dout_subsys ceph_subsys_rbd | |
13 | #undef dout_prefix | |
14 | #define dout_prefix *_dout << "librbd::crypto::LoadRequest: " << this \ | |
15 | << " " << __func__ << ": " | |
16 | ||
17 | namespace librbd { | |
18 | namespace crypto { | |
19 | ||
20 | using librbd::util::create_context_callback; | |
21 | ||
22 | template <typename I> | |
23 | LoadRequest<I>::LoadRequest( | |
24 | I* image_ctx, std::unique_ptr<EncryptionFormat<I>> format, | |
25 | Context* on_finish) : m_image_ctx(image_ctx), | |
26 | m_format(std::move(format)), | |
27 | m_on_finish(on_finish) { | |
28 | } | |
29 | ||
30 | template <typename I> | |
31 | void LoadRequest<I>::send() { | |
32 | if (m_image_ctx->crypto != nullptr) { | |
33 | lderr(m_image_ctx->cct) << "encryption already loaded" << dendl; | |
34 | finish(-EEXIST); | |
35 | return; | |
36 | } | |
37 | ||
38 | auto ictx = m_image_ctx; | |
39 | while (ictx != nullptr) { | |
40 | if (ictx->test_features(RBD_FEATURE_JOURNALING)) { | |
41 | lderr(m_image_ctx->cct) << "cannot use encryption with journal." | |
42 | << " image name: " << ictx->name << dendl; | |
43 | finish(-ENOTSUP); | |
44 | return; | |
45 | } | |
46 | ictx = ictx->parent; | |
47 | } | |
48 | ||
49 | auto ctx = create_context_callback< | |
50 | LoadRequest<I>, &LoadRequest<I>::finish>(this); | |
51 | m_format->load(m_image_ctx, ctx); | |
52 | } | |
53 | ||
54 | template <typename I> | |
55 | void LoadRequest<I>::finish(int r) { | |
56 | ||
57 | if (r == 0) { | |
58 | // load crypto layers to image and its ancestors | |
59 | auto crypto = m_format->get_crypto(); | |
60 | auto ictx = m_image_ctx; | |
61 | while (ictx != nullptr) { | |
62 | util::set_crypto(ictx, crypto); | |
63 | ictx = ictx->parent; | |
64 | } | |
65 | } | |
66 | ||
67 | m_on_finish->complete(r); | |
68 | delete this; | |
69 | } | |
70 | ||
71 | } // namespace crypto | |
72 | } // namespace librbd | |
73 | ||
74 | template class librbd::crypto::LoadRequest<librbd::ImageCtx>; |