From 5407e4380b318cf04f9996fc9d163abd8b9674b3 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 1 Dec 2020 21:26:54 -0500 Subject: [PATCH] librbd/migration: avoid async callback on image ctx open request If the ImageState::open call fails, we cannot have the callback be asynchronously dispatched via the now deleted ImageCtx object. Signed-off-by: Jason Dillaman --- src/librbd/ImageState.cc | 10 +++++++--- src/librbd/migration/NativeFormat.cc | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/librbd/ImageState.cc b/src/librbd/ImageState.cc index ab63b69bddaeb..a81a8373dbd61 100644 --- a/src/librbd/ImageState.cc +++ b/src/librbd/ImageState.cc @@ -808,6 +808,11 @@ void ImageState::complete_action_unlock(State next_state, int r) { TaskFinisherSingleton::get_singleton(m_image_ctx->cct).queue(ctx, r); } else { for (auto ctx : action_contexts.second) { + if (next_state == STATE_OPEN) { + // we couldn't originally wrap the open callback w/ an async wrapper in + // case the image failed to open + ctx = create_async_context_callback(*m_image_ctx, ctx); + } ctx->complete(r); } @@ -828,9 +833,8 @@ void ImageState::send_open_unlock() { m_state = STATE_OPENING; - Context *ctx = create_async_context_callback( - *m_image_ctx, create_context_callback< - ImageState, &ImageState::handle_open>(this)); + Context *ctx = create_context_callback< + ImageState, &ImageState::handle_open>(this); image::OpenRequest *req = image::OpenRequest::create( m_image_ctx, m_open_flags, ctx); diff --git a/src/librbd/migration/NativeFormat.cc b/src/librbd/migration/NativeFormat.cc index 91846f61d284a..68d1ac864a357 100644 --- a/src/librbd/migration/NativeFormat.cc +++ b/src/librbd/migration/NativeFormat.cc @@ -153,8 +153,7 @@ void NativeFormat::open(Context* on_finish) { } // open the source RBD image - auto ctx = util::create_async_context_callback(*m_image_ctx, on_finish); - m_image_ctx->state->open(flags, ctx); + m_image_ctx->state->open(flags, on_finish); } template -- 2.39.5