qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-block@nongnu.org, pbonzini@redhat.com, eesposit@redhat.com,
	qemu-devel@nongnu.org
Subject: Re: [PATCH 05/20] test-bdrv-drain: Don't modify the graph in coroutines
Date: Mon, 1 May 2023 11:30:59 -0400	[thread overview]
Message-ID: <20230501153059.GG14869@fedora> (raw)
In-Reply-To: <20230425173158.574203-6-kwolf@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 7200 bytes --]

On Tue, Apr 25, 2023 at 07:31:43PM +0200, Kevin Wolf wrote:
> test-bdrv-drain contains a few test cases that are run both in coroutine
> and non-coroutine context. Running the entire code including the setup
> and shutdown in coroutines is incorrect because graph modifications can
> generally not happen in coroutines.
> 
> Change the test so that creating and destroying the test nodes and
> BlockBackends always happens outside of coroutine context.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  tests/unit/test-bdrv-drain.c | 112 +++++++++++++++++++++++------------
>  1 file changed, 75 insertions(+), 37 deletions(-)
> 
> diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c
> index d9d3807062..765ae382da 100644
> --- a/tests/unit/test-bdrv-drain.c
> +++ b/tests/unit/test-bdrv-drain.c
> @@ -188,6 +188,25 @@ static void do_drain_begin_unlocked(enum drain_type drain_type, BlockDriverState
>      }
>  }
>  
> +static BlockBackend * no_coroutine_fn test_setup(void)
> +{
> +    BlockBackend *blk;
> +    BlockDriverState *bs, *backing;
> +
> +    blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL);
> +    bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR,
> +                              &error_abort);
> +    blk_insert_bs(blk, bs, &error_abort);
> +
> +    backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
> +    bdrv_set_backing_hd(bs, backing, &error_abort);
> +
> +    bdrv_unref(backing);
> +    bdrv_unref(bs);
> +
> +    return blk;
> +}
> +
>  static void do_drain_end_unlocked(enum drain_type drain_type, BlockDriverState *bs)
>  {
>      if (drain_type != BDRV_DRAIN_ALL) {
> @@ -199,25 +218,19 @@ static void do_drain_end_unlocked(enum drain_type drain_type, BlockDriverState *
>      }
>  }
>  
> -static void test_drv_cb_common(enum drain_type drain_type, bool recursive)
> +static void test_drv_cb_common(BlockBackend *blk, enum drain_type drain_type,
> +                               bool recursive)
>  {
> -    BlockBackend *blk;
> -    BlockDriverState *bs, *backing;
> +    BlockDriverState *bs = blk_bs(blk);
> +    BlockDriverState *backing = bs->backing->bs;
>      BDRVTestState *s, *backing_s;
>      BlockAIOCB *acb;
>      int aio_ret;
>  
>      QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, 0);
>  
> -    blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL);
> -    bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR,
> -                              &error_abort);
>      s = bs->opaque;
> -    blk_insert_bs(blk, bs, &error_abort);
> -
> -    backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
>      backing_s = backing->opaque;
> -    bdrv_set_backing_hd(bs, backing, &error_abort);
>  
>      /* Simple bdrv_drain_all_begin/end pair, check that CBs are called */
>      g_assert_cmpint(s->drain_count, ==, 0);
> @@ -252,44 +265,53 @@ static void test_drv_cb_common(enum drain_type drain_type, bool recursive)
>  
>      g_assert_cmpint(s->drain_count, ==, 0);
>      g_assert_cmpint(backing_s->drain_count, ==, 0);
> -
> -    bdrv_unref(backing);
> -    bdrv_unref(bs);
> -    blk_unref(blk);
>  }
>  
>  static void test_drv_cb_drain_all(void)
>  {
> -    test_drv_cb_common(BDRV_DRAIN_ALL, true);
> +    BlockBackend *blk = test_setup();
> +    test_drv_cb_common(blk, BDRV_DRAIN_ALL, true);
> +    blk_unref(blk);
>  }
>  
>  static void test_drv_cb_drain(void)
>  {
> -    test_drv_cb_common(BDRV_DRAIN, false);
> +    BlockBackend *blk = test_setup();
> +    test_drv_cb_common(blk, BDRV_DRAIN, false);
> +    blk_unref(blk);
> +}
> +
> +static void test_drv_cb_co_drain_all_entry(void)

Missing coroutine_fn.

