From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org
Subject: [PULL 12/28] test-bdrv-drain: Don't modify the graph in coroutines
Date: Wed, 10 May 2023 14:20:55 +0200 [thread overview]
Message-ID: <20230510122111.46566-13-kwolf@redhat.com> (raw)
In-Reply-To: <20230510122111.46566-1-kwolf@redhat.com>
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>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20230504115750.54437-6-kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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..9a4c5e59d6 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 coroutine_fn test_drv_cb_co_drain_all_entry(void)
+{
+ 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 coroutine_fn test_drv_cb_co_drain_entry(void)
{
- 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 coroutine_fn test_quiesce_co_drain_all_entry(void)
+{
+ 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 coroutine_fn test_quiesce_co_drain_entry(void)
+{
+ 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.1
next prev parent reply other threads:[~2023-05-10 12:26 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-10 12:20 [PULL 00/28] Block layer patches Kevin Wolf
2023-05-10 12:20 ` [PULL 01/28] block: add configure options for excluding vmdk, vhdx and vpc Kevin Wolf
2023-05-10 12:20 ` [PULL 02/28] block: add missing coroutine_fn annotations Kevin Wolf
2023-05-10 12:20 ` [PULL 03/28] aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() Kevin Wolf
2023-05-10 12:20 ` [PULL 04/28] block: Fix use after free in blockdev_mark_auto_del() Kevin Wolf
2023-05-10 12:20 ` [PULL 05/28] iotests/nbd-reconnect-on-open: Fix NBD socket path Kevin Wolf
2023-05-10 12:20 ` [PULL 06/28] migration: Attempt disk reactivation in more failure scenarios Kevin Wolf
2023-05-10 12:20 ` [PULL 07/28] qcow2: Don't call bdrv_getlength() in coroutine_fns Kevin Wolf
2023-05-10 12:20 ` [PULL 08/28] block: Consistently call bdrv_activate() outside coroutine Kevin Wolf
2023-05-10 12:20 ` [PULL 09/28] block: bdrv/blk_co_unref() for calls in coroutine context Kevin Wolf
2023-05-11 15:32 ` Michael Tokarev
2023-05-15 13:07 ` Kevin Wolf
2023-05-15 14:25 ` Michael Tokarev
2023-05-10 12:20 ` [PULL 10/28] block: Don't call no_coroutine_fns in qmp_block_resize() Kevin Wolf
2023-05-10 12:20 ` [PULL 11/28] iotests: Test resizing image attached to an iothread Kevin Wolf
2023-05-10 12:20 ` Kevin Wolf [this message]
2023-05-10 12:20 ` [PULL 13/28] graph-lock: Add GRAPH_UNLOCKED(_PTR) Kevin Wolf
2023-05-10 12:20 ` [PULL 14/28] graph-lock: Fix GRAPH_RDLOCK_GUARD*() to be reader lock Kevin Wolf
2023-05-10 12:20 ` [PULL 15/28] block: .bdrv_open is non-coroutine and unlocked Kevin Wolf
2023-05-10 12:20 ` [PULL 16/28] nbd: Remove nbd_co_flush() wrapper function Kevin Wolf
2023-05-10 12:21 ` [PULL 17/28] nbd: Mark nbd_co_do_establish_connection() and callers GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 18/28] vhdx: Require GRAPH_RDLOCK for accessing a node's parent list Kevin Wolf
2023-05-10 12:21 ` [PULL 19/28] mirror: " Kevin Wolf
2023-05-10 12:21 ` [PULL 20/28] block: Mark bdrv_co_get_allocated_file_size() and callers GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 21/28] block: Mark bdrv_co_get_info() " Kevin Wolf
2023-05-10 12:21 ` [PULL 22/28] block: Mark bdrv_co_debug_event() GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 23/28] block: Mark BlockDriver callbacks for amend job GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 24/28] block: Mark bdrv_query_bds_stats() and callers GRAPH_RDLOCK Kevin Wolf
2023-05-10 12:21 ` [PULL 25/28] block: Mark bdrv_query_block_graph_info() " Kevin Wolf
2023-05-10 12:21 ` [PULL 26/28] block: Mark bdrv_recurse_can_replace() " Kevin Wolf
2023-05-10 12:21 ` [PULL 27/28] block: Mark bdrv_refresh_limits() " Kevin Wolf
2023-05-10 12:21 ` [PULL 28/28] block: compile out assert_bdrv_graph_readable() by default Kevin Wolf
2023-05-10 15:42 ` [PULL 00/28] Block layer patches Richard Henderson
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=20230510122111.46566-13-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.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).