]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/crypto/ShutDownCryptoRequest.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / librbd / crypto / ShutDownCryptoRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "ShutDownCryptoRequest.h"
5
6 #include "common/dout.h"
7 #include "common/errno.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/Utils.h"
10 #include "librbd/crypto/CryptoImageDispatch.h"
11 #include "librbd/crypto/CryptoObjectDispatch.h"
12 #include "librbd/io/ImageDispatcherInterface.h"
13 #include "librbd/io/ObjectDispatcherInterface.h"
14
15 #define dout_subsys ceph_subsys_rbd
16 #undef dout_prefix
17 #define dout_prefix *_dout << "librbd::crypto::ShutDownCryptoRequest: " \
18 << this << " " << __func__ << ": "
19
20 namespace librbd {
21 namespace crypto {
22
23 using librbd::util::create_context_callback;
24
25 template <typename I>
26 ShutDownCryptoRequest<I>::ShutDownCryptoRequest(
27 I* image_ctx, Context* on_finish) : m_image_ctx(image_ctx),
28 m_on_finish(on_finish) {
29 }
30
31 template <typename I>
32 void ShutDownCryptoRequest<I>::send() {
33 shut_down_object_dispatch();
34 }
35
36 template <typename I>
37 void ShutDownCryptoRequest<I>::shut_down_object_dispatch() {
38 if (!m_image_ctx->io_object_dispatcher->exists(
39 io::OBJECT_DISPATCH_LAYER_CRYPTO)) {
40 finish(0);
41 return;
42 }
43
44 auto ctx = create_context_callback<
45 ShutDownCryptoRequest<I>,
46 &ShutDownCryptoRequest<I>::handle_shut_down_object_dispatch>(this);
47
48 m_image_ctx->io_object_dispatcher->shut_down_dispatch(
49 io::OBJECT_DISPATCH_LAYER_CRYPTO, ctx);
50 }
51
52 template <typename I>
53 void ShutDownCryptoRequest<I>::handle_shut_down_object_dispatch(int r) {
54 if (r < 0) {
55 lderr(m_image_ctx->cct) << "failed to shut down object dispatch: "
56 << cpp_strerror(r) << dendl;
57 finish(r);
58 return;
59 }
60
61 shut_down_image_dispatch();
62 }
63
64 template <typename I>
65 void ShutDownCryptoRequest<I>::shut_down_image_dispatch() {
66 if (!m_image_ctx->io_image_dispatcher->exists(
67 io::IMAGE_DISPATCH_LAYER_CRYPTO)) {
68 finish(0);
69 return;
70 }
71
72 auto ctx = create_context_callback<
73 ShutDownCryptoRequest<I>,
74 &ShutDownCryptoRequest<I>::handle_shut_down_image_dispatch>(this);
75 m_image_ctx->io_image_dispatcher->shut_down_dispatch(
76 io::IMAGE_DISPATCH_LAYER_CRYPTO, ctx);
77 }
78
79 template <typename I>
80 void ShutDownCryptoRequest<I>::handle_shut_down_image_dispatch(int r) {
81 if (r < 0) {
82 lderr(m_image_ctx->cct) << "failed to shut down image dispatch: "
83 << cpp_strerror(r) << dendl;
84 }
85 finish(r);
86 }
87
88 template <typename I>
89 void ShutDownCryptoRequest<I>::finish(int r) {
90 if (r == 0) {
91 std::unique_lock image_locker{m_image_ctx->image_lock};
92 m_image_ctx->crypto = nullptr;
93 }
94
95 m_on_finish->complete(r);
96 delete this;
97 }
98
99 } // namespace crypto
100 } // namespace librbd
101
102 template class librbd::crypto::ShutDownCryptoRequest<librbd::ImageCtx>;