]> xenbits.xensource.com Git - qemu-xen.git/commit
nbd/server: Quiesce coroutines on context switch
authorSergio Lopez <slp@redhat.com>
Mon, 14 Dec 2020 17:05:18 +0000 (18:05 +0100)
committerEric Blake <eblake@redhat.com>
Wed, 20 Jan 2021 20:48:54 +0000 (14:48 -0600)
commitf148ae7d36cbb924447f4b528a94d7799836c749
tree9c08b2964964a841c219c1ea61f7f2addd42ffdf
parentc7040ff64ec93ee925a81d3547db925fe7d1f1c0
nbd/server: Quiesce coroutines on context switch

When switching between AIO contexts we need to me make sure that both
recv_coroutine and send_coroutine are not scheduled to run. Otherwise,
QEMU may crash while attaching the new context with an error like
this one:

aio_co_schedule: Co-routine was already scheduled in 'aio_co_schedule'

To achieve this we need a local implementation of
'qio_channel_readv_all_eof' named 'nbd_read_eof' (a trick already done
by 'nbd/client.c') that allows us to interrupt the operation and to
know when recv_coroutine is yielding.

With this in place, we delegate detaching the AIO context to the
owning context with a BH ('nbd_aio_detach_bh') scheduled using
'aio_wait_bh_oneshot'. This BH signals that we need to quiesce the
channel by setting 'client->quiescing' to 'true', and either waits for
the coroutine to finish using AIO_WAIT_WHILE or, if it's yielding in
'nbd_read_eof', actively enters the coroutine to interrupt it.

RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1900326
Signed-off-by: Sergio Lopez <slp@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20201214170519.223781-4-slp@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
nbd/server.c