]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/librbd/crypto/FormatRequest.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / crypto / FormatRequest.cc
index 53dda58aae0e51bdc9dddf13f0b477d84cc2c663..5e90bbb7632aa64ebdc7714138ff935adca53263 100644 (file)
@@ -7,6 +7,7 @@
 #include "common/errno.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/Utils.h"
+#include "librbd/crypto/EncryptionFormat.h"
 #include "librbd/crypto/ShutDownCryptoRequest.h"
 #include "librbd/crypto/Utils.h"
 #include "librbd/io/AioCompletion.h"
@@ -26,7 +27,7 @@ using librbd::util::create_context_callback;
 
 template <typename I>
 FormatRequest<I>::FormatRequest(
-        I* image_ctx, std::unique_ptr<EncryptionFormat<I>> format,
+        I* image_ctx, EncryptionFormat format,
         Context* on_finish) : m_image_ctx(image_ctx),
                               m_format(std::move(format)),
                               m_on_finish(on_finish) {
@@ -39,10 +40,16 @@ void FormatRequest<I>::send() {
     finish(-ENOTSUP);
     return;
   }
-
-  if (m_image_ctx->crypto == nullptr) {
+  
+  if (m_image_ctx->encryption_format.get() == nullptr) {
     format();
     return;
+  } else if (m_image_ctx->parent != nullptr) {
+    lderr(m_image_ctx->cct) << "cannot format a cloned image "
+                               "while encryption is loaded"
+                            << dendl;
+    finish(-EINVAL);
+    return;
   }
 
   auto ctx = create_context_callback<
@@ -53,6 +60,8 @@ void FormatRequest<I>::send() {
 
 template <typename I>
 void FormatRequest<I>::handle_shutdown_crypto(int r) {
+  ldout(m_image_ctx->cct, 20) << "r=" << r << dendl;
+
   if (r != 0) {
     lderr(m_image_ctx->cct) << "unable to unload existing crypto: "
                             << cpp_strerror(r) << dendl;
@@ -72,6 +81,8 @@ void FormatRequest<I>::format() {
 
 template <typename I>
 void FormatRequest<I>::handle_format(int r) {
+  ldout(m_image_ctx->cct, 20) << "r=" << r << dendl;
+
   if (r != 0) {
     lderr(m_image_ctx->cct) << "unable to format image: " << cpp_strerror(r)
                             << dendl;
@@ -96,6 +107,8 @@ void FormatRequest<I>::flush() {
 
 template <typename I>
 void FormatRequest<I>::handle_flush(int r) {
+  ldout(m_image_ctx->cct, 20) << "r=" << r << dendl;
+
   if (r != 0) {
     lderr(m_image_ctx->cct) << "unable to flush image: " << cpp_strerror(r)
                             << dendl;
@@ -106,8 +119,12 @@ void FormatRequest<I>::handle_flush(int r) {
 
 template <typename I>
 void FormatRequest<I>::finish(int r) {
-  if (r == 0) {
-    util::set_crypto(m_image_ctx, m_format->get_crypto());
+  ldout(m_image_ctx->cct, 20) << "r=" << r << dendl;
+
+  if (r == 0 && m_image_ctx->parent == nullptr) {
+    // only load on flat images, to avoid a case where encryption
+    // is wrongfully loaded only on the child image
+    util::set_crypto(m_image_ctx, std::move(m_format));
   }
   m_on_finish->complete(r);
   delete this;