[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 05/21] block: Introduce bdrv_schedule_unref()
From: |
Stefan Hajnoczi |
Subject: |
Re: [PATCH v2 05/21] block: Introduce bdrv_schedule_unref() |
Date: |
Tue, 12 Sep 2023 12:49:13 -0400 |
On Mon, Sep 11, 2023 at 11:46:04AM +0200, Kevin Wolf wrote:
> 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>
> ---
> include/block/block-global-state.h | 1 +
> block.c | 17 +++++++++++++++++
> block/graph-lock.c | 26 +++++++++++++++++++-------
> tests/qemu-iotests/051.pc.out | 6 +++---
> 4 files changed, 40 insertions(+), 10 deletions(-)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
signature.asc
Description: PGP signature
- [PATCH v2 00/21] Graph locking part 4 (node management), Kevin Wolf, 2023/09/11
- [PATCH v2 01/21] block: Remove unused BlockReopenQueueEntry.perms_checked, Kevin Wolf, 2023/09/11
- [PATCH v2 02/21] preallocate: Factor out preallocate_truncate_to_real_size(), Kevin Wolf, 2023/09/11
- [PATCH v2 04/21] block: Take AioContext lock for bdrv_append() more consistently, Kevin Wolf, 2023/09/11
- [PATCH v2 05/21] block: Introduce bdrv_schedule_unref(), Kevin Wolf, 2023/09/11
- Re: [PATCH v2 05/21] block: Introduce bdrv_schedule_unref(),
Stefan Hajnoczi <=
- [PATCH v2 03/21] preallocate: Don't poll during permission updates, Kevin Wolf, 2023/09/11
- [PATCH v2 06/21] block-coroutine-wrapper: Add no_co_wrapper_bdrv_wrlock functions, Kevin Wolf, 2023/09/11
- [PATCH v2 08/21] block: Mark bdrv_replace_child_noperm() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 07/21] block-coroutine-wrapper: Allow arbitrary parameter names, Kevin Wolf, 2023/09/11
- [PATCH v2 09/21] block: Mark bdrv_replace_child_tran() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 10/21] block: Mark bdrv_attach_child_common() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 11/21] block: Call transaction callbacks with lock held, Kevin Wolf, 2023/09/11
- [PATCH v2 12/21] block: Mark bdrv_attach_child() GRAPH_WRLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 13/21] block: Mark bdrv_parent_perms_conflict() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/11
- [PATCH v2 14/21] block: Mark bdrv_get_cumulative_perm() and callers GRAPH_RDLOCK, Kevin Wolf, 2023/09/11