@@ -939,10 +939,10 @@ static void test_blockjob_common_drain_node(enum drain_type drain_type,
blk_insert_bs(blk_target, target, &error_abort);
blk_set_allow_aio_context_change(blk_target, true);
- aio_context_acquire(ctx);
tjob = block_job_create("job0", &test_job_driver, NULL, src,
0, BLK_PERM_ALL,
0, 0, NULL, NULL, &error_abort);
+ aio_context_acquire(ctx);
job = &tjob->common;
block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abort);
@@ -1388,8 +1388,6 @@ static void test_detach_indirect(bool by_parent_cb)
if (!by_parent_cb) {
detach_by_driver_cb_class = child_of_bds;
- detach_by_driver_cb_class.drained_begin =
- detach_by_driver_cb_drained_begin;
}
/* Create all involved nodes */
@@ -1447,6 +1445,12 @@ static void test_detach_indirect(bool by_parent_cb)
acb = blk_aio_preadv(blk, 0, &qiov, 0, detach_by_parent_aio_cb, NULL);
g_assert(acb != NULL);
+ if (!by_parent_cb) {
+ /* set .drained_begin cb to run only in the following drain. */
+ detach_by_driver_cb_class.drained_begin =
+ detach_by_driver_cb_drained_begin;
+ }
+
/* Drain and check the expected result */
bdrv_subtree_drained_begin(parent_b);
@@ -1470,6 +1474,12 @@ static void test_detach_indirect(bool by_parent_cb)
bdrv_subtree_drained_end(parent_b);
+ if (!by_parent_cb) {
+ /* restore .drained_begin cb, we don't need it anymore. */
+ detach_by_driver_cb_class.drained_begin =
+ child_of_bds.drained_begin;
+ }
+
bdrv_unref(parent_b);
blk_unref(blk);
@@ -1483,7 +1493,7 @@ static void test_detach_indirect(bool by_parent_cb)
static void test_detach_by_parent_cb(void)
{
- test_detach_indirect(true);
+ /* test_detach_indirect(true); */
}
static void test_detach_by_driver_cb(void)
There are a couple of problems in this test when we add subtree drains in bdrv_replace_child_noperm: - First of all, inconsistency between block_job_create under aiocontext lock that internally calls blk_insert_bs and therefore bdrv_replace_child_noperm, and blk_insert_bs that is called two lines above in the same test without aiocontext. Since we use the unlocked subtree_drain, we want to move the aiocontext further down. - test_detach_by_parent_cb: this test uses a callback of an I/O function (blk_aio_preadv) to modify the grah, using bdrv_attach_child. This is simply not allowed anymore. I/O cannot change the graph. - test_detach_indirect: here it is simply a matter of wrong callbacks used. In the original test, there was only a subtree drain, so overriding .drained_begin was not a problem. Now that we have additional subtree drains, we risk to call the test callback to early, or multiple times. We do not want that, so override the callback only when we actually want to use it. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> --- tests/unit/test-bdrv-drain.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)