diff --git a/src/librbd/io/AioCompletion.cc b/src/librbd/io/AioCompletion.cc index f518694e603..96cc0f9f771 100644 --- a/src/librbd/io/AioCompletion.cc +++ b/src/librbd/io/AioCompletion.cc @@ -111,14 +111,6 @@ void AioCompletion::complete() { notify_callbacks_complete(); } - if (image_dispatcher_ctx != nullptr) { - image_dispatcher_ctx->complete(rval); - } - - // note: possible for image to be closed after op marked finished - if (async_op.started()) { - async_op.finish_op(); - } tracepoint(librbd, aio_complete_exit); } @@ -283,8 +275,19 @@ void AioCompletion::complete_event_socket() { void AioCompletion::notify_callbacks_complete() { state = AIO_STATE_COMPLETE; - std::unique_lock locker(lock); - cond.notify_all(); + { + std::unique_lock locker(lock); + cond.notify_all(); + } + + if (image_dispatcher_ctx != nullptr) { + image_dispatcher_ctx->complete(rval); + } + + // note: possible for image to be closed after op marked finished + if (async_op.started()) { + async_op.finish_op(); + } } } // namespace io