qemu-e2k/block
Kevin Wolf 411132c979 export/vhost-user-blk: Fix consecutive drains
The vhost-user-blk export implement AioContext switches in its drain
implementation. This means that on drain_begin, it detaches the server
from its AioContext and on drain_end, attaches it again and schedules
the server->co_trip coroutine in the updated AioContext.

However, nothing guarantees that server->co_trip is even safe to be
scheduled. Not only is it unclear that the coroutine is actually in a
state where it can be reentered externally without causing problems, but
with two consecutive drains, it is possible that the scheduled coroutine
didn't have a chance yet to run and trying to schedule an already
scheduled coroutine a second time crashes with an assertion failure.

Following the model of NBD, this commit makes the vhost-user-blk export
shut down server->co_trip during drain so that resuming the export means
creating and scheduling a new coroutine, which is always safe.

There is one exception: If the drain call didn't poll (for example, this
happens in the context of bdrv_graph_wrlock()), then the coroutine
didn't have a chance to shut down. However, in this case the AioContext
can't have changed; changing the AioContext always involves a polling
drain. So in this case we can simply assert that the AioContext is
unchanged and just leave the coroutine running or wake it up if it has
yielded to wait for the AioContext to be attached again.

Fixes: e1054cd4aa
Fixes: https://issues.redhat.com/browse/RHEL-1708
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20231127115755.22846-1-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2023-11-28 14:56:32 +01:00
..
export export/vhost-user-blk: Fix consecutive drains 2023-11-28 14:56:32 +01:00
monitor block: Mark bdrv_skip_implicit_filters() and callers GRAPH_RDLOCK 2023-11-07 19:14:19 +01:00
accounting.c
aio_task.c
amend.c
backup.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
blkdebug.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
blkio.c util/defer-call: move defer_call() to util/ 2023-10-31 15:41:42 +01:00
blklogwrites.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
blkreplay.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
blkverify.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
block-backend.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
block-copy.c block: Mark bdrv_chain_contains() and callers GRAPH_RDLOCK 2023-11-07 19:14:19 +01:00
block-gen.h
block-ram-registrar.c
bochs.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
cloop.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
commit.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
copy-before-write.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
copy-before-write.h
copy-on-read.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
copy-on-read.h block: Mark bdrv_(un)freeze_backing_chain() and callers GRAPH_RDLOCK 2023-11-07 19:14:19 +01:00
coroutines.h
create.c
crypto.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
crypto.h
curl.c block: Mark bdrv_apply_auto_read_only() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
dirty-bitmap.c
dmg-bz2.c
dmg-lzfse.c
dmg.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
dmg.h
file-posix.c file-posix: fix over-writing of returning zone_append offset 2023-11-06 16:15:07 +01:00
file-win32.c
filter-compress.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
gluster.c block: Mark bdrv_apply_auto_read_only() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
graph-lock.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
io.c block: Add missing GRAPH_RDLOCK annotations 2023-11-08 17:56:17 +01:00
io_uring.c virtio: use defer_call() in virtio_irqfd_notify() 2023-10-31 15:42:14 +01:00
iscsi-opts.c
iscsi.c block: Mark bdrv_apply_auto_read_only() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
linux-aio.c virtio: use defer_call() in virtio_irqfd_notify() 2023-10-31 15:42:14 +01:00
meson.build util/defer-call: move defer_call() to util/ 2023-10-31 15:41:42 +01:00
mirror.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
nbd.c block: Mark bdrv_apply_auto_read_only() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
nfs.c block: Mark bdrv_refresh_filename() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
null.c
nvme.c block/nvme: nvme_process_completion() fix bound for cid 2023-11-06 15:00:28 +00:00
parallels-ext.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
parallels.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
parallels.h block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
preallocate.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
progress_meter.c
qapi-sysemu.c block: Fix locking in media change monitor commands 2023-10-31 13:51:28 +01:00
qapi.c block: Mark bdrv_refresh_filename() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
qcow.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
qcow2-bitmap.c qcow2: Take locks for accessing bs->file 2023-11-08 17:56:17 +01:00
qcow2-cache.c qcow2: Mark qcow2_signal_corruption() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
qcow2-cluster.c qcow2: Take locks for accessing bs->file 2023-11-08 17:56:17 +01:00
qcow2-refcount.c qcow2: Mark qcow2_signal_corruption() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
qcow2-snapshot.c
qcow2-threads.c
qcow2.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
qcow2.h qcow2: Take locks for accessing bs->file 2023-11-08 17:56:17 +01:00
qed-check.c
qed-cluster.c
qed-l2-cache.c
qed-table.c
qed.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
qed.h block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
quorum.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
raw-format.c block: Protect bs->file with graph_lock 2023-11-08 17:56:18 +01:00
rbd.c block: Mark bdrv_apply_auto_read_only() and callers GRAPH_RDLOCK 2023-10-12 16:31:33 +02:00
replication.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
reqlist.c
snapshot-access.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
snapshot.c block: Fix deadlocks in bdrv_graph_wrunlock() 2023-11-21 12:45:21 +01:00
ssh.c
stream.c stream: Fix AioContext locking during bdrv_graph_wrlock() 2023-11-21 12:45:21 +01:00
throttle-groups.c block: mark mixed functions that can suspend 2023-09-26 18:09:08 +02:00
throttle.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
trace-events nbd/client: Accept 64-bit block status chunks 2023-10-05 11:02:08 -05:00
trace.h
vdi.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
vhdx-endian.c
vhdx-log.c vhdx: Take locks for accessing bs->file 2023-11-08 17:56:18 +01:00
vhdx.c vhdx: Take locks for accessing bs->file 2023-11-08 17:56:18 +01:00
vhdx.h vhdx: Take locks for accessing bs->file 2023-11-08 17:56:18 +01:00
vmdk.c vmdk: Don't corrupt desc file in vmdk_write_cid 2023-11-28 14:56:32 +01:00
vpc.c block: Take graph lock for most of .bdrv_open 2023-11-08 17:56:18 +01:00
vvfat.c cpr: relax blockdev migration blockers 2023-11-01 16:13:59 +01:00
win32-aio.c
write-threshold.c