qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [qemu/qemu] 6a206a: block: Inline bdrv_detach_child()


From: Peter Maydell
Subject: [Qemu-commits] [qemu/qemu] 6a206a: block: Inline bdrv_detach_child()
Date: Wed, 14 Dec 2022 14:23:21 -0800

  Branch: refs/heads/staging
  Home:   https://github.com/qemu/qemu
  Commit: 6a206ad94a21ff77394606ab130d50c235b4a925
      
https://github.com/qemu/qemu/commit/6a206ad94a21ff77394606ab130d50c235b4a925
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: Inline bdrv_detach_child()

The only caller is bdrv_root_unref_child(), let's just do the logic
directly in it. It simplifies further conversion of
bdrv_root_unref_child() to transaction actions.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221107163558.618889-2-vsementsov@yandex-team.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 388e653f467eab86d7233bf87c69fcdecfa336c4
      
https://github.com/qemu/qemu/commit/388e653f467eab86d7233bf87c69fcdecfa336c4
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: drop bdrv_remove_filter_or_cow_child

Drop this simple wrapper used only in one place. We have too many graph
modifying functions even without it.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221107163558.618889-3-vsementsov@yandex-team.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 73bbfd27308002bfa90358334284b07b78941100
      
https://github.com/qemu/qemu/commit/73bbfd27308002bfa90358334284b07b78941100
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: bdrv_refresh_perms(): allow external tran

Allow passing external Transaction pointer, stop creating extra
Transaction objects.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221107163558.618889-4-vsementsov@yandex-team.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 7544a42f0e5e699de7032e7caec89888018a5de7
      
https://github.com/qemu/qemu/commit/7544a42f0e5e699de7032e7caec89888018a5de7
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: refactor bdrv_list_refresh_perms to allow any list of nodes

We are going to increase usage of collecting nodes in a list to then
update, and calling bdrv_topological_dfs() each time is not convenient,
and not correct as we are going to interleave graph modifying with
filling the node list.

So, let's switch to a function that takes any list of nodes, adds all
their subtrees and do topological sort. And finally, refresh
permissions.

While being here, make the function public, as we'll want to use it
from blockdev.c in near future.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@openvz.org>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221107163558.618889-5-vsementsov@yandex-team.ru>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 445d2b34da92c7628ecc976a60aed9ad8a630fe2
      
https://github.com/qemu/qemu/commit/445d2b34da92c7628ecc976a60aed9ad8a630fe2
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/qed.c

  Log Message:
  -----------
  qed: Don't yield in bdrv_qed_co_drain_begin()

We want to change .bdrv_co_drained_begin() back to be a non-coroutine
callback, so in preparation, avoid yielding in its implementation.

Because we increase bs->in_flight and bdrv_drained_begin() polls, the
behaviour is unchanged.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-2-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: e54917e6751e2acc31c08dc6b6f8a84be0aa5d51
      
https://github.com/qemu/qemu/commit/e54917e6751e2acc31c08dc6b6f8a84be0aa5d51
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M tests/unit/test-bdrv-drain.c

  Log Message:
  -----------
  test-bdrv-drain: Don't yield in .bdrv_co_drained_begin/end()

We want to change .bdrv_co_drained_begin/end() back to be non-coroutine
callbacks, so in preparation, avoid yielding in their implementation.

This does almost the same as the existing logic in bdrv_drain_invoke(),
by creating and entering coroutines internally. However, since the test
case is by far the heaviest user of coroutine code in drain callbacks,
it is preferable to have the complexity in the test case rather than the
drain core, which is already complicated enough without this.

The behaviour for bdrv_drain_begin() is unchanged because we increase
bs->in_flight and this is still polled. However, bdrv_drain_end()
doesn't wait for the spawned coroutine to complete any more. This is
fine, we don't rely on bdrv_drain_end() restarting all operations
immediately before the next aio_poll().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-3-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: b13b590b72808984fb05b33c314a5d830e68a556
      
https://github.com/qemu/qemu/commit/b13b590b72808984fb05b33c314a5d830e68a556
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/io.c
    M block/qed.c
    M block/throttle.c
    M include/block/block_int-common.h
    M tests/unit/test-bdrv-drain.c

  Log Message:
  -----------
  block: Revert .bdrv_drained_begin/end to non-coroutine_fn

Polling during bdrv_drained_end() can be problematic (and in the future,
we may get cases for bdrv_drained_begin() where polling is forbidden,
and we don't care about already in-flight requests, but just want to
prevent new requests from arriving).

The .bdrv_drained_begin/end callbacks running in a coroutine is the only
reason why we have to do this polling, so make them non-coroutine
callbacks again. None of the callers actually yield any more.

This means that bdrv_drained_end() effectively doesn't poll any more,
even if AIO_WAIT_WHILE() loops are still there (their condition is false
from the beginning). This is generally not a problem, but in
test-bdrv-drain, some additional explicit aio_poll() calls need to be
added because the test case wants to verify the final state after BHs
have executed.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-4-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 446c8698d91699423450af494b5f745066c42305
      
