]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/api/migration: get_source_spec should read spec from OSD
authorJason Dillaman <dillaman@redhat.com>
Mon, 16 Nov 2020 23:12:58 +0000 (18:12 -0500)
committerJason Dillaman <dillaman@redhat.com>
Tue, 17 Nov 2020 01:25:16 +0000 (20:25 -0500)
In the case where the migration state is EXECUTED, the
ImageCtx::migration_info struct is never populated. Therefore, fallback
to reading from the OSD if the struct is empty.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/api/Migration.cc

index 51d5602b73f7f962d09740badaf6675f746773f4..b1f3542dbb98da985ea33815af0500c336658011 100644 (file)
@@ -817,19 +817,38 @@ int Migration<I>::get_source_spec(I* image_ctx, std::string* source_spec) {
   auto cct = image_ctx->cct;
   ldout(cct, 10) << dendl;
 
-  if (image_ctx->migration_info.empty()) {
-    return -ENOENT;
+  image_ctx->image_lock.lock_shared();
+  auto migration_info = image_ctx->migration_info;
+  image_ctx->image_lock.unlock_shared();
+
+  if (migration_info.empty()) {
+    // attempt to directly read the spec in case the state is EXECUTED
+    cls::rbd::MigrationSpec migration_spec;
+    int r = cls_client::migration_get(&image_ctx->md_ctx, image_ctx->header_oid,
+                                      &migration_spec);
+    if (r == -ENOENT) {
+      return r;
+    } else if (r < 0) {
+      lderr(cct) << "failed retrieving migration header: " << cpp_strerror(r)
+                 << dendl;
+      return r;
+    }
+
+    migration_info = {
+      migration_spec.pool_id, migration_spec.pool_namespace,
+      migration_spec.image_name, migration_spec.image_id,
+      migration_spec.source_spec, {}, 0, false};
   }
 
-  if (!image_ctx->migration_info.source_spec.empty()) {
-    *source_spec = image_ctx->migration_info.source_spec;
+  if (!migration_info.source_spec.empty()) {
+    *source_spec = migration_info.source_spec;
   } else {
     // legacy migration source
     *source_spec = migration::NativeFormat<I>::build_source_spec(
-      image_ctx->migration_info.pool_id,
-      image_ctx->migration_info.pool_namespace,
-      image_ctx->migration_info.image_name,
-      image_ctx->migration_info.image_id);
+      migration_info.pool_id,
+      migration_info.pool_namespace,
+      migration_info.image_name,
+      migration_info.image_id);
   }
 
   return 0;