> +{
> +    BlockBackend *blk = blk_all_next(NULL);
> +    test_drv_cb_common(blk, BDRV_DRAIN_ALL, true);
>  }
>  
>  static void test_drv_cb_co_drain_all(void)
>  {
> -    call_in_coroutine(test_drv_cb_drain_all);
> +    BlockBackend *blk = test_setup();
> +    call_in_coroutine(test_drv_cb_co_drain_all_entry);
> +    blk_unref(blk);
>  }
>  
> -static void test_drv_cb_co_drain(void)
> +static void test_drv_cb_co_drain_entry(void)

Missing coroutine_fn.

>  {
> -    call_in_coroutine(test_drv_cb_drain);
> +    BlockBackend *blk = blk_all_next(NULL);
> +    test_drv_cb_common(blk, BDRV_DRAIN, false);
>  }
>  
> -static void test_quiesce_common(enum drain_type drain_type, bool recursive)
> +static void test_drv_cb_co_drain(void)
>  {
> -    BlockBackend *blk;
> -    BlockDriverState *bs, *backing;
> -
> -    blk = blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL);
> -    bs = bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR,
> -                              &error_abort);
> -    blk_insert_bs(blk, bs, &error_abort);
> +    BlockBackend *blk = test_setup();
> +    call_in_coroutine(test_drv_cb_co_drain_entry);
> +    blk_unref(blk);
> +}
>  
> -    backing = bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abort);
> -    bdrv_set_backing_hd(bs, backing, &error_abort);
> +static void test_quiesce_common(BlockBackend *blk, enum drain_type drain_type,
> +                                bool recursive)
> +{
> +    BlockDriverState *bs = blk_bs(blk);
> +    BlockDriverState *backing = bs->backing->bs;
>  
>      g_assert_cmpint(bs->quiesce_counter, ==, 0);
>      g_assert_cmpint(backing->quiesce_counter, ==, 0);
> @@ -307,30 +329,46 @@ static void test_quiesce_common(enum drain_type drain_type, bool recursive)
>  
>      g_assert_cmpint(bs->quiesce_counter, ==, 0);
>      g_assert_cmpint(backing->quiesce_counter, ==, 0);
> -
> -    bdrv_unref(backing);
> -    bdrv_unref(bs);
> -    blk_unref(blk);
>  }
>  
>  static void test_quiesce_drain_all(void)
>  {
> -    test_quiesce_common(BDRV_DRAIN_ALL, true);
> +    BlockBackend *blk = test_setup();
> +    test_quiesce_common(blk, BDRV_DRAIN_ALL, true);
> +    blk_unref(blk);
>  }
>  
>  static void test_quiesce_drain(void)
>  {
> -    test_quiesce_common(BDRV_DRAIN, false);
> +    BlockBackend *blk = test_setup();
> +    test_quiesce_common(blk, BDRV_DRAIN, false);
> +    blk_unref(blk);
> +}
> +
> +static void test_quiesce_co_drain_all_entry(void)

Missing coroutine_fn.

> +{
> +    BlockBackend *blk = blk_all_next(NULL);
> +    test_quiesce_common(blk, BDRV_DRAIN_ALL, true);
>  }
>  
>  static void test_quiesce_co_drain_all(void)
>  {
> -    call_in_coroutine(test_quiesce_drain_all);
> +    BlockBackend *blk = test_setup();
> +    call_in_coroutine(test_quiesce_co_drain_all_entry);
> +    blk_unref(blk);
> +}
> +
> +static void test_quiesce_co_drain_entry(void)

Missing coroutine_fn.