https://github.com/qemu/qemu/commit/446c8698d91699423450af494b5f745066c42305
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/block-backend.c
    M block/io.c
    M blockjob.c
    M include/block/block-io.h
    M include/block/block_int-common.h

  Log Message:
  -----------
  block: Remove drained_end_counter

drained_end_counter is unused now, nobody changes its value any more. It
can be removed.

In cases where we had two almost identical functions that only differed
in whether the caller passes drained_end_counter, or whether they would
poll for a local drained_end_counter to reach 0, these become a single
function.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Message-Id: <20221118174110.55183-5-kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 9917aed61b8d159a095ef079892fbc9d0fbd0ddc
      
https://github.com/qemu/qemu/commit/9917aed61b8d159a095ef079892fbc9d0fbd0ddc
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/io.c

  Log Message:
  -----------
  block: Inline bdrv_drain_invoke()

bdrv_drain_invoke() has now two entirely separate cases that share no
code any more and are selected depending on a bool parameter. Each case
has only one caller. Just inline the function.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-6-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: deff9b2e2ba539b44fac3174ae15b938769bf522
      
https://github.com/qemu/qemu/commit/deff9b2e2ba539b44fac3174ae15b938769bf522
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: Fix locking for bdrv_reopen_queue_child()

Callers don't agree whether bdrv_reopen_queue_child() should be called
with the AioContext lock held or not. Standardise on holding the lock
(as done by QMP blockdev-reopen and the replication block driver) and
fix bdrv_reopen() to do the same.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221118174110.55183-7-kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 99b76f531ce42add18f72850ffec26d6fcb12662
      
https://github.com/qemu/qemu/commit/99b76f531ce42add18f72850ffec26d6fcb12662
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/replication.c
    M blockdev.c

  Log Message:
  -----------
  block: Drain individual nodes during reopen

bdrv_reopen() and friends use subtree drains as a lazy way of covering
all the nodes they touch. Turns out that this lazy way is a lot more
complicated than just draining the nodes individually, even not
accounting for the additional complexity in the drain mechanism itself.

Simplify the code by switching to draining the individual nodes that are
already managed in the BlockReopenQueue anyway.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221118174110.55183-8-kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 40e48d27b9c5a20f22a2f0cb42fb975d3d4ff7e5
      
https://github.com/qemu/qemu/commit/40e48d27b9c5a20f22a2f0cb42fb975d3d4ff7e5
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: Don't use subtree drains in bdrv_drop_intermediate()

Instead of using a subtree drain from the top node (which also drains
child nodes of base that we're not even interested in), use a normal
drain for base, which automatically drains all of the parents, too.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-9-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: ac4c59c0892cf3da529f76ee59aa431df3d50ca9
      
https://github.com/qemu/qemu/commit/ac4c59c0892cf3da529f76ee59aa431df3d50ca9
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/stream.c
    M include/block/block-global-state.h

  Log Message:
  -----------
  stream: Replace subtree drain with a single node drain

The subtree drain was introduced in commit b1e1af394d9 as a way to avoid
graph changes between finding the base node and changing the block graph
as necessary on completion of the image streaming job.

The block graph could change between these two points because
bdrv_set_backing_hd() first drains the parent node, which involved
polling and can do anything.

Subtree draining was an imperfect way to make this less likely (because
with it, fewer callbacks are called during this window). Everyone agreed
that it's not really the right solution, and it was only committed as a
stopgap solution.

This replaces the subtree drain with a solution that simply drains the
parent node before we try to find the base node, and then call a version
of bdrv_set_backing_hd() that doesn't drain, but just asserts that the
parent node is already drained.

This way, any graph changes caused by draining happen before we start
looking at the graph and things stay consistent between finding the base
node and changing the graph.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-10-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: a442c7bc9a8e9743716ce48c9eb670b540d1d399
      
https://github.com/qemu/qemu/commit/a442c7bc9a8e9743716ce48c9eb670b540d1d399
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/io.c
    M include/block/block-io.h
    M include/block/block_int-common.h
    M include/block/block_int-io.h
    M tests/unit/test-bdrv-drain.c

  Log Message:
  -----------
  block: Remove subtree drains

Subtree drains are not used any more. Remove them.

After this, BdrvChildClass.attach/detach() don't poll any more.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-11-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: c49c309d692266dc793b3ad7ee06f1b005568d02
      
https://github.com/qemu/qemu/commit/c49c309d692266dc793b3ad7ee06f1b005568d02
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/io.c
    M include/block/block_int-common.h
    M tests/unit/test-bdrv-drain.c

  Log Message:
  -----------
  block: Call drain callbacks only once

We only need to call both the BlockDriver's callback and the parent
callbacks when going from undrained to drained or vice versa. A second
drain section doesn't make a difference for the driver or the parent,
they weren't supposed to send new requests before and after the second
drain.

One thing that gets in the way is the 'ignore_bds_parents' parameter in
bdrv_do_drained_begin_quiesce() and bdrv_do_drained_end(): It means that
bdrv_drain_all_begin() increases bs->quiesce_counter, but does not
quiesce the parent through BdrvChildClass callbacks. If an additional
drain section is started now, bs->quiesce_counter will be non-zero, but
we would still need to quiesce the parent through BdrvChildClass in
order to keep things consistent (and unquiesce it on the matching
bdrv_drained_end(), even though the counter would not reach 0 yet as
long as the bdrv_drain_all() section is still active).

Instead of keeping track of this, let's just get rid of the parameter.
It was introduced in commit 6cd5c9d7b2d as an optimisation so that
during bdrv_drain_all(), we wouldn't recursively drain all parents up to
the root for each node, resulting in quadratic complexity. As it happens,
calling the callbacks only once solves the same problem, so as of this
patch, we'll still have O(n) complexity and ignore_bds_parents is not
needed any more.

This patch only ignores the 'ignore_bds_parents' parameter. It will be
removed in a separate patch.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20221118174110.55183-12-kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 312ecd1b3abaff1faac887c46b90e8851995797d
      
https://github.com/qemu/qemu/commit/312ecd1b3abaff1faac887c46b90e8851995797d
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/io.c
    M include/block/block-io.h

  Log Message:
  -----------
  block: Remove ignore_bds_parents parameter from drain_begin/end.

ignore_bds_parents is now ignored during drain_begin and drain_end, so
we can just remove it there. It is still a valid optimisation for
drain_all in bdrv_drained_poll(), so leave it around there.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221118174110.55183-13-kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 40bb0bb870e72dcc88658d2a1ce46119e326a1cf
      
https://github.com/qemu/qemu/commit/40bb0bb870e72dcc88658d2a1ce46119e326a1cf
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/io.c

  Log Message:
  -----------
  block: Drop out of coroutine in bdrv_do_drained_begin_quiesce()

The next patch adds a parent drain to bdrv_attach_child_common(), which
shouldn't be, but is currently called from coroutines in some cases (e.g.
.bdrv_co_create implementations generally open new nodes). Therefore,
the assertion that we're not in a coroutine doesn't hold true any more.

