1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "ShutDownCryptoRequest.h"
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"
15 #define dout_subsys ceph_subsys_rbd
17 #define dout_prefix *_dout << "librbd::crypto::ShutDownCryptoRequest: " \
18 << this << " " << __func__ << ": "
23 using librbd::util::create_context_callback
;
26 ShutDownCryptoRequest
<I
>::ShutDownCryptoRequest(
27 I
* image_ctx
, Context
* on_finish
) : m_image_ctx(image_ctx
),
28 m_on_finish(on_finish
) {
32 void ShutDownCryptoRequest
<I
>::send() {
33 shut_down_object_dispatch();
37 void ShutDownCryptoRequest
<I
>::shut_down_object_dispatch() {
38 if (!m_image_ctx
->io_object_dispatcher
->exists(
39 io::OBJECT_DISPATCH_LAYER_CRYPTO
)) {
44 auto ctx
= create_context_callback
<
45 ShutDownCryptoRequest
<I
>,
46 &ShutDownCryptoRequest
<I
>::handle_shut_down_object_dispatch
>(this);
48 m_image_ctx
->io_object_dispatcher
->shut_down_dispatch(
49 io::OBJECT_DISPATCH_LAYER_CRYPTO
, ctx
);
53 void ShutDownCryptoRequest
<I
>::handle_shut_down_object_dispatch(int r
) {
55 lderr(m_image_ctx
->cct
) << "failed to shut down object dispatch: "
56 << cpp_strerror(r
) << dendl
;
61 shut_down_image_dispatch();
65 void ShutDownCryptoRequest
<I
>::shut_down_image_dispatch() {
66 if (!m_image_ctx
->io_image_dispatcher
->exists(
67 io::IMAGE_DISPATCH_LAYER_CRYPTO
)) {
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
);
80 void ShutDownCryptoRequest
<I
>::handle_shut_down_image_dispatch(int r
) {
82 lderr(m_image_ctx
->cct
) << "failed to shut down image dispatch: "
83 << cpp_strerror(r
) << dendl
;
89 void ShutDownCryptoRequest
<I
>::finish(int r
) {
91 std::unique_lock image_locker
{m_image_ctx
->image_lock
};
92 m_image_ctx
->crypto
= nullptr;
95 m_on_finish
->complete(r
);
100 } // namespace librbd
102 template class librbd::crypto::ShutDownCryptoRequest
<librbd::ImageCtx
>;