> +{
> +    BlockBackend *blk = blk_all_next(NULL);
> +    test_quiesce_common(blk, BDRV_DRAIN, false);
>  }
>  
>  static void test_quiesce_co_drain(void)
>  {
> -    call_in_coroutine(test_quiesce_drain);
> +    BlockBackend *blk = test_setup();
> +    call_in_coroutine(test_quiesce_co_drain_entry);
> +    blk_unref(blk);
>  }
>  
>  static void test_nested(void)
> -- 
> 2.40.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2023-05-01 15:32 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 17:31 [PATCH 00/20] Graph locking, part 3 (more block drivers) Kevin Wolf
2023-04-25 17:31 ` [PATCH 01/20] qcow2: Don't call bdrv_getlength() in coroutine_fns Kevin Wolf
2023-04-25 18:37   ` Eric Blake
2023-04-27 11:12     ` Kevin Wolf
2023-04-27 15:07       ` Eric Blake
2023-05-01 15:19   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 02/20] block: Consistently call bdrv_activate() outside coroutine Kevin Wolf
2023-04-25 18:39   ` Eric Blake
2023-05-01 15:21   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 03/20] block: bdrv/blk_co_unref() for calls in coroutine context Kevin Wolf
2023-04-25 20:04   ` Eric Blake
2023-04-27 14:30   ` Paolo Bonzini
2023-04-27 17:00     ` Kevin Wolf
2023-04-27 20:49       ` Paolo Bonzini
2023-05-04 11:18         ` Kevin Wolf
2023-05-01 15:23   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 04/20] block: Don't call no_coroutine_fns in qmp_block_resize() Kevin Wolf
2023-04-25 20:08   ` Eric Blake
2023-04-27 11:15     ` Kevin Wolf
2023-04-27 15:09       ` Eric Blake
2023-05-01 15:24   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 05/20] test-bdrv-drain: Don't modify the graph in coroutines Kevin Wolf
2023-04-25 20:10   ` Eric Blake
2023-05-01 15:30   ` Stefan Hajnoczi [this message]
2023-04-25 17:31 ` [PATCH 06/20] graph-lock: Add GRAPH_UNLOCKED(_PTR) Kevin Wolf
2023-04-25 20:20   ` Eric Blake
2023-05-01 15:32   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 07/20] graph-lock: Fix GRAPH_RDLOCK_GUARD*() to be reader lock Kevin Wolf
2023-04-25 20:36   ` Eric Blake
2023-04-27 11:28     ` Kevin Wolf
2023-04-27 15:15       ` Eric Blake
2023-05-01 15:34   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 08/20] block: .bdrv_open is non-coroutine and unlocked Kevin Wolf
2023-04-25 21:04   ` Eric Blake
2023-05-01 16:01   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 09/20] nbd: Remove nbd_co_flush() wrapper function Kevin Wolf
2023-04-25 21:05   ` Eric Blake
2023-05-01 16:02   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 10/20] nbd: Mark nbd_co_do_establish_connection() and callers GRAPH_RDLOCK Kevin Wolf
2023-04-25 21:07   ` Eric Blake
2023-05-01 18:57   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 11/20] vhdx: Take graph lock for accessing a node's parent list Kevin Wolf
2023-04-25 21:08   ` Eric Blake
2023-05-01 18:58   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 12/20] mirror: " Kevin Wolf
2023-04-25 21:09   ` Eric Blake
2023-05-01 18:59   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 13/20] block: Mark bdrv_co_get_allocated_file_size() and callers GRAPH_RDLOCK Kevin Wolf
2023-04-25 21:10   ` Eric Blake
2023-05-01 19:03   ` Stefan Hajnoczi
2023-05-04 10:52     ` Kevin Wolf
2023-04-25 17:31 ` [PATCH 14/20] block: Mark bdrv_co_get_info() " Kevin Wolf
2023-04-25 21:12   ` Eric Blake
2023-05-01 19:04   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 15/20] block: Mark bdrv_co_debug_event() GRAPH_RDLOCK Kevin Wolf
2023-04-25 21:14   ` Eric Blake
2023-05-04 11:12     ` Kevin Wolf
2023-05-01 19:05   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 16/20] block: Mark BlockDriver callbacks for amend job GRAPH_RDLOCK Kevin Wolf
2023-04-25 21:20   ` Eric Blake
2023-05-01 19:07   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 17/20] block: Mark bdrv_query_bds_stats() and callers GRAPH_RDLOCK Kevin Wolf
2023-04-25 21:20   ` Eric Blake
2023-05-01 19:08   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 18/20] block: Mark bdrv_query_block_graph_info() " Kevin Wolf
2023-04-25 21:21   ` Eric Blake
2023-05-01 19:08   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 19/20] block: Mark bdrv_recurse_can_replace() " Kevin Wolf
2023-04-25 21:22   ` Eric Blake
2023-05-01 19:10   ` Stefan Hajnoczi
2023-04-25 17:31 ` [PATCH 20/20] block: Mark bdrv_refresh_limits() " Kevin Wolf
2023-04-25 21:23   ` Eric Blake
2023-05-01 19:10   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230501153059.GG14869@fedora \
    --to=stefanha@redhat.com \
    --cc=eesposit@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).