qemu/include/block
Kevin Wolf ac2ae233a0 block: Introduce bdrv_schedule_unref()
bdrv_unref() is called by a lot of places that need to hold the graph
lock (it naturally happens in the context of operations that change the
graph). However, bdrv_unref() takes the graph writer lock internally, so
it can't actually be called while already holding a graph lock without
causing a deadlock.

bdrv_unref() also can't just become GRAPH_WRLOCK because it drains the
node before closing it, and draining requires that the graph is
unlocked.

The solution is to defer deleting the node until we don't hold the lock
any more and draining is possible again.

Note that keeping images open for longer than necessary can create
problems, too: You can't open an image again before it is really closed
(if image locking didn't prevent it, it would cause corruption).
Reopening an image immediately happens at least during bdrv_open() and
bdrv_co_create().

In order to solve this problem, make sure to run the deferred unref in
bdrv_graph_wrunlock(), i.e. the first possible place where we can drain
again. This is also why bdrv_schedule_unref() is marked GRAPH_WRLOCK.

The output of iotest 051 is updated because the additional polling
changes the order of HMP output, resulting in a new "(qemu)" prompt in
the test output that was previously on a separate line and filtered out.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20230911094620.45040-6-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2023-09-20 17:46:01 +02:00
..
accounting.h block: add accounting for zone append operation 2023-05-15 08:18:10 -04:00
aio-wait.h aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() 2023-05-10 14:15:13 +02:00
aio.h aio: remove aio_disable_external() API 2023-05-30 17:37:26 +02:00
aio_task.h coroutine: Move coroutine_fn to qemu/osdep.h, trim includes 2023-01-19 10:18:28 +01:00
block-common.h block: add subcluster_size field to BlockDriverInfo 2023-08-30 07:39:10 -04:00
block-copy.h block: Mark bdrv_co_block_status() and callers GRAPH_RDLOCK 2023-02-23 19:49:07 +01:00
block-global-state.h block: Introduce bdrv_schedule_unref() 2023-09-20 17:46:01 +02:00
block-hmp-cmds.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
block-io.h block/io: align requests to subcluster_size 2023-08-30 07:39:10 -04:00
block.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
block_backup.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
block_int-common.h Block layer patches 2023-09-11 09:11:22 -04:00
block_int-global-state.h block: Mark bdrv_recurse_can_replace() and callers GRAPH_RDLOCK 2023-05-10 14:16:54 +02:00
block_int-io.h block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK 2023-02-23 19:49:33 +01:00
block_int.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
blockjob.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
blockjob_int.h blockjob: Adhere to rate limit even when reentered early 2023-05-19 19:12:12 +02:00
dirty-bitmap.h block: Mark bdrv_*_dirty_bitmap() and callers GRAPH_RDLOCK 2023-02-23 19:49:32 +01:00
export.h block/export: don't require AioContext lock around blk_exp_ref/unref() 2023-05-30 17:32:02 +02:00
fuse.h fuse: Allow exporting BDSs via FUSE 2020-12-11 17:52:39 +01:00
graph-lock.h graph-lock: Unlock the AioContext while polling 2023-06-28 08:46:23 +02:00
nbd.h nbd: drop unused nbd_receive_negotiate() aio_context argument 2023-09-07 20:32:11 -05:00
nvme.h hw/nvme: flexible data placement emulation 2023-03-06 15:28:02 +01:00
qapi.h block: Remove bdrv_query_block_node_info 2023-09-08 17:03:09 +02:00
qdict.h include: move qdict_{crumple,flatten} declarations 2022-04-21 17:03:51 +04:00
raw-aio.h block/linux-aio: convert to blk_io_plug_call() API 2023-06-01 07:34:03 -04:00
replication.h replication: move include out of root directory 2021-05-26 14:49:46 +02:00
reqlist.h block/reqlist: add reqlist_wait_all() 2022-03-07 09:33:30 +01:00
snapshot.h include/block/snapshot: global state API + assertions 2022-03-04 18:18:25 +01:00
thread-pool.h thread-pool: avoid passing the pool parameter every time 2023-04-25 13:17:28 +02:00
throttle-groups.h include/block: Untangle inclusion loops 2023-01-20 07:24:28 +01:00
ufs.h hw/ufs: Initial commit for emulated Universal-Flash-Storage 2023-09-07 14:01:29 -04:00
write-threshold.h block: Clean up includes 2023-02-08 07:28:05 +01:00