We could just remove the assertion because there is nothing in the
function that should be in conflict with running in a coroutine, but
just to be on the safe side, we can reverse the caller relationship
between bdrv_do_drained_begin() and bdrv_do_drained_begin_quiesce() so
that the latter also just drops out of coroutine context and we can
still be certain in the future that any drain code doesn't run in
coroutines.

As a nice side effect, the structure of bdrv_do_drained_begin() is now
symmetrical with bdrv_do_drained_end().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221118174110.55183-14-kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: ccae3e8a4af4e8a0b2ee6f2aa75a6f49a503ea1c
      
https://github.com/qemu/qemu/commit/ccae3e8a4af4e8a0b2ee6f2aa75a6f49a503ea1c
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/io.c
    M include/block/block-io.h
    M tests/unit/test-bdrv-drain.c

  Log Message:
  -----------
  block: Don't poll in bdrv_replace_child_noperm()

In order to make sure that bdrv_replace_child_noperm() doesn't have to
poll any more, get rid of the bdrv_parent_drained_begin_single() call.

This is possible now because we can require that the parent is already
drained through the child in question when the function is called and we
don't call the parent drain callbacks more than once.

The additional drain calls needed in callers cause the test case to run
its code in the drain handler too early (bdrv_attach_child() drains
now), so modify it to only enable the code after the test setup has
completed.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221118174110.55183-15-kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 1f00111dff5452effc37b9a2b42d8bad7b9c7c28
      
https://github.com/qemu/qemu/commit/1f00111dff5452effc37b9a2b42d8bad7b9c7c28
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/io.c
    M include/block/block-io.h

  Log Message:
  -----------
  block: Remove poll parameter from bdrv_parent_drained_begin_single()

All callers of bdrv_parent_drained_begin_single() pass poll=false now,
so we don't need the parameter any more.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221118174110.55183-16-kwolf@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 247c2043489e31b104e4fc514f2dd36fff879785
      
https://github.com/qemu/qemu/commit/247c2043489e31b104e4fc514f2dd36fff879785
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/io.c
    M include/block/block-io.h

  Log Message:
  -----------
  block-io: introduce coroutine_fn duplicates for 
bdrv_common_block_status_above callers

bdrv_common_block_status_above() is a g_c_w, and it is being called by
many "wrapper" functions like bdrv_is_allocated(),
bdrv_is_allocated_above() and bdrv_block_status_above().

Because we want to eventually split the coroutine from non-coroutine
case in g_c_w, create duplicate wrappers that take care of directly
calling the same coroutine functions called in the g_c_w.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-2-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 54397354f32487f606d256602bacbfc134abc48c
      
