diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/librbd/crypto/FormatRequest.cc | |
parent | Initial commit. (diff) | |
download | ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/librbd/crypto/FormatRequest.cc')
-rw-r--r-- | src/librbd/crypto/FormatRequest.cc | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/librbd/crypto/FormatRequest.cc b/src/librbd/crypto/FormatRequest.cc new file mode 100644 index 000000000..53dda58aa --- /dev/null +++ b/src/librbd/crypto/FormatRequest.cc @@ -0,0 +1,119 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "FormatRequest.h" + +#include "common/dout.h" +#include "common/errno.h" +#include "librbd/ImageCtx.h" +#include "librbd/Utils.h" +#include "librbd/crypto/ShutDownCryptoRequest.h" +#include "librbd/crypto/Utils.h" +#include "librbd/io/AioCompletion.h" +#include "librbd/io/ImageDispatchSpec.h" +#include "librbd/io/ObjectDispatcherInterface.h" +#include "librbd/io/Types.h" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::crypto::FormatRequest: " << this \ + << " " << __func__ << ": " + +namespace librbd { +namespace crypto { + +using librbd::util::create_context_callback; + +template <typename I> +FormatRequest<I>::FormatRequest( + I* image_ctx, std::unique_ptr<EncryptionFormat<I>> format, + Context* on_finish) : m_image_ctx(image_ctx), + m_format(std::move(format)), + m_on_finish(on_finish) { +} + +template <typename I> +void FormatRequest<I>::send() { + if (m_image_ctx->test_features(RBD_FEATURE_JOURNALING)) { + lderr(m_image_ctx->cct) << "cannot use encryption with journal" << dendl; + finish(-ENOTSUP); + return; + } + + if (m_image_ctx->crypto == nullptr) { + format(); + return; + } + + auto ctx = create_context_callback< + FormatRequest<I>, &FormatRequest<I>::handle_shutdown_crypto>(this); + auto *req = ShutDownCryptoRequest<I>::create(m_image_ctx, ctx); + req->send(); +} + +template <typename I> +void FormatRequest<I>::handle_shutdown_crypto(int r) { + if (r != 0) { + lderr(m_image_ctx->cct) << "unable to unload existing crypto: " + << cpp_strerror(r) << dendl; + finish(r); + return; + } + + format(); +} + +template <typename I> +void FormatRequest<I>::format() { + auto ctx = create_context_callback< + FormatRequest<I>, &FormatRequest<I>::handle_format>(this); + m_format->format(m_image_ctx, ctx); +} + +template <typename I> +void FormatRequest<I>::handle_format(int r) { + if (r != 0) { + lderr(m_image_ctx->cct) << "unable to format image: " << cpp_strerror(r) + << dendl; + finish(r); + return; + } + + flush(); +} + +template <typename I> +void FormatRequest<I>::flush() { + auto ctx = create_context_callback< + FormatRequest<I>, &FormatRequest<I>::handle_flush>(this); + auto aio_comp = io::AioCompletion::create_and_start( + ctx, librbd::util::get_image_ctx(m_image_ctx), io::AIO_TYPE_FLUSH); + auto req = io::ImageDispatchSpec::create_flush( + *m_image_ctx, io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp, + io::FLUSH_SOURCE_INTERNAL, {}); + req->send(); +} + +template <typename I> +void FormatRequest<I>::handle_flush(int r) { + if (r != 0) { + lderr(m_image_ctx->cct) << "unable to flush image: " << cpp_strerror(r) + << dendl; + } + + finish(r); +} + +template <typename I> +void FormatRequest<I>::finish(int r) { + if (r == 0) { + util::set_crypto(m_image_ctx, m_format->get_crypto()); + } + m_on_finish->complete(r); + delete this; +} + +} // namespace crypto +} // namespace librbd + +template class librbd::crypto::FormatRequest<librbd::ImageCtx>; |