]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/tools/rbd/Utils.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / tools / rbd / Utils.h
index bd00765f8ed7511600f31fde492f7e5dbbe80eac..5076fd7fe9ce54f5b215bc93b09ae41a57d2f75c 100644 (file)
@@ -4,6 +4,7 @@
 #ifndef CEPH_RBD_UTILS_H
 #define CEPH_RBD_UTILS_H
 
+#include "include/compat.h"
 #include "include/int_types.h"
 #include "include/rados/librados.hpp"
 #include "include/rbd/librbd.hpp"
@@ -84,6 +85,43 @@ struct ProgressContext : public librbd::ProgressContext {
 
 int get_percentage(uint64_t part, uint64_t whole);
 
+struct EncryptionOptions {
+  std::vector<librbd::encryption_spec_t> specs;
+
+  ~EncryptionOptions() {
+    for (auto& spec : specs) {
+      switch (spec.format) {
+      case RBD_ENCRYPTION_FORMAT_LUKS: {
+        auto opts =
+            static_cast<librbd::encryption_luks_format_options_t*>(spec.opts);
+        ceph_memzero_s(opts->passphrase.data(), opts->passphrase.size(),
+                       opts->passphrase.size());
+        delete opts;
+        break;
+      }
+      case RBD_ENCRYPTION_FORMAT_LUKS1: {
+        auto opts =
+            static_cast<librbd::encryption_luks1_format_options_t*>(spec.opts);
+        ceph_memzero_s(opts->passphrase.data(), opts->passphrase.size(),
+                       opts->passphrase.size());
+        delete opts;
+        break;
+      }
+      case RBD_ENCRYPTION_FORMAT_LUKS2: {
+        auto opts =
+            static_cast<librbd::encryption_luks2_format_options_t*>(spec.opts);
+        ceph_memzero_s(opts->passphrase.data(), opts->passphrase.size(),
+                       opts->passphrase.size());
+        delete opts;
+        break;
+      }
+      default:
+        ceph_abort();
+      }
+    }
+  }
+};
+
 template <typename T, void(T::*MF)(int)>
 librbd::RBD::AioCompletion *create_aio_completion(T *t) {
   return new librbd::RBD::AioCompletion(
@@ -162,6 +200,9 @@ int get_formatter(const boost::program_options::variables_map &vm,
 int get_snap_create_flags(const boost::program_options::variables_map &vm,
                           uint32_t *flags);
 
+int get_encryption_options(const boost::program_options::variables_map &vm,
+                           EncryptionOptions* result);
+
 void init_context();
 
 int init_rados(librados::Rados *rados);