https://github.com/qemu/qemu/commit/54397354f32487f606d256602bacbfc134abc48c
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/block-copy.c
    M include/block/block-copy.h

  Log Message:
  -----------
  block-copy: add coroutine_fn annotations

These functions end up calling bdrv_common_block_status_above(), a
generated_co_wrapper function.
In addition, they also happen to be always called in coroutine context,
meaning all callers are coroutine_fn.
This means that the g_c_w function will enter the qemu_in_coroutine()
case and eventually suspend (or in other words call qemu_coroutine_yield()).
Therefore we can mark such functions coroutine_fn too.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-3-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 3ceedc1662f3cfd985e75ea13b1c3f55acb112d2
      
https://github.com/qemu/qemu/commit/3ceedc1662f3cfd985e75ea13b1c3f55acb112d2
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M nbd/server.c

  Log Message:
  -----------
  nbd/server.c: add coroutine_fn annotations

These functions end up calling bdrv_*() implemented as generated_co_wrapper
functions.
In addition, they also happen to be always called in coroutine context,
meaning all callers are coroutine_fn.
This means that the g_c_w function will enter the qemu_in_coroutine()
case and eventually suspend (or in other words call qemu_coroutine_yield()).
Therefore we can mark such functions coroutine_fn too.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-4-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: c3d5e1aa1391e64cea9c271662f8edd9f4d22aa9
      
https://github.com/qemu/qemu/commit/c3d5e1aa1391e64cea9c271662f8edd9f4d22aa9
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/block-backend.c
    M block/commit.c
    M include/sysemu/block-backend-io.h
    M nbd/server.c

  Log Message:
  -----------
  block-backend: replace bdrv_*_above with blk_*_above

Avoid mixing bdrv_* functions with blk_*, so create blk_* counterparts
for bdrv_block_status_above and bdrv_is_allocated_above.

Note that since blk_co_block_status_above only calls the g_c_w function
bdrv_common_block_status_above and is marked as coroutine_fn, call
directly bdrv_co_common_block_status_above() to avoid using a g_c_w.
Same applies to blk_co_is_allocated_above.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-5-eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 9b785e13edf2134174c51c674e62bc7dac7e5eaf
      
https://github.com/qemu/qemu/commit/9b785e13edf2134174c51c674e62bc7dac7e5eaf
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/vmdk.c

  Log Message:
  -----------
  block/vmdk: add coroutine_fn annotations

These functions end up calling bdrv_create() implemented as generated_co_wrapper
functions.
In addition, they also happen to be always called in coroutine context,
meaning all callers are coroutine_fn.
This means that the g_c_w function will enter the qemu_in_coroutine()
case and eventually suspend (or in other words call qemu_coroutine_yield()).
Therefore we can mark such functions coroutine_fn too.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-6-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 4c789639228edb6b2511ceaf6036ab943e7986a2
      
https://github.com/qemu/qemu/commit/4c789639228edb6b2511ceaf6036ab943e7986a2
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: avoid duplicating filename string in bdrv_create

We know that the string will stay around until the function
returns, and the parameter of drv->bdrv_co_create_opts is const char*,
so it must not be modified either.

Suggested-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-7-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 4722b75c8b912c93133219b041e49fa5a597593e
      
https://github.com/qemu/qemu/commit/4722b75c8b912c93133219b041e49fa5a597593e
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: distinguish between bdrv_create running in coroutine and not

Call two different functions depending on whether bdrv_create
is in coroutine or not, following the same pattern as
generated_co_wrapper functions.

This allows to also call the coroutine function directly,
without using CreateCo or relying in bdrv_create().

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-8-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: f17271ea253f0eb395e23ed2e104f8dd8238a7fb
      
https://github.com/qemu/qemu/commit/f17271ea253f0eb395e23ed2e104f8dd8238a7fb
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/crypto.c
    M block/parallels.c
    M block/qcow.c
    M block/qcow2.c
    M block/qed.c
    M block/raw-format.c
    M block/vdi.c
    M block/vhdx.c
    M block/vmdk.c
    M block/vpc.c
    M include/block/block-global-state.h

  Log Message:
  -----------
  block: bdrv_create_file is a coroutine_fn

It is always called in coroutine_fn callbacks, therefore
it can directly call bdrv_co_create().

Rename it to bdrv_co_create_file too.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-9-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 46b2d0e64dddde54c227d1550d86e1f9c14f3cac
      
https://github.com/qemu/qemu/commit/46b2d0e64dddde54c227d1550d86e1f9c14f3cac
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/coroutines.h
    M docs/devel/block-coroutine-wrapper.rst
    M include/block/block-common.h
    M include/block/block-io.h
    M include/sysemu/block-backend-io.h
    M scripts/block-coroutine-wrapper.py

  Log Message:
  -----------
  block: rename generated_co_wrapper in co_wrapper_mixed

In preparation to the incoming new function specifiers,
rename g_c_w with a more meaningful name and document it.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-10-eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: b2010e980e9ef3b5785721356b2045175be73da8
      
