mirror_qemu/nbd
Kevin Wolf a69a002dcd nbd/server: Fix race in draining the export
When draining an NBD export, nbd_drained_begin() first sets
client->quiescing so that nbd_client_receive_next_request() won't start
any new request coroutines. Then nbd_drained_poll() tries to makes sure
that we wait for any existing request coroutines by checking that
client->nb_requests has become 0.

However, there is a small window between creating a new request
coroutine and increasing client->nb_requests. If a coroutine is in this
state, it won't be waited for and drain returns too early.

In the context of switching to a different AioContext, this means that
blk_aio_attached() will see client->recv_coroutine != NULL and fail its
assertion.

Fix this by increasing client->nb_requests immediately when starting the
coroutine. Doing this after the checks if we should create a new
coroutine is okay because client->lock is held.

Cc: qemu-stable@nongnu.org
Fixes: fd6afc501a ("nbd/server: Use drained block ops to quiesce the server")
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20240314165825.40261-2-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
(cherry picked from commit 9c707525cb)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2024-03-19 19:45:55 +03:00
..
client-connection.c nbd/client: Request extended headers during negotiation 2023-10-05 11:02:08 -05:00
client.c nbd/client: Request extended headers during negotiation 2023-10-05 11:02:08 -05:00
common.c nbd: Add types for extended headers 2023-09-22 17:21:08 -05:00
meson.build nbd: move connection code from block/nbd to nbd/client-connection 2021-06-18 10:59:53 -05:00
nbd-internal.h nbd/server: Prepare to receive extended header requests 2023-10-05 11:02:08 -05:00
server.c nbd/server: Fix race in draining the export 2024-03-19 19:45:55 +03:00
trace-events nbd/server: Add FLAG_PAYLOAD support to CMD_BLOCK_STATUS 2023-10-05 11:02:08 -05:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00