From nobody Sat May 18 05:53:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1639392393318212.0186338406112; Mon, 13 Dec 2021 02:46:33 -0800 (PST) Received: from localhost ([::1]:55850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwiqm-0003AD-BK for importer@patchew.org; Mon, 13 Dec 2021 05:46:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwilk-0002xI-9s for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwili-0007oP-8C for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-473-QG7ZLh98OgCUhoRooeafhg-1; Mon, 13 Dec 2021 05:41:11 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C027102CB73; Mon, 13 Dec 2021 10:41:10 +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 B5FE66B8EA; Mon, 13 Dec 2021 10:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639392077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cVd1vHCe8dL2//q6DTsC0467/dR+xKXi+J9NI88sMKA=; b=gCjHbS6x5qX2kNK8n72tvQCrYUC+EapzXT8/jl5KexnVauhzV0yAtGIH9t/sWJhSVXd4qj CisnodSF8B372e7C4zU/neaoFKLptqo/8UaKVisu9enD85LXn+TJL0SpLXNAkDVGeMKWLm fBxvVJN7BKAd+3M64MafuLmI7t9Et40= X-MC-Unique: QG7ZLh98OgCUhoRooeafhg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH 1/6] tests/unit/test-bdrv-drain.c: graph setup functions can't run in coroutines Date: Mon, 13 Dec 2021 05:40:09 -0500 Message-Id: <20211213104014.69858-2-eesposit@redhat.com> In-Reply-To: <20211213104014.69858-1-eesposit@redhat.com> References: <20211213104014.69858-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.713, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Cc: Kevin Wolf , Fam Zheng , Emanuele Giuseppe Esposito , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1639392395023100001 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 83485a33aa..a62e6451a1 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 From nobody Sat May 18 05:53:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1639392228608763.8707256092417; Mon, 13 Dec 2021 02:43:48 -0800 (PST) Received: from localhost ([::1]:46850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwio7-0005dr-6b for importer@patchew.org; Mon, 13 Dec 2021 05:43:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwilf-0002tg-K1 for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23577) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwile-0007mO-8x for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:15 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-604-j7PmGAbFOZiy6M6yNeC4jA-1; Mon, 13 Dec 2021 05:41:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D24D801B25; Mon, 13 Dec 2021 10:41:11 +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 B5D714D73A; Mon, 13 Dec 2021 10:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639392073; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xmrqLMODE9CfmevOXCMF7tf9vn7k1pncAj2DKa6mMNc=; b=cC/3KesZNdO+P9jOVRVbYktooACmnwmQ1Mv2I12Dlq9sb+EyKsPDjLEIWzWLpAK+NHBf17 dR8i7HH8S1OWHgXRr3liNGYfZb6FUDcoSRbwSp4ZFmBHpo1dI2s1wJYaFrxtB2IsHlzD36 bPgndlNg+mwxi1QDoo+Ad0HYZBAX6S4= X-MC-Unique: j7PmGAbFOZiy6M6yNeC4jA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH 2/6] introduce BDRV_POLL_WHILE_UNLOCKED Date: Mon, 13 Dec 2021 05:40:10 -0500 Message-Id: <20211213104014.69858-3-eesposit@redhat.com> In-Reply-To: <20211213104014.69858-1-eesposit@redhat.com> References: <20211213104014.69858-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.713, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: , Cc: Kevin Wolf , Fam Zheng , Emanuele Giuseppe Esposito , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1639392229862100001 Content-Type: text/plain; charset="utf-8" Same as BDRV_POLL_WHILE, but uses AIO_WAIT_WHILE_UNLOCKED. Signed-off-by: Emanuele Giuseppe Esposito --- include/block/block-global-state.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 7a6b065101..818164a06b 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -158,6 +158,11 @@ void bdrv_drain_all(void); AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \ cond); }) =20 +#define BDRV_POLL_WHILE_UNLOCKED(bs, cond) ({ \ + BlockDriverState *bs_ =3D (bs); \ + AIO_WAIT_WHILE_UNLOCKED(bdrv_get_aio_context(bs_), \ + cond); }) + int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, --=20 2.31.1 From nobody Sat May 18 05:53:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1639392229769610.3087960882614; Mon, 13 Dec 2021 02:43:49 -0800 (PST) Received: from localhost ([::1]:47018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwio8-0005k7-JK for importer@patchew.org; Mon, 13 Dec 2021 05:43:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39070) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwilk-0002xR-9P for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwilg-0007mz-Oo for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:19 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-fDmOK21OM7qSUNaQpuJS6g-1; Mon, 13 Dec 2021 05:41:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E1D8102CB78; Mon, 13 Dec 2021 10:41:12 +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 772A24D73A; Mon, 13 Dec 2021 10:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639392076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3LseeJuvvZcvozmKRXLU8wjWGXFYabLAWMQveHBl/5U=; b=SZF20xG/0aM5zRUQ0Z/N3rw85WOXXWm8BKR7yQwndnc7wA2+YayGbVZTYJ5qoUE4O6gfVA KzC0qqw+v4USw+8DJNviomeAR9ALEEby6VUNzcBUAe/DtkcbZFxeiWUF7hIzeWVTN3vZfq Cc7woGPxDghpin8u0+5otGyBwhV+d9s= X-MC-Unique: fDmOK21OM7qSUNaQpuJS6g-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH 3/6] block/io.c: introduce bdrv_subtree_drained_{begin/end}_unlocked Date: Mon, 13 Dec 2021 05:40:11 -0500 Message-Id: <20211213104014.69858-4-eesposit@redhat.com> In-Reply-To: <20211213104014.69858-1-eesposit@redhat.com> References: <20211213104014.69858-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.713, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Cc: Kevin Wolf , Fam Zheng , Emanuele Giuseppe Esposito , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1639392231794100003 Content-Type: text/plain; charset="utf-8" Same as the locked version, but use BDRV_POLL_UNLOCKED Signed-off-by: Emanuele Giuseppe Esposito --- block/io.c | 35 ++++++++++++++++++++++++++--------- include/block/block-io.h | 2 ++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/block/io.c b/block/io.c index 3be08cad29..a031691860 100644 --- a/block/io.c +++ b/block/io.c @@ -334,7 +334,7 @@ static bool bdrv_drain_poll_top_level(BlockDriverState = *bs, bool recursive, =20 static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, BdrvChild *parent, bool ignore_bds_paren= ts, - bool poll); + bool poll, bool unlock); static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, BdrvChild *parent, bool ignore_bds_parents, int *drained_end_counter); @@ -352,7 +352,7 @@ static void bdrv_co_drain_bh_cb(void *opaque) if (data->begin) { assert(!data->drained_end_counter); bdrv_do_drained_begin(bs, data->recursive, data->parent, - data->ignore_bds_parents, data->poll); + data->ignore_bds_parents, data->poll, fa= lse); } else { assert(!data->poll); bdrv_do_drained_end(bs, data->recursive, data->parent, @@ -441,7 +441,7 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, =20 static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, BdrvChild *parent, bool ignore_bds_paren= ts, - bool poll) + bool poll, bool unlock) { BdrvChild *child, *next; =20 @@ -458,7 +458,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, bs->recursive_quiesce_counter++; QLIST_FOREACH_SAFE(child, &bs->children, next, next) { bdrv_do_drained_begin(child->bs, true, child, ignore_bds_paren= ts, - false); + false, false); } } =20 @@ -473,18 +473,28 @@ static void bdrv_do_drained_begin(BlockDriverState *b= s, bool recursive, */ if (poll) { assert(!ignore_bds_parents); - BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs, recursive, paren= t)); + if (unlock) { + BDRV_POLL_WHILE_UNLOCKED(bs, + bdrv_drain_poll_top_level(bs, recursi= ve, parent)); + } else { + BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs, recursive, p= arent)); + } } } =20 void bdrv_drained_begin(BlockDriverState *bs) { - bdrv_do_drained_begin(bs, false, NULL, false, true); + bdrv_do_drained_begin(bs, false, NULL, false, true, false); } =20 void bdrv_subtree_drained_begin(BlockDriverState *bs) { - bdrv_do_drained_begin(bs, true, NULL, false, true); + bdrv_do_drained_begin(bs, true, NULL, false, true, false); +} + +void bdrv_subtree_drained_begin_unlocked(BlockDriverState *bs) +{ + bdrv_do_drained_begin(bs, true, NULL, false, true, true); } =20 /** @@ -556,12 +566,19 @@ void bdrv_subtree_drained_end(BlockDriverState *bs) BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0); } =20 +void bdrv_subtree_drained_end_unlocked(BlockDriverState *bs) +{ + int drained_end_counter =3D 0; + bdrv_do_drained_end(bs, true, NULL, false, &drained_end_counter); + BDRV_POLL_WHILE_UNLOCKED(bs, qatomic_read(&drained_end_counter) > 0); +} + void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt) { int i; =20 for (i =3D 0; i < new_parent->recursive_quiesce_counter; i++) { - bdrv_do_drained_begin(child->bs, true, child, false, true); + bdrv_do_drained_begin(child->bs, true, child, false, true, false); } } =20 @@ -671,7 +688,7 @@ void bdrv_drain_all_begin(void) AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 aio_context_acquire(aio_context); - bdrv_do_drained_begin(bs, false, NULL, true, false); + bdrv_do_drained_begin(bs, false, NULL, true, false, false); aio_context_release(aio_context); } =20 diff --git a/include/block/block-io.h b/include/block/block-io.h index e2789dd344..457e77bfce 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -249,6 +249,7 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, * exclusive access to all child nodes as well. */ void bdrv_subtree_drained_begin(BlockDriverState *bs); +void bdrv_subtree_drained_begin_unlocked(BlockDriverState *bs); =20 /** * bdrv_drained_end: @@ -281,6 +282,7 @@ void bdrv_drained_end_no_poll(BlockDriverState *bs, int= *drained_end_counter); * End a quiescent section started by bdrv_subtree_drained_begin(). */ void bdrv_subtree_drained_end(BlockDriverState *bs); +void bdrv_subtree_drained_end_unlocked(BlockDriverState *bs); =20 bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *nam= e, uint32_t granularity, Error **errp); --=20 2.31.1 From nobody Sat May 18 05:53:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1639392336722885.6918343006103; Mon, 13 Dec 2021 02:45:36 -0800 (PST) Received: from localhost ([::1]:54658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwipr-0002N4-DO for importer@patchew.org; Mon, 13 Dec 2021 05:45:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwili-0002wN-Ei for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:45149) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwilf-0007mX-QJ for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-201-D2Ys16cvNkqqtxFnBa8kDQ-1; Mon, 13 Dec 2021 05:41:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D427B102CB73; Mon, 13 Dec 2021 10:41:12 +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 38B816B8EA; Mon, 13 Dec 2021 10:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639392075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z7F3Bbxh+io7h96uJ2icq61kxjI8KmHIokVFozYrTHk=; b=S8WdxKuyI4nBL1s36ANK7+r9TWRd+7jE21vnouNXZIZ1ZEOoNz9YwToFZkBQ/9MXdRimhB DCoX3ztqeFuf1tqpn8ZefxWOdbHxAvKcOQz6mz7UgCK70u1UxCM0MMHXqM9AJ4q1d+N9OV U2xStIuYaHvKe7suc3nN9tSqJPAsqJU= X-MC-Unique: D2Ys16cvNkqqtxFnBa8kDQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH 4/6] block.c: add subtree_drains where needed Date: Mon, 13 Dec 2021 05:40:12 -0500 Message-Id: <20211213104014.69858-5-eesposit@redhat.com> In-Reply-To: <20211213104014.69858-1-eesposit@redhat.com> References: <20211213104014.69858-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.713, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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: , Cc: Kevin Wolf , Fam Zheng , Emanuele Giuseppe Esposito , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1639392337647100001 Content-Type: text/plain; charset="utf-8" Protect bdrv_replace_child_noperm, as it modifies the graph by adding/removing elements to .children and .parents list of a bs. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/block.c b/block.c index 3c3c90704c..1aa9e51a98 100644 --- a/block.c +++ b/block.c @@ -2369,7 +2369,11 @@ static void bdrv_replace_child_abort(void *opaque) * So whether new_bs was NULL or not, we cannot pass s->childp here; a= nd in * any case, there is no reason to pass it anyway. */ + bdrv_subtree_drained_begin_unlocked(s->child->bs); + bdrv_subtree_drained_begin_unlocked(s->old_bs); bdrv_replace_child_noperm(&s->child, s->old_bs, true); + bdrv_subtree_drained_end_unlocked(s->old_bs); + bdrv_subtree_drained_end_unlocked(s->child->bs); /* * The child was pre-existing, so s->old_bs must be non-NULL, and * s->child thus must not have been freed @@ -2427,13 +2431,20 @@ static void bdrv_replace_child_tran(BdrvChild **chi= ldp, =20 if (new_bs) { bdrv_ref(new_bs); + bdrv_subtree_drained_begin_unlocked(new_bs); } /* * Pass free_empty_child=3Dfalse, we will free the child (if * necessary) in bdrv_replace_child_commit() (if our * @free_empty_child parameter was true). */ + bdrv_subtree_drained_begin_unlocked(s->old_bs); bdrv_replace_child_noperm(childp, new_bs, false); + bdrv_subtree_drained_end_unlocked(s->old_bs); + + if (new_bs) { + bdrv_subtree_drained_end_unlocked(new_bs); + } /* old_bs reference is transparently moved from *childp to @s */ } =20 @@ -2951,7 +2962,9 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) * need to keep it as an empty shell (after this function, it will * not be attached to any parent, and it will not have a .bs). */ + bdrv_subtree_drained_begin_unlocked(bs); bdrv_replace_child_noperm(s->child, NULL, false); + bdrv_subtree_drained_end_unlocked(bs); =20 if (bdrv_get_aio_context(bs) !=3D s->old_child_ctx) { bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); @@ -3051,7 +3064,10 @@ static int bdrv_attach_child_common(BlockDriverState= *child_bs, } =20 bdrv_ref(child_bs); + + bdrv_subtree_drained_begin_unlocked(child_bs); bdrv_replace_child_noperm(&new_child, child_bs, true); + bdrv_subtree_drained_end_unlocked(child_bs); /* child_bs was non-NULL, so new_child must not have been freed */ assert(new_child !=3D NULL); =20 @@ -3114,8 +3130,16 @@ static void bdrv_detach_child(BdrvChild **childp) BlockDriverState *old_bs =3D (*childp)->bs; =20 assert(qemu_in_main_thread()); + if (old_bs) { + bdrv_subtree_drained_begin(old_bs); + } + bdrv_replace_child_noperm(childp, NULL, true); =20 + if (old_bs) { + bdrv_subtree_drained_end(old_bs); + } + if (old_bs) { /* * Update permissions for old node. We're just taking a parent awa= y, so --=20 2.31.1 From nobody Sat May 18 05:53:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1639392271529320.1336578823971; Mon, 13 Dec 2021 02:44:31 -0800 (PST) Received: from localhost ([::1]:50818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwioo-0008G2-Im for importer@patchew.org; Mon, 13 Dec 2021 05:44:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwill-0002ya-Fj for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52245) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwili-0007oU-CV for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:21 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-207-ZW9TizJzMj2JLhxQZE21lQ-1; Mon, 13 Dec 2021 05:41:14 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 953DC640A1; Mon, 13 Dec 2021 10:41:13 +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 EE8E66B8EA; Mon, 13 Dec 2021 10:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639392077; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jFvf8EJSgXHYZIgb45dR2RFSuImjrGJV7vsU0A2n7Qs=; b=LKqk/KR7jlzP+Hy4rnq6eht8h2WOVbS1bRNnu5kkVDaMCaiKUqms9fCJM8d/7JhxPUAEyx VgPuI3xJK+bWsVsFeoJ3hSTGI/AsGy3SiwYfD3yiDniXMx8VWmBKhU2i6ZsTyl0TnOn4ta Hi/ar0ca7vC6KEES1OuFVaEbcsKmYSc= X-MC-Unique: ZW9TizJzMj2JLhxQZE21lQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH 5/6] test-bdrv-drain.c: adapt test to the new subtree drains Date: Mon, 13 Dec 2021 05:40:13 -0500 Message-Id: <20211213104014.69858-6-eesposit@redhat.com> In-Reply-To: <20211213104014.69858-1-eesposit@redhat.com> References: <20211213104014.69858-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.713, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=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: , Cc: Kevin Wolf , Fam Zheng , Emanuele Giuseppe Esposito , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1639392274208100001 Content-Type: text/plain; charset="utf-8" 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 --- tests/unit/test-bdrv-drain.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index a62e6451a1..9414fc68b7 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -939,10 +939,10 @@ static void test_blockjob_common_drain_node(enum drai= n_type drain_type, blk_insert_bs(blk_target, target, &error_abort); blk_set_allow_aio_context_change(blk_target, true); =20 - aio_context_acquire(ctx); tjob =3D block_job_create("job0", &test_job_driver, NULL, src, 0, BLK_PERM_ALL, 0, 0, NULL, NULL, &error_abort); + aio_context_acquire(ctx); job =3D &tjob->common; block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abor= t); =20 @@ -1388,8 +1388,6 @@ static void test_detach_indirect(bool by_parent_cb) =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; } =20 /* Create all involved nodes */ @@ -1447,6 +1445,12 @@ static void test_detach_indirect(bool by_parent_cb) acb =3D blk_aio_preadv(blk, 0, &qiov, 0, detach_by_parent_aio_cb, NULL= ); g_assert(acb !=3D NULL); =20 + if (!by_parent_cb) { + /* set .drained_begin cb to run only in the following drain. */ + detach_by_driver_cb_class.drained_begin =3D + detach_by_driver_cb_drained_begin; + } + /* Drain and check the expected result */ bdrv_subtree_drained_begin(parent_b); =20 @@ -1470,6 +1474,12 @@ static void test_detach_indirect(bool by_parent_cb) =20 bdrv_subtree_drained_end(parent_b); =20 + if (!by_parent_cb) { + /* restore .drained_begin cb, we don't need it anymore. */ + detach_by_driver_cb_class.drained_begin =3D + child_of_bds.drained_begin; + } + bdrv_unref(parent_b); blk_unref(blk); =20 @@ -1483,7 +1493,7 @@ static void test_detach_indirect(bool by_parent_cb) =20 static void test_detach_by_parent_cb(void) { - test_detach_indirect(true); + /* test_detach_indirect(true); */ } =20 static void test_detach_by_driver_cb(void) --=20 2.31.1 From nobody Sat May 18 05:53:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1639392449659768.9885507309306; Mon, 13 Dec 2021 02:47:29 -0800 (PST) Received: from localhost ([::1]:58194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mwirg-0004pi-J9 for importer@patchew.org; Mon, 13 Dec 2021 05:47:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwilm-0002z0-RQ for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:46373) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mwilk-0007pk-0z for qemu-devel@nongnu.org; Mon, 13 Dec 2021 05:41:22 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-121-UGdpIrOQM0qI2X4Rckw9Aw-1; Mon, 13 Dec 2021 05:41:15 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5611B190B2A2; Mon, 13 Dec 2021 10:41:14 +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 AF6F66B8EA; Mon, 13 Dec 2021 10:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639392079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oXFBL3hZSgpoP7JTPaqpp3zMoPErEhu+cQwWOS3SdD8=; b=YcbDaSdQHTnvzj8i4GYQJSfTvwpPAgja1Y3lrxvVD2n6cMIxfZLyKsjfB9HXvYakAwCdFV sKzIz2hyYt0s0JSFTecDDZz80UdSFRT3e0BWISv+o1ROBk6jfRTdEZltIsfYvjbm5k2U5A q+IAtjxKNFfKVnJmTP9U21PsVxJ8Cxw= X-MC-Unique: UGdpIrOQM0qI2X4Rckw9Aw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Subject: [RFC PATCH 6/6] block/io.c: enable assert_bdrv_graph_writable Date: Mon, 13 Dec 2021 05:40:14 -0500 Message-Id: <20211213104014.69858-7-eesposit@redhat.com> In-Reply-To: <20211213104014.69858-1-eesposit@redhat.com> References: <20211213104014.69858-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eesposit@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.713, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: , Cc: Kevin Wolf , Fam Zheng , Emanuele Giuseppe Esposito , qemu-devel@nongnu.org, Hanna Reitz , Stefan Hajnoczi , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1639392450419100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Emanuele Giuseppe Esposito --- block/io.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/io.c b/block/io.c index a031691860..c2f1a494c4 100644 --- a/block/io.c +++ b/block/io.c @@ -759,6 +759,7 @@ void assert_bdrv_graph_writable(BlockDriverState *bs) * Once the necessary drains are added, * assert also for qatomic_read(&bs->quiesce_counter) > 0 */ + assert(qatomic_read(&bs->quiesce_counter) > 0); assert(qemu_in_main_thread()); } =20 --=20 2.31.1