https://github.com/qemu/qemu/commit/b2010e980e9ef3b5785721356b2045175be73da8
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M docs/devel/block-coroutine-wrapper.rst
    M include/block/block-common.h
    M scripts/block-coroutine-wrapper.py

  Log Message:
  -----------
  block-coroutine-wrapper.py: introduce co_wrapper

This new annotation starts just a function wrapper that creates
a new coroutine. It assumes the caller is not a coroutine.
It will be the default annotation to be used in the future.

This is much better as c_w_mixed, because it is clear if the caller
is a coroutine or not, and provides the advantage of automating
the code creation. In the future all c_w_mixed functions will be
substituted by co_wrapper.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-11-eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: af758182ef422e51e63ba35ff62cf5ceba1cf051
      
https://github.com/qemu/qemu/commit/af758182ef422e51e63ba35ff62cf5ceba1cf051
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/block-gen.h
    M scripts/block-coroutine-wrapper.py

  Log Message:
  -----------
  block-coroutine-wrapper.py: support functions without bs arg

Right now, we take the first parameter of the function to get the
BlockDriverState to pass to bdrv_poll_co(), that internally calls
functions that figure in which aiocontext the coroutine should run.

However, it is useless to pass a bs just to get its own AioContext,
so instead pass it directly, and default to the main loop if no
BlockDriverState is passed as parameter.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-12-eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: df8973975c12d7fa8408abc6ff55f4ae7c076bb3
      
https://github.com/qemu/qemu/commit/df8973975c12d7fa8408abc6ff55f4ae7c076bb3
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/block-gen.h
    M scripts/block-coroutine-wrapper.py

  Log Message:
  -----------
  block-coroutine-wrapper.py: support also basic return types

Extend the regex to cover also return type, pointers included.
This implies that the value returned by the function cannot be
a simple "int" anymore, but the custom return type.
Therefore remove poll_state->ret and instead use a per-function
custom "ret" field.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-13-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: ef2004fd52bb35dfd31ec96b59e8bd2b6eddb98e
      
https://github.com/qemu/qemu/commit/ef2004fd52bb35dfd31ec96b59e8bd2b6eddb98e
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M include/block/block-global-state.h

  Log Message:
  -----------
  block: convert bdrv_create to co_wrapper

This function is never called in coroutine context, therefore
instead of manually creating a new coroutine, delegate it to the
block-coroutine-wrapper script, defining it as co_wrapper.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-14-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: f4cf0e5d9ead3eb2e1ac19eb108d2d593c7d3d8b
      
https://github.com/qemu/qemu/commit/f4cf0e5d9ead3eb2e1ac19eb108d2d593c7d3d8b
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/dirty-bitmap.c
    M block/meson.build
    M include/block/block-common.h
    M include/block/block-io.h
    M include/block/dirty-bitmap.h

  Log Message:
  -----------
  block/dirty-bitmap: convert coroutine-only functions to co_wrapper

bdrv_can_store_new_dirty_bitmap and bdrv_remove_persistent_dirty_bitmap
check if they are running in a coroutine, directly calling the
coroutine callback if it's the case.
Except that no coroutine calls such functions, therefore that check
can be removed, and function creation can be offloaded to
c_w.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-Id: <20221128142337.657646-15-eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 80266d35cbdef0eafafdf05adeefa4124128e462
      
https://github.com/qemu/qemu/commit/80266d35cbdef0eafafdf05adeefa4124128e462
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/io.c
    M include/block/block-global-state.h

  Log Message:
  -----------
  block: Factor out bdrv_drain_all_begin_nopoll()

Provide a separate function that just quiesces the users of a node to
prevent new requests from coming in, but without waiting for the already
in-flight I/O to complete.

This function can be used in contexts where polling is not allowed.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-2-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 75b86545ebf377210cfca6e91c41df31cac8673b
      
https://github.com/qemu/qemu/commit/75b86545ebf377210cfca6e91c41df31cac8673b
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    A block/graph-lock.c
    M block/meson.build
    M include/block/aio.h
    M include/block/block_int.h
    A include/block/graph-lock.h

  Log Message:
  -----------
  graph-lock: Introduce a lock to protect block graph operations

Block layer graph operations are always run under BQL in the main loop.
This is proved by the assertion qemu_in_main_thread() and its wrapper
macro GLOBAL_STATE_CODE.

However, there are also concurrent coroutines running in other iothreads
that always try to traverse the graph. Currently this is protected
(among various other things) by the AioContext lock, but once this is
removed, we need to make sure that reads do not happen while modifying
the graph.

We distinguish between writer (main loop, under BQL) that modifies the
graph, and readers (all other coroutines running in various AioContext),
that go through the graph edges, reading ->parents and->children.

The writer (main loop) has "exclusive" access, so it first waits for any
current read to finish, and then prevents incoming ones from entering
while it has the exclusive access.

