From nobody Sun May 19 13:07:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1670242295; cv=none; d=zohomail.com; s=zohoarc; b=EGkyCOq7nZ5t75pn8/kG1bROIvicAMHLUh6UxY5OGU1Ie0a4/fkRyV5w1Aze1gDkWg2KIfk6upKqtMkKiBHNBJJkiQFOQH9ZFnQAlbDEC8bM1p4DMsAbJfDRThJwwKOmV3+/JG34sCiHA9sbGvwnZsESkRXj4Met5h3BWDwi0a4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670242295; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dbPu+vp7PvZVFJ3apwCjuxKxuDzeG7IZ/szZJOYbpI0=; b=eyemtuOOYUaWBJPSzs91yQXR/wgBET5V+g4JbVj9N9aqKqr80VHMbzStWXlv8uwnPu78CDol5YNtCxcQY1SH7vGOTY/G+34TyD3krRz98OmDZKqvRO7YDb+s01FNvC8i5q6JuE41PAzWlnttUVTjRmCGxQS33sL8l6ETrK+XAyA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1670242295783147.09429925301004; Mon, 5 Dec 2022 04:11:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2AIz-0008J0-8R; Mon, 05 Dec 2022 07:10:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2AIv-0008IG-KS for qemu-devel@nongnu.org; Mon, 05 Dec 2022 07:10:37 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2AIt-0006Xi-Hv for qemu-devel@nongnu.org; Mon, 05 Dec 2022 07:10:37 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-rWfHHguYO9iwyG5y3Xp4Ig-1; Mon, 05 Dec 2022 07:10:33 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9EB98800B23; Mon, 5 Dec 2022 12:10:32 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AC8263F45; Mon, 5 Dec 2022 12:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670242234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dbPu+vp7PvZVFJ3apwCjuxKxuDzeG7IZ/szZJOYbpI0=; b=I8EBM/PEgFdsZOwQohLnK6GDhOdTz5bu+Vr1GoYH7HtYJGL7uVRc8Py0h88RJZ3wCiR/PN rjakwga8d8e1s4qeLzNRszDMyPJoOwb90JdDgg/AFemNNxuC9lnBPgZtKApempf38iuv9a 5x5eIDCj249HUxbWxv6BJQpahp1jEhI= X-MC-Unique: rWfHHguYO9iwyG5y3Xp4Ig-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , Hanna Reitz , Stefan Hajnoczi , Emanuele Giuseppe Esposito Subject: [PATCH 1/2] test-bdrv-drain.c: remove test_detach_by_parent_cb() Date: Mon, 5 Dec 2022 07:10:28 -0500 Message-Id: <20221205121029.1089209-2-eesposit@redhat.com> In-Reply-To: <20221205121029.1089209-1-eesposit@redhat.com> References: <20221205121029.1089209-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1670242296836100002 Content-Type: text/plain; charset="utf-8" This test uses a callback of an I/O function (blk_aio_preadv) to modify the graph, using bdrv_attach_child. This is simply not allowed anymore. I/O cannot change the graph. The problem in this test is in: acb =3D blk_aio_preadv(blk, 0, &qiov, 0, detach_by_parent_aio_cb, NULL); /* Drain and check the expected result */ bdrv_subtree_drained_begin(parent_b); because the detach_by_parent_aio_cb calls detach_indirect_bh(), that modifies the graph and is invoked during bdrv_subtree_drained_begin(). The call stack is the following: 1. blk_aio_preadv() creates a coroutine, increments in_flight counter and enters the coroutine running blk_aio_read_entry() 2. blk_aio_read_entry() performs the read and then schedules a bh to complete (blk_aio_complete) 3. at this point, subtree_drained_begin() kicks in and waits for all in_flight requests, polling 4. polling allows the bh to be scheduled, so blk_aio_complete runs 5. blk_aio_complete *first* invokes the callback (detach_by_parent_aio_cb) and then decrements the in_flight counter 6. Here is the problem: detach_by_parent_aio_cb modifies the graph, so both bdrv_unref_child() and bdrv_attach_child() will have subtree_drains inside. And this causes a deadlock, because the nested drain will wait for in_flight counter to go to zero, which is only happening once the drain itself finishes. Different story is test_detach_by_driver_cb(): in this case, detach_by_parent_aio_cb() does not call detach_indirect_bh(), but it is instead called as a bh running in the main loop by detach_by_driver_cb_drained_begin(), the callback for .drained_begin(). This test was added in 231281ab42 and part of the series "Drain fixes and cleanups, part 3" https://lists.nongnu.org/archive/html/qemu-block/2018-05/msg01132.html but as explained above I believe that it is not valid anymore, and can be discarded. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi --- tests/unit/test-bdrv-drain.c | 41 ++++++++---------------------------- 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 09dc4a4891..4ce159250e 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1316,7 +1316,6 @@ struct detach_by_parent_data { BdrvChild *child_b; BlockDriverState *c; BdrvChild *child_c; - bool by_parent_cb; }; static struct detach_by_parent_data detach_by_parent_data; =20 @@ -1334,12 +1333,7 @@ static void detach_indirect_bh(void *opaque) =20 static void detach_by_parent_aio_cb(void *opaque, int ret) { - struct detach_by_parent_data *data =3D &detach_by_parent_data; - g_assert_cmpint(ret, =3D=3D, 0); - if (data->by_parent_cb) { - detach_indirect_bh(data); - } } =20 static void detach_by_driver_cb_drained_begin(BdrvChild *child) @@ -1358,33 +1352,25 @@ static BdrvChildClass detach_by_driver_cb_class; * \ / \ * A B C * - * by_parent_cb =3D=3D true: Test that parent callbacks don't poll - * - * PA has a pending write request whose callback changes the child nod= es of - * PB: It removes B and adds C instead. The subtree of PB is drained, = which - * will indirectly drain the write request, too. - * - * by_parent_cb =3D=3D false: Test that bdrv_drain_invoke() doesn't poll + * Test that bdrv_drain_invoke() doesn't poll * * PA's BdrvChildClass has a .drained_begin callback that schedules a = BH * that does the same graph change. If bdrv_drain_invoke() calls it, t= he * state is messed up, but if it is only polled in the single * BDRV_POLL_WHILE() at the end of the drain, this should work fine. */ -static void test_detach_indirect(bool by_parent_cb) +static void test_detach_indirect(void) { BlockBackend *blk; BlockDriverState *parent_a, *parent_b, *a, *b, *c; BdrvChild *child_a, *child_b; BlockAIOCB *acb; + BDRVTestState *s; =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 - if (!by_parent_cb) { - detach_by_driver_cb_class =3D child_of_bds; - detach_by_driver_cb_class.drained_begin =3D - detach_by_driver_cb_drained_begin; - } + detach_by_driver_cb_class =3D child_of_bds; + detach_by_driver_cb_class.drained_begin =3D detach_by_driver_cb_draine= d_begin; =20 /* Create all involved nodes */ parent_a =3D bdrv_new_open_driver(&bdrv_test, "parent-a", BDRV_O_RDWR, @@ -1403,10 +1389,8 @@ static void test_detach_indirect(bool by_parent_cb) =20 /* If we want to get bdrv_drain_invoke() to call aio_poll(), the driver * callback must not return immediately. */ - if (!by_parent_cb) { - BDRVTestState *s =3D parent_a->opaque; - s->sleep_in_drain_begin =3D true; - } + s =3D parent_a->opaque; + s->sleep_in_drain_begin =3D true; =20 /* Set child relationships */ bdrv_ref(b); @@ -1418,7 +1402,7 @@ static void test_detach_indirect(bool by_parent_cb) =20 bdrv_ref(a); bdrv_attach_child(parent_a, a, "PA-A", - by_parent_cb ? &child_of_bds : &detach_by_driver_cb_= class, + &detach_by_driver_cb_class, BDRV_CHILD_DATA, &error_abort); =20 g_assert_cmpint(parent_a->refcnt, =3D=3D, 1); @@ -1436,7 +1420,6 @@ static void test_detach_indirect(bool by_parent_cb) .parent_b =3D parent_b, .child_b =3D child_b, .c =3D c, - .by_parent_cb =3D by_parent_cb, }; acb =3D blk_aio_preadv(blk, 0, &qiov, 0, detach_by_parent_aio_cb, NULL= ); g_assert(acb !=3D NULL); @@ -1475,14 +1458,9 @@ static void test_detach_indirect(bool by_parent_cb) bdrv_unref(c); } =20 -static void test_detach_by_parent_cb(void) -{ - test_detach_indirect(true); -} - static void test_detach_by_driver_cb(void) { - test_detach_indirect(false); + test_detach_indirect(); } =20 static void test_append_to_drained(void) @@ -2236,7 +2214,6 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/detach/drain_all", test_detach_by_drain_a= ll); g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain); g_test_add_func("/bdrv-drain/detach/drain_subtree", test_detach_by_dra= in_subtree); - g_test_add_func("/bdrv-drain/detach/parent_cb", test_detach_by_parent_= cb); g_test_add_func("/bdrv-drain/detach/driver_cb", test_detach_by_driver_= cb); =20 g_test_add_func("/bdrv-drain/attach/drain", test_append_to_drained); --=20 2.31.1 From nobody Sun May 19 13:07:57 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1670242297; cv=none; d=zohomail.com; s=zohoarc; b=a9JsWemF3DIynwIKwKYH8AQ6ueQ+uQN/YPgM9/YT2YWkStVFryDEMp8bHHNr87G/hiTKQSZOL+bYqblGUQssCuV7BvLS7yLhEUGbhNgWU4exK+zdFYEx6ZKaLxQOBpt/f+uikry/Sce2sG3l/WW7bA9y5uZJYaZM2QC2IoPasbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670242297; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iELcNiEK7+OmeBopiSZf9E1lU1qAtgc2jgfHZHuzaIo=; b=LWIdyGS2TT/YbkDSoRZng2sIDM2ldwxYu5tAKQk0lgBf2eW/5ERs8kCCwdf48HJgnhYwDdFGHDgMR2h6l20lFalZ00jdlwJ9LOeh4rYBV2jS5FZy3f0j6V/0k9ikDv/5XsZA3SE7fQFL/YLru5B4fDC7J8We1QBaZXoczgNbZ2w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1670242297901257.4313690270027; Mon, 5 Dec 2022 04:11:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2AIz-0008JO-Vk; Mon, 05 Dec 2022 07:10:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2AIw-0008IY-U7 for qemu-devel@nongnu.org; Mon, 05 Dec 2022 07:10:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2AIt-0006YA-MY for qemu-devel@nongnu.org; Mon, 05 Dec 2022 07:10:38 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-463-ImKnhWRSPCScY_MQa1v29w-1; Mon, 05 Dec 2022 07:10:33 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E0F621C07825; Mon, 5 Dec 2022 12:10:32 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id A840F63F45; Mon, 5 Dec 2022 12:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670242234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iELcNiEK7+OmeBopiSZf9E1lU1qAtgc2jgfHZHuzaIo=; b=B5SiAEYkuMO6cYiuyDx2PDpKO/0flTPBZ4ucaLPUjVpZee/EVE8GBMiSxaSNrTyxmpWz5o nl0JOtt4pPD2muGDh1r51nGdks6JDgw/lMnL8ONeF2Lo61fq+fIXmJOTarRhp92jOr3F5r fyP4XsvP0NXJuZWIQCXKxUtX09XqCBY= X-MC-Unique: ImKnhWRSPCScY_MQa1v29w-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , Hanna Reitz , Stefan Hajnoczi , Emanuele Giuseppe Esposito Subject: [PATCH 2/2] tests/unit/test-bdrv-drain.c: graph setup functions can't run in coroutines Date: Mon, 5 Dec 2022 07:10:29 -0500 Message-Id: <20221205121029.1089209-3-eesposit@redhat.com> In-Reply-To: <20221205121029.1089209-1-eesposit@redhat.com> References: <20221205121029.1089209-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1670242298412100009 Content-Type: text/plain; charset="utf-8" Graph initialization functions like blk_new(), bdrv_new() and so on should not run in a coroutine. In fact, they might invoke a drain (for example blk_insert_bs eventually calls bdrv_replace_child_noperm) that in turn can invoke callbacks like bdrv_do_drained_begin_quiesce(), that asserts exactly that we are not in a coroutine. Move the initialization phase of test_drv_cb and test_quiesce_common outside the coroutine logic. Signed-off-by: Emanuele Giuseppe Esposito --- tests/unit/test-bdrv-drain.c | 118 ++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 45 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 4ce159250e..8b379727c9 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -116,7 +116,8 @@ static void aio_ret_cb(void *opaque, int ret) } =20 typedef struct CallInCoroutineData { - void (*entry)(void); + void (*entry)(void *); + void *arg; bool done; } CallInCoroutineData; =20 @@ -124,15 +125,16 @@ static coroutine_fn void call_in_coroutine_entry(void= *opaque) { CallInCoroutineData *data =3D opaque; =20 - data->entry(); + data->entry(data->arg); data->done =3D true; } =20 -static void call_in_coroutine(void (*entry)(void)) +static void call_in_coroutine(void (*entry)(void *), void *arg) { Coroutine *co; CallInCoroutineData data =3D { .entry =3D entry, + .arg =3D arg, .done =3D false, }; =20 @@ -192,26 +194,28 @@ static void do_drain_end_unlocked(enum drain_type dra= in_type, BlockDriverState * } } =20 -static void test_drv_cb_common(enum drain_type drain_type, bool recursive) -{ +typedef struct TestDriverCBData { + enum drain_type drain_type; + bool recursive; BlockBackend *blk; BlockDriverState *bs, *backing; - BDRVTestState *s, *backing_s; +} TestDriverCBData; + +static void test_drv_cb_common(void *arg) +{ + TestDriverCBData *data =3D arg; + BlockBackend *blk =3D data->blk; + BlockDriverState *bs =3D data->bs; + BlockDriverState *backing =3D data->backing; + enum drain_type drain_type =3D data->drain_type; + bool recursive =3D data->recursive; + BDRVTestState *s =3D bs->opaque; + BDRVTestState *backing_s =3D backing->opaque; BlockAIOCB *acb; int aio_ret; =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 - blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, - &error_abort); - s =3D bs->opaque; - blk_insert_bs(blk, bs, &error_abort); - - backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); - backing_s =3D 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, =3D=3D, 0); g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); @@ -245,54 +249,77 @@ static void test_drv_cb_common(enum drain_type drain_= type, bool recursive) =20 g_assert_cmpint(s->drain_count, =3D=3D, 0); g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); +} =20 - bdrv_unref(backing); - bdrv_unref(bs); - blk_unref(blk); +static void test_common_cb(enum drain_type drain_type, bool in_coroutine, + void (*cb)(void *)) +{ + TestDriverCBData data; + + data.drain_type =3D drain_type; + data.recursive =3D (drain_type !=3D BDRV_DRAIN); + + data.blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_AL= L); + data.bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, + &error_abort); + blk_insert_bs(data.blk, data.bs, &error_abort); + + data.backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error= _abort); + bdrv_set_backing_hd(data.bs, data.backing, &error_abort); + + if (in_coroutine) { + call_in_coroutine(cb, &data); + } else { + cb(&data); + } + + bdrv_unref(data.backing); + bdrv_unref(data.bs); + blk_unref(data.blk); +} + +static void test_drv_cb(enum drain_type drain_type, bool in_coroutine) +{ + test_common_cb(drain_type, in_coroutine, test_drv_cb_common); } =20 static void test_drv_cb_drain_all(void) { - test_drv_cb_common(BDRV_DRAIN_ALL, true); + test_drv_cb(BDRV_DRAIN_ALL, false); } =20 static void test_drv_cb_drain(void) { - test_drv_cb_common(BDRV_DRAIN, false); + test_drv_cb(BDRV_DRAIN, false); } =20 static void test_drv_cb_drain_subtree(void) { - test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); + test_drv_cb(BDRV_SUBTREE_DRAIN, false); } =20 static void test_drv_cb_co_drain_all(void) { - call_in_coroutine(test_drv_cb_drain_all); + test_drv_cb(BDRV_DRAIN_ALL, true); } =20 static void test_drv_cb_co_drain(void) { - call_in_coroutine(test_drv_cb_drain); + test_drv_cb(BDRV_DRAIN, true); } =20 static void test_drv_cb_co_drain_subtree(void) { - call_in_coroutine(test_drv_cb_drain_subtree); + test_drv_cb(BDRV_SUBTREE_DRAIN, true); } =20 -static void test_quiesce_common(enum drain_type drain_type, bool recursive) +static void test_quiesce_common(void *arg) { - BlockBackend *blk; - BlockDriverState *bs, *backing; - - blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, - &error_abort); - blk_insert_bs(blk, bs, &error_abort); - - backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); - bdrv_set_backing_hd(bs, backing, &error_abort); + TestDriverCBData *data =3D arg; + BlockDriverState *bs =3D data->bs; + BlockDriverState *backing =3D data->backing; + enum drain_type drain_type =3D data->drain_type; + bool recursive =3D data->recursive; =20 g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); @@ -306,40 +333,41 @@ static void test_quiesce_common(enum drain_type drain= _type, bool recursive) =20 g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); +} =20 - bdrv_unref(backing); - bdrv_unref(bs); - blk_unref(blk); +static void test_quiesce(enum drain_type drain_type, bool in_coroutine) +{ + test_common_cb(drain_type, in_coroutine, test_quiesce_common); } =20 static void test_quiesce_drain_all(void) { - test_quiesce_common(BDRV_DRAIN_ALL, true); + test_quiesce(BDRV_DRAIN_ALL, false); } =20 static void test_quiesce_drain(void) { - test_quiesce_common(BDRV_DRAIN, false); + test_quiesce(BDRV_DRAIN, false); } =20 static void test_quiesce_drain_subtree(void) { - test_quiesce_common(BDRV_SUBTREE_DRAIN, true); + test_quiesce(BDRV_SUBTREE_DRAIN, false); } =20 static void test_quiesce_co_drain_all(void) { - call_in_coroutine(test_quiesce_drain_all); + test_quiesce(BDRV_DRAIN_ALL, true); } =20 static void test_quiesce_co_drain(void) { - call_in_coroutine(test_quiesce_drain); + test_quiesce(BDRV_DRAIN, true); } =20 static void test_quiesce_co_drain_subtree(void) { - call_in_coroutine(test_quiesce_drain_subtree); + test_quiesce(BDRV_SUBTREE_DRAIN, true); } =20 static void test_nested(void) --=20 2.31.1