qemu-commits
[Top][All Lists]
Advanced

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

[Qemu-commits] [qemu/qemu] 00eb93: block: Inline bdrv_detach_child()


From: Peter Maydell
Subject: [Qemu-commits] [qemu/qemu] 00eb93: block: Inline bdrv_detach_child()
Date: Fri, 16 Dec 2022 13:43:37 -0800

  Branch: refs/heads/master
  Home:   https://github.com/qemu/qemu
  Commit: 00eb93b5886519a35a06bf403e5be4c4cb3df25a
      
https://github.com/qemu/qemu/commit/00eb93b5886519a35a06bf403e5be4c4cb3df25a
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-15 (Thu, 15 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: f38eaec4c3618dfc4a23e20435cefb5bf8325264
      
https://github.com/qemu/qemu/commit/f38eaec4c3618dfc4a23e20435cefb5bf8325264
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-15 (Thu, 15 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: f1316edbfcea3b31181f22d737ac7cf80b395355
      
https://github.com/qemu/qemu/commit/f1316edbfcea3b31181f22d737ac7cf80b395355
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-15 (Thu, 15 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: fb0ff4d1baf8012e7f358daf007967d65e1f545a
      
https://github.com/qemu/qemu/commit/fb0ff4d1baf8012e7f358daf007967d65e1f545a
  Author: Vladimir Sementsov-Ogievskiy <vladimir.sementsov-ogievskiy@openvz.org>
  Date:   2022-12-15 (Thu, 15 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: 6d47eb0c8bf2d50682c7dccae74d24104076fe23
      
https://github.com/qemu/qemu/commit/6d47eb0c8bf2d50682c7dccae74d24104076fe23
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 7bce1c299834557bffd92294608ea528648cfe75
      
https://github.com/qemu/qemu/commit/7bce1c299834557bffd92294608ea528648cfe75
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 5e8ac21717373cbe96ef7a91e216bf5788815d63
      
https://github.com/qemu/qemu/commit/5e8ac21717373cbe96ef7a91e216bf5788815d63
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 2f65df6e16dea2d6e7212fa675f4779d9281e26f
      
https://github.com/qemu/qemu/commit/2f65df6e16dea2d6e7212fa675f4779d9281e26f
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: c7bc05f78ab31fb02fc9635f60b9bd22efc8d121
      
https://github.com/qemu/qemu/commit/c7bc05f78ab31fb02fc9635f60b9bd22efc8d121
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 2e117866d7c96cc17e84cd2946fee1bf3292d814
      
https://github.com/qemu/qemu/commit/2e117866d7c96cc17e84cd2946fee1bf3292d814
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: d22933acd2f470eeef779e4d444e848f76dcfaf8
      
https://github.com/qemu/qemu/commit/d22933acd2f470eeef779e4d444e848f76dcfaf8
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 631086deefc32690ee56efed1c5b891dec31ae37
      
https://github.com/qemu/qemu/commit/631086deefc32690ee56efed1c5b891dec31ae37
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 92140b9f3f07d80e2c27edcc6e32f392be2135e6
      
https://github.com/qemu/qemu/commit/92140b9f3f07d80e2c27edcc6e32f392be2135e6
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 299403aedaeb7f08d8e98aa8614b29d4e5546066
      
https://github.com/qemu/qemu/commit/299403aedaeb7f08d8e98aa8614b29d4e5546066
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 57e05be343f33f4e5899a8d8946a8596d68424a1
      
https://github.com/qemu/qemu/commit/57e05be343f33f4e5899a8d8946a8596d68424a1
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: a82a3bd135078d14f1bb4b5e50f51e77d3748270
      
https://github.com/qemu/qemu/commit/a82a3bd135078d14f1bb4b5e50f51e77d3748270
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 05c272ff0cf1b16cc3606f746182dd99b774f553
      
https://github.com/qemu/qemu/commit/05c272ff0cf1b16cc3606f746182dd99b774f553
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 23987471285a26397e3152a9244b652445fd36c4
      
https://github.com/qemu/qemu/commit/23987471285a26397e3152a9244b652445fd36c4
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 606ed756c1d69cba4822be8923248d2fd714f069
      
https://github.com/qemu/qemu/commit/606ed756c1d69cba4822be8923248d2fd714f069
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 7b52a921c12c01be3b2ce331081dd9accea99948
      
https://github.com/qemu/qemu/commit/7b52a921c12c01be3b2ce331081dd9accea99948
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 43a0d4f08b7a7bae90c0753db2b49441ef3e7f6e
      
https://github.com/qemu/qemu/commit/43a0d4f08b7a7bae90c0753db2b49441ef3e7f6e
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 6f58ac55396bc624c78e73939d5fe6a44a13d150
      
https://github.com/qemu/qemu/commit/6f58ac55396bc624c78e73939d5fe6a44a13d150
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: ff7e261bb91ecf44df12a551582187ddf6b187fe
      
https://github.com/qemu/qemu/commit/ff7e261bb91ecf44df12a551582187ddf6b187fe
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: f7f93a478a0c5d134d80afff7203e0aef788e5cd
      
https://github.com/qemu/qemu/commit/f7f93a478a0c5d134d80afff7203e0aef788e5cd
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: a212e675cde67fb783b7f8e5b31dd02e9c880f58
      
https://github.com/qemu/qemu/commit/a212e675cde67fb783b7f8e5b31dd02e9c880f58
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 84bdf21f97e670d61615d44a95d2f33b41f849b1
      
https://github.com/qemu/qemu/commit/84bdf21f97e670d61615d44a95d2f33b41f849b1
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 2475a0d0f4b0b450f25f7672c7072b4fdae6df00
      
https://github.com/qemu/qemu/commit/2475a0d0f4b0b450f25f7672c7072b4fdae6df00
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 1bd542016cc2c132e3d52dbc9e663966dfc10e72
      
https://github.com/qemu/qemu/commit/1bd542016cc2c132e3d52dbc9e663966dfc10e72
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 76a2f554c1e7b8acb332f765034fdf0ab3525202
      
https://github.com/qemu/qemu/commit/76a2f554c1e7b8acb332f765034fdf0ab3525202
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 0582fb8293ad4a5d67810fb362789eba6e0ae75e
      
https://github.com/qemu/qemu/commit/0582fb8293ad4a5d67810fb362789eba6e0ae75e
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 6700dfb1b8c2828aa0c851136892c4774de87c95
      
https://github.com/qemu/qemu/commit/6700dfb1b8c2828aa0c851136892c4774de87c95
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 741443eb4301eb130dab812c7ae7cfd71a68a679
      
https://github.com/qemu/qemu/commit/741443eb4301eb130dab812c7ae7cfd71a68a679
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 0508d0be4b547be8da97c95ea9e1f433077dd2ec
      
https://github.com/qemu/qemu/commit/0508d0be4b547be8da97c95ea9e1f433077dd2ec
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: da0bd744344adb1f285002467d7fa84699dc2fce
      
https://github.com/qemu/qemu/commit/da0bd744344adb1f285002467d7fa84699dc2fce
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: aead9dc9d1acc5876951885c064ec4153fbd0ed8
      
https://github.com/qemu/qemu/commit/aead9dc9d1acc5876951885c064ec4153fbd0ed8
  Author: Paolo Bonzini <pbonzini@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 8aa77000c2ba8c234f72b9b4162529d02ea00188
      
https://github.com/qemu/qemu/commit/8aa77000c2ba8c234f72b9b4162529d02ea00188
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 587d82fae258794e33cacc9bf4ba61949184e822
      
https://github.com/qemu/qemu/commit/587d82fae258794e33cacc9bf4ba61949184e822
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 702152d1c72225d318bb1626b457f87719cc2f25
      
https://github.com/qemu/qemu/commit/702152d1c72225d318bb1626b457f87719cc2f25
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: b1cc02e9463a406c6edd7ac55e356cf65a0681d7
      
https://github.com/qemu/qemu/commit/b1cc02e9463a406c6edd7ac55e356cf65a0681d7
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: d9bfb9de00d4ee15908cc2f76333d6657b580dea
      
https://github.com/qemu/qemu/commit/d9bfb9de00d4ee15908cc2f76333d6657b580dea
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 617f3a963589dbd54fe1f323eeac36411b352a0e
      
https://github.com/qemu/qemu/commit/617f3a963589dbd54fe1f323eeac36411b352a0e
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: e13550558840422f980a0a71efe52ee83f37933d
      
https://github.com/qemu/qemu/commit/e13550558840422f980a0a71efe52ee83f37933d
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 293125078086027ee625b3fae23b374ad08f98c8
      
https://github.com/qemu/qemu/commit/293125078086027ee625b3fae23b374ad08f98c8
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 1af823923541ddfa0bfe51af5f40e9a8469e8992
      
https://github.com/qemu/qemu/commit/1af823923541ddfa0bfe51af5f40e9a8469e8992
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 3f35f82e04923affb3283b451b6d66880f266a5a
      
https://github.com/qemu/qemu/commit/3f35f82e04923affb3283b451b6d66880f266a5a
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 4002ffdc4fa7a2fd9b5a86772311c646a73775f7
      
https://github.com/qemu/qemu/commit/4002ffdc4fa7a2fd9b5a86772311c646a73775f7
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 303de47b2c1e20a7f326ad11976d6006f5498709
      
https://github.com/qemu/qemu/commit/303de47b2c1e20a7f326ad11976d6006f5498709
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: e6d3f7a602a370362bc52b0aed7dfff1a0bf726d
      
https://github.com/qemu/qemu/commit/e6d3f7a602a370362bc52b0aed7dfff1a0bf726d
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 90830f595062ecf0d2c96049f5e01f3d37a2107f
      
https://github.com/qemu/qemu/commit/90830f595062ecf0d2c96049f5e01f3d37a2107f
  Author: Emanuele Giuseppe Esposito <eesposit@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: 1b3ff9feb942c2ad0b01ac931e99ad451ab0ef39
      
https://github.com/qemu/qemu/commit/1b3ff9feb942c2ad0b01ac931e99ad451ab0ef39
  Author: Kevin Wolf <kwolf@redhat.com>
  Date:   2022-12-15 (Thu, 15 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: d038d2645acabf6f52fd61baeaa021c3ebe97714
      
https://github.com/qemu/qemu/commit/d038d2645acabf6f52fd61baeaa021c3ebe97714
  Author: Peter Maydell <peter.maydell@linaro.org>
  Date:   2022-12-16 (Fri, 16 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 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 Thu 15 Dec 2022 15:08:34 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: (50 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
  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
  block-coroutine-wrapper.py: support also basic return types
  ...

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


Compare: https://github.com/qemu/qemu/compare/4208e6ae114a...d038d2645aca



reply via email to

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