The readers (coroutines in multiple AioContext) are free to access the
graph as long the writer is not modifying the graph. In case it is, they
go in a CoQueue and sleep until the writer is done.

If a coroutine changes AioContext, the counter in the original and new
AioContext are left intact, since the writer does not care where the
reader is, but only if there is one.

As a result, some AioContexts might have a negative reader count, to
balance the positive count of the AioContext that took the lock.  This
also means that when an AioContext is deleted it may have a nonzero
reader count. In that case we transfer the count to a global shared
counter so that the writer is always aware of all readers.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-3-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 3c38785d99e3f21d404c84f7dcd193be8031535a
      
https://github.com/qemu/qemu/commit/3c38785d99e3f21d404c84f7dcd193be8031535a
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M include/block/graph-lock.h

  Log Message:
  -----------
  graph-lock: Implement guard macros

Similar to the implementation in lockable.h, implement macros to
automatically take and release the rdlock.

Create the empty GraphLockable and GraphLockableMainloop structs only to
use it as a type for G_DEFINE_AUTOPTR_CLEANUP_FUNC.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-4-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 74102dc1482fa4b43068356dc11c848b6a133baf
      
https://github.com/qemu/qemu/commit/74102dc1482fa4b43068356dc11c848b6a133baf
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    A stubs/graph-lock.c
    M stubs/meson.build
    M util/async.c

  Log Message:
  -----------
  async: Register/unregister aiocontext in graph lock list

Add/remove the AioContext in aio_context_list in graph-lock.c when it is
created/destroyed. This allows using the graph locking operations from
this AioContext.

In order to allow linking util/async.c with binaries that don't include
the block layer, introduce stubs for (un)register_aiocontext().

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-5-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: a22640aea1d33c84d4e5c5c672c67d52dd72d607
      
https://github.com/qemu/qemu/commit/a22640aea1d33c84d4e5c5c672c67d52dd72d607
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    A include/qemu/clang-tsa.h

  Log Message:
  -----------
  Import clang-tsa.h

This defines macros that allow clang to perform Thread Safety Analysis
based on function and variable annotations that specify the locking
rules. On non-clang compilers, the annotations are ignored.

Imported tsa.h from the original repository with the pthread_mutex_t
wrapper removed:

https://github.com/jhi/clang-thread-safety-analysis-for-c.git

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-6-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 9471446d68328a97c3a988f12476ce5b42a411f6
      
https://github.com/qemu/qemu/commit/9471446d68328a97c3a988f12476ce5b42a411f6
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M include/qemu/clang-tsa.h

  Log Message:
  -----------
  clang-tsa: Add TSA_ASSERT() macro

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-7-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: e7a24d0eec0744d230d4a3bf2ab681ee944400ec
      
https://github.com/qemu/qemu/commit/e7a24d0eec0744d230d4a3bf2ab681ee944400ec
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M include/qemu/clang-tsa.h

  Log Message:
  -----------
  clang-tsa: Add macros for shared locks

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-8-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: f6749febcc3860ad7a27c50d68f05ea5c7fe93a1
      
https://github.com/qemu/qemu/commit/f6749febcc3860ad7a27c50d68f05ea5c7fe93a1
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M configure

  Log Message:
  -----------
  configure: Enable -Wthread-safety if present

This enables clang's thread safety analysis (TSA), which we'll use to
statically check the block graph locking.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-9-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: c05ca211a445b60cead625058b82c0c5db75fff5
      
https://github.com/qemu/qemu/commit/c05ca211a445b60cead625058b82c0c5db75fff5
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M tests/unit/test-bdrv-drain.c

  Log Message:
  -----------
  test-bdrv-drain: Fix incorrrect drain assumptions

The test case assumes that a drain only happens in one specific place
where it drains explicitly. This assumption happened to hold true until
now, but block layer functions may drain interally (any graph
modifications are going to do that through bdrv_graph_wrlock()), so this
is incorrect. Make sure that the test code in .drained_begin only runs
where we actually want it to run.

When scheduling a BH from .drained_begin, we also need to increase the
in_flight counter to make sure that the operation is actually completed
in time before the node that it works on goes away.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-10-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 6e41d1946fc3c7ddb4e41e9a84b8e89faf1fff69
      
https://github.com/qemu/qemu/commit/6e41d1946fc3c7ddb4e41e9a84b8e89faf1fff69
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M blockdev.c

  Log Message:
  -----------
  block: Fix locking in external_snapshot_prepare()

bdrv_img_create() polls internally (when calling bdrv_create(), which is
a co_wrapper), so it can't be called while holding the lock of any
AioContext except the current one without causing deadlocks. Drop the
lock around the call in external_snapshot_prepare().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-11-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: a05d4c5d9593b77892937de2c8d625388910dd13
      
https://github.com/qemu/qemu/commit/a05d4c5d9593b77892937de2c8d625388910dd13
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: wrlock in bdrv_replace_child_noperm

