From 0d073fed8103e2c6558b243f59cdffd6c78665ea Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 16 Nov 2020 18:12:58 -0500 Subject: [PATCH] librbd/api/migration: get_source_spec should read spec from OSD 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 --- src/librbd/api/Migration.cc | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/librbd/api/Migration.cc b/src/librbd/api/Migration.cc index 51d5602b73f7f..b1f3542dbb98d 100644 --- a/src/librbd/api/Migration.cc +++ b/src/librbd/api/Migration.cc @@ -817,19 +817,38 @@ int Migration::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::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; -- 2.47.3