]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: helper method for constructing source-spec for legacy migration
authorJason Dillaman <dillaman@redhat.com>
Fri, 16 Oct 2020 00:31:02 +0000 (20:31 -0400)
committerJason Dillaman <dillaman@redhat.com>
Sat, 24 Oct 2020 17:51:06 +0000 (13:51 -0400)
The legacy migration source format has explicit pool, namespace, and image
parameters. This helper method will convert it into the JSON format that
will be used for the new-style migration source-spec.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/migration/NativeFormat.cc
src/librbd/migration/NativeFormat.h

index bf6a78fc53f88ac27829c60197aa69bcdd12faba..b613f74e7ad9f97544a08dd75dbd80ce57a0d6db 100644 (file)
@@ -9,6 +9,8 @@
 #include "librbd/Utils.h"
 #include "librbd/asio/ContextWQ.h"
 #include "librbd/io/ImageDispatchSpec.h"
+#include "json_spirit/json_spirit.h"
+#include <sstream>
 
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
 namespace librbd {
 namespace migration {
 
+template <typename I>
+std::string NativeFormat<I>::build_source_spec(
+    int64_t pool_id, const std::string& pool_namespace,
+    const std::string& image_name, const std::string& image_id) {
+  json_spirit::mObject source_spec;
+  source_spec["type"] = "native";
+  source_spec["pool_id"] = pool_id;
+  source_spec["pool_namespace"] = pool_namespace;
+  if (!image_id.empty()) {
+    source_spec["image_id"] = image_id;
+  } else {
+    source_spec["image_name"] = image_name;
+  }
+  return json_spirit::write(source_spec);
+}
+
 template <typename I>
 NativeFormat<I>::NativeFormat(
     I* image_ctx, const MigrationInfo& migration_info)
index 0f0d43adc39015d8865dc2a1f84dde16b6344c95..0468be46594366821fa2e407a698b6a28d937115 100644 (file)
@@ -21,6 +21,11 @@ namespace migration {
 template <typename ImageCtxT>
 class NativeFormat : public FormatInterface {
 public:
+  static std::string build_source_spec(int64_t pool_id,
+                                       const std::string& pool_namespace,
+                                       const std::string& image_name,
+                                       const std::string& image_id);
+
   static NativeFormat* create(ImageCtxT* image_ctx,
                               const MigrationInfo& migration_info) {
     return new NativeFormat(image_ctx, migration_info);