Protect the main function where graph is modified.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-12-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 5db06c5a9a1af25034511b628a2c2e3df47ec340
      
https://github.com/qemu/qemu/commit/5db06c5a9a1af25034511b628a2c2e3df47ec340
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c

  Log Message:
  -----------
  block: remove unnecessary assert_bdrv_graph_writable()

We don't protect bdrv->aio_context with the graph rwlock,
so these assertions are not needed

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-13-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: ca787bd2b7ddce9f11ffdaeacff54b5de61b94a2
      
https://github.com/qemu/qemu/commit/ca787bd2b7ddce9f11ffdaeacff54b5de61b94a2
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/graph-lock.c
    M include/block/block_int-global-state.h
    M include/block/graph-lock.h

  Log Message:
  -----------
  block: assert that graph read and writes are performed correctly

Remove the old assert_bdrv_graph_writable, and replace it with
the new version using graph-lock API.

See the function documentation for more information.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-14-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 00b2c73caee9e1aa18deecaa32bffc11ff99e925
      
https://github.com/qemu/qemu/commit/00b2c73caee9e1aa18deecaa32bffc11ff99e925
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/graph-lock.c
    M include/block/graph-lock.h

  Log Message:
  -----------
  graph-lock: TSA annotations for lock/unlock functions

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-15-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 0eb40a44d174e0a7208d43aa20d0a9de2f20571f
      
https://github.com/qemu/qemu/commit/0eb40a44d174e0a7208d43aa20d0a9de2f20571f
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M include/block/block_int-common.h
    M include/block/graph-lock.h

  Log Message:
  -----------
  Mark assert_bdrv_graph_readable/writable() GRAPH_RD/WRLOCK

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-16-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 13daa8b129f89523a705c3dd533a5fc6bb9ea763
      
https://github.com/qemu/qemu/commit/13daa8b129f89523a705c3dd533a5fc6bb9ea763
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M include/block/block-common.h
    M scripts/block-coroutine-wrapper.py

  Log Message:
  -----------
  block-coroutine-wrapper.py: introduce annotations that take the graph rdlock

Add co_wrapper_bdrv_rdlock and co_wrapper_mixed_bdrv_rdlock option to
the block-coroutine-wrapper.py script.

This "_bdrv_rdlock" option takes and releases the graph rdlock when a
coroutine function is created.

This means that when used together with "_mixed", the function marked
with co_wrapper_mixed_bdrv_rdlock will support both coroutine and
non-coroutine case, and in the latter case it will create a coroutine
that takes and releases the rdlock. When called from a coroutine, the
caller must already hold the graph lock.

Example:
void co_wrapper_mixed_bdrv_rdlock bdrv_f1();

Becomes

static void bdrv_co_enter_f1()
{
    bdrv_graph_co_rdlock();
    bdrv_co_function();
    bdrv_graph_co_rdunlock();
}

void bdrv_f1()
{
    if (qemu_in_coroutine) {
        assume_graph_lock();
        bdrv_co_function();
    } else {
        qemu_co_enter(bdrv_co_enter_f1);
        ...
    }
}

When used alone, the function will not work in coroutine context, and
when called in non-coroutine context it will create a new coroutine that
takes care of taking and releasing the rdlock automatically.

Example:
void co_wrapper_bdrv_rdlock bdrv_f1();

Becomes

static void bdrv_co_enter_f1()
{
    bdrv_graph_co_rdlock();
    bdrv_co_function();
    bdrv_graph_co_rdunlock();
}

void bdrv_f1()
{
    assert(!qemu_in_coroutine());
    qemu_co_enter(bdrv_co_enter_f1);
    ...
}

About their usage:
- co_wrapper does not take the rdlock, so it can be used also outside
  the block layer.
- co_wrapper_mixed will be used by many blk_* functions, since the
  coroutine function needs to call blk_wait_while_drained() and
  the rdlock *must* be taken afterwards, otherwise it's a deadlock.
  In the future this annotation will go away, and blk_* will use
  co_wrapper directly.
- co_wrapper_bdrv_rdlock will be used by BlockDriver callbacks, ideally
  by all of them in the future.
- co_wrapper_mixed_bdrv_rdlock will be used by the remaining functions
  that are still called by coroutine and non-coroutine context. In the
  future this annotation will go away, as we will split such mixed
  functions.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-17-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 1ad1fce171f668738915693fa182c654144cf3b6
      
https://github.com/qemu/qemu/commit/1ad1fce171f668738915693fa182c654144cf3b6
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block/coroutines.h
    M include/block/block-io.h

  Log Message:
  -----------
  block: use co_wrapper_mixed_bdrv_rdlock in functions taking the rdlock

Take the rdlock already, before we add the assertions.

All these functions either read the graph recursively, or call
BlockDriver callbacks that will eventually need to be protected by the
graph rdlock.

Do it now to all functions together, because many of these recursively
call each other.

