]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd/migration: tweak open source image state machine
authorJason Dillaman <dillaman@redhat.com>
Wed, 2 Dec 2020 00:48:41 +0000 (19:48 -0500)
committerJason Dillaman <dillaman@redhat.com>
Wed, 2 Dec 2020 00:48:41 +0000 (19:48 -0500)
Remove the need for the child (destination) image to be opened
for the state machine to function.

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

index 27cc99f529ebc788400eadc6d11804a2ccbe377d..348226c392b736d4bf0658f637aa19b54d518ae5 100644 (file)
@@ -119,8 +119,8 @@ void RefreshParentRequest<I>::send_open_parent() {
         RefreshParentRequest<I>,
         &RefreshParentRequest<I>::handle_open_parent, false>(this));
     auto req = migration::OpenSourceImageRequest<I>::create(
-      &m_child_image_ctx, m_parent_md.spec.snap_id, m_migration_info,
-      &m_parent_image_ctx, ctx);
+      m_child_image_ctx.md_ctx, &m_child_image_ctx, m_parent_md.spec.snap_id,
+      m_migration_info, &m_parent_image_ctx, ctx);
     req->send();
     return;
   }
index fc574ef7498443dadaec74a74bc4fa6db48153d2..8dd3a6fc016215518bf6221f8be1c01500cf5d65 100644 (file)
@@ -22,13 +22,13 @@ namespace migration {
 
 template <typename I>
 OpenSourceImageRequest<I>::OpenSourceImageRequest(
-    I* dst_image_ctx, uint64_t src_snap_id,
+    librados::IoCtx& io_ctx, I* dst_image_ctx, uint64_t src_snap_id,
     const MigrationInfo &migration_info, I** src_image_ctx, Context* on_finish)
-  : m_dst_image_ctx(dst_image_ctx), m_src_snap_id(src_snap_id),
+  : m_cct(reinterpret_cast<CephContext*>(io_ctx.cct())), m_io_ctx(io_ctx),
+    m_dst_image_ctx(dst_image_ctx), m_src_snap_id(src_snap_id),
     m_migration_info(migration_info), m_src_image_ctx(src_image_ctx),
     m_on_finish(on_finish) {
-  auto cct = m_dst_image_ctx->cct;
-  ldout(cct, 10) << dendl;
+  ldout(m_cct, 10) << dendl;
 }
 
 template <typename I>
@@ -38,12 +38,10 @@ void OpenSourceImageRequest<I>::send() {
 
 template <typename I>
 void OpenSourceImageRequest<I>::open_source() {
-  auto cct = m_dst_image_ctx->cct;
-  ldout(cct, 10) << dendl;
+  ldout(m_cct, 10) << dendl;
 
   // note that all source image ctx properties are placeholders
-  *m_src_image_ctx = I::create("", "", m_src_snap_id, m_dst_image_ctx->md_ctx,
-                               true);
+  *m_src_image_ctx = I::create("", "", m_src_snap_id, m_io_ctx, true);
   auto src_image_ctx = *m_src_image_ctx;
   src_image_ctx->child = m_dst_image_ctx;
 
@@ -70,8 +68,8 @@ void OpenSourceImageRequest<I>::open_source() {
   int r = source_spec_builder.parse_source_spec(source_spec,
                                                 &source_spec_object);
   if (r < 0) {
-    lderr(cct) << "failed to parse migration source-spec:" << cpp_strerror(r)
-               << dendl;
+    lderr(m_cct) << "failed to parse migration source-spec:" << cpp_strerror(r)
+                 << dendl;
     (*m_src_image_ctx)->state->close();
     finish(r);
     return;
@@ -80,8 +78,8 @@ void OpenSourceImageRequest<I>::open_source() {
   r = source_spec_builder.build_format(source_spec_object, import_only,
                                        &m_format);
   if (r < 0) {
-    lderr(cct) << "failed to build migration format handler: "
-               << cpp_strerror(r) << dendl;
+    lderr(m_cct) << "failed to build migration format handler: "
+                 << cpp_strerror(r) << dendl;
     (*m_src_image_ctx)->state->close();
     finish(r);
     return;
@@ -95,12 +93,11 @@ void OpenSourceImageRequest<I>::open_source() {
 
 template <typename I>
 void OpenSourceImageRequest<I>::handle_open_source(int r) {
-  auto cct = m_dst_image_ctx->cct;
-  ldout(cct, 10) << "r=" << r << dendl;
+  ldout(m_cct, 10) << "r=" << r << dendl;
 
   if (r < 0) {
-    lderr(cct) << "failed to open migration source: " << cpp_strerror(r)
-               << dendl;
+    lderr(m_cct) << "failed to open migration source: " << cpp_strerror(r)
+                 << dendl;
     finish(r);
     return;
   }
@@ -115,8 +112,7 @@ void OpenSourceImageRequest<I>::handle_open_source(int r) {
 
 template <typename I>
 void OpenSourceImageRequest<I>::finish(int r) {
-  auto cct = m_dst_image_ctx->cct;
-  ldout(cct, 10) << "r=" << r << dendl;
+  ldout(m_cct, 10) << "r=" << r << dendl;
 
   if (r < 0) {
     *m_src_image_ctx = nullptr;
index 1ad247686a1d24a7602f79a28f18b232e9221454..a9099452d607d4e8c5917ac4b0d8626574311c99 100644 (file)
@@ -4,6 +4,7 @@
 #ifndef CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H
 #define CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H
 
+#include "include/rados/librados_fwd.hpp"
 #include "librbd/Types.h"
 #include <memory>
 
@@ -20,17 +21,19 @@ struct FormatInterface;
 template <typename ImageCtxT>
 class OpenSourceImageRequest {
 public:
-  static OpenSourceImageRequest* create(ImageCtxT* destination_image_ctx,
+  static OpenSourceImageRequest* create(librados::IoCtx& io_ctx,
+                                        ImageCtxT* destination_image_ctx,
                                         uint64_t src_snap_id,
                                         const MigrationInfo &migration_info,
                                         ImageCtxT** source_image_ctx,
                                         Context* on_finish) {
-    return new OpenSourceImageRequest(destination_image_ctx, src_snap_id,
-                                      migration_info, source_image_ctx,
-                                      on_finish);
+    return new OpenSourceImageRequest(io_ctx, destination_image_ctx,
+                                      src_snap_id, migration_info,
+                                      source_image_ctx, on_finish);
   }
 
-  OpenSourceImageRequest(ImageCtxT* destination_image_ctx,
+  OpenSourceImageRequest(librados::IoCtx& io_ctx,
+                         ImageCtxT* destination_image_ctx,
                          uint64_t src_snap_id,
                          const MigrationInfo &migration_info,
                          ImageCtxT** source_image_ctx,
@@ -53,6 +56,8 @@ private:
    * @endverbatim
    */
 
+  CephContext* m_cct;
+  librados::IoCtx& m_io_ctx;
   ImageCtxT* m_dst_image_ctx;
   uint64_t m_src_snap_id;
   MigrationInfo m_migration_info;