For example, bdrv_co_truncate calls BlockDriver->bdrv_co_truncate, and
some driver callbacks implement their own .bdrv_co_truncate by calling
bdrv_flush inside. So if bdrv_flush asserts but bdrv_truncate does not
take the rdlock yet, the assertion will always fail.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-18-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 2ad19e5dc950d4b340894846b9e71c0b20f9a1cc
      
https://github.com/qemu/qemu/commit/2ad19e5dc950d4b340894846b9e71c0b20f9a1cc
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/coroutines.h
    M block/io.c
    M include/block/block_int-common.h

  Log Message:
  -----------
  block: GRAPH_RDLOCK for functions only called by co_wrappers

The generated coroutine wrappers already take care to take the lock in
the non-coroutine path, and assume that the lock is already taken in the
coroutine path.

The only thing we need to do for the wrapped function is adding the
GRAPH_RDLOCK annotation. Doing so also allows us to mark the
corresponding callbacks in BlockDriver as GRAPH_RDLOCK_PTR.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20221207131838.239125-19-kwolf@redhat.com>
Reviewed-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>


  Commit: 6c72e976fc3f9b276cbd37dfd555b2d789af01e1
      
https://github.com/qemu/qemu/commit/6c72e976fc3f9b276cbd37dfd555b2d789af01e1
  Author: Peter Maydell <peter.maydell@linaro.org>
  Date:   2022-12-14 (Wed, 14 Dec 2022)

  Changed paths:
    M block.c
    M block/block-backend.c
    M block/block-copy.c
    M block/block-gen.h
    M block/commit.c
    M block/coroutines.h
    M block/crypto.c
    M block/dirty-bitmap.c
    A block/graph-lock.c
    M block/io.c
    M block/meson.build
    M block/parallels.c
    M block/qcow.c
    M block/qcow2.c
    M block/qed.c
    M block/raw-format.c
    M block/replication.c
    M block/stream.c
    M block/throttle.c
    M block/vdi.c
    M block/vhdx.c
    M block/vmdk.c
    M block/vpc.c
    M blockdev.c
    M blockjob.c
    M configure
    M docs/devel/block-coroutine-wrapper.rst
    M include/block/aio.h
    M include/block/block-common.h
    M include/block/block-copy.h
    M include/block/block-global-state.h
    M include/block/block-io.h
    M include/block/block_int-common.h
    M include/block/block_int-global-state.h
    M include/block/block_int-io.h
    M include/block/block_int.h
    M include/block/dirty-bitmap.h
    A include/block/graph-lock.h
    A include/qemu/clang-tsa.h
    M include/sysemu/block-backend-io.h
    M nbd/server.c
    M scripts/block-coroutine-wrapper.py
    A stubs/graph-lock.c
    M stubs/meson.build
    M tests/unit/test-bdrv-drain.c
    M util/async.c

  Log Message:
  -----------
  Merge tag 'for-upstream' of https://repo.or.cz/qemu/kevin into staging

Block layer patches

- Code cleanups around block graph modification
- Simplify drain
- coroutine_fn correctness fixes, including splitting generated
  coroutine wrappers into co_wrapper (to be called only from
  non-coroutine context) and co_wrapper_mixed (both coroutine and
  non-coroutine context)
- Introduce a block graph rwlock

# gpg: Signature made Wed 14 Dec 2022 12:21:15 GMT
# gpg:                using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6
# gpg:                issuer "kwolf@redhat.com"
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full]
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74  56FE 7F09 B272 C88F 2FD6

* tag 'for-upstream' of https://repo.or.cz/qemu/kevin: (51 commits)
  block: GRAPH_RDLOCK for functions only called by co_wrappers
  block: use co_wrapper_mixed_bdrv_rdlock in functions taking the rdlock
  block-coroutine-wrapper.py: introduce annotations that take the graph rdlock
  Mark assert_bdrv_graph_readable/writable() GRAPH_RD/WRLOCK
  graph-lock: TSA annotations for lock/unlock functions
  block: assert that graph read and writes are performed correctly
  block: remove unnecessary assert_bdrv_graph_writable()
  block: wrlock in bdrv_replace_child_noperm
  block: Fix locking in external_snapshot_prepare()
  test-bdrv-drain: Fix incorrrect drain assumptions
  configure: Enable -Wthread-safety if present
  clang-tsa: Add macros for shared locks
  clang-tsa: Add TSA_ASSERT() macro
  Import clang-tsa.h
  async: Register/unregister aiocontext in graph lock list
  graph-lock: Implement guard macros
  graph-lock: Introduce a lock to protect block graph operations
  block: Factor out bdrv_drain_all_begin_nopoll()
  block/dirty-bitmap: convert coroutine-only functions to co_wrapper
  block: convert bdrv_create to co_wrapper
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Compare: https://github.com/qemu/qemu/compare/b2fda7db99b6...6c72e976fc3f



reply via email to

[Prev in Thread] Current Thread [Next in Thread]