From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766480232253.1879374458399; Wed, 20 Dec 2017 02:41:20 -0800 (PST) Received: from localhost ([::1]:45198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbnx-0000Yf-UG for importer@patchew.org; Wed, 20 Dec 2017 05:40:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbiR-00048f-Ja for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbiQ-0004Hs-Bc for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53416) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbiK-0004AY-Lf; Wed, 20 Dec 2017 05:35:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9EA5C0828A6; Wed, 20 Dec 2017 10:35:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id D5FD418B35; Wed, 20 Dec 2017 10:34:56 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:33:54 +0100 Message-Id: <20171220103412.13048-2-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 20 Dec 2017 10:35:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 01/19] block: Remove unused bdrv_requests_pending X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fam Zheng Signed-off-by: Fam Zheng Signed-off-by: Kevin Wolf --- include/block/block_int.h | 1 - block/io.c | 18 ------------------ 2 files changed, 19 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index a5482775ec..e107163594 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1045,7 +1045,6 @@ bool blk_dev_is_tray_open(BlockBackend *blk); bool blk_dev_is_medium_locked(BlockBackend *blk); =20 void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes); -bool bdrv_requests_pending(BlockDriverState *bs); =20 void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *in); diff --git a/block/io.c b/block/io.c index 1e92d2e5b2..cf780c3cb0 100644 --- a/block/io.c +++ b/block/io.c @@ -134,24 +134,6 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs) assert(old >=3D 1); } =20 -/* Check if any requests are in-flight (including throttled requests) */ -bool bdrv_requests_pending(BlockDriverState *bs) -{ - BdrvChild *child; - - if (atomic_read(&bs->in_flight)) { - return true; - } - - QLIST_FOREACH(child, &bs->children, next) { - if (bdrv_requests_pending(child->bs)) { - return true; - } - } - - return false; -} - typedef struct { Coroutine *co; BlockDriverState *bs; --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766624988234.18959818437668; Wed, 20 Dec 2017 02:43:44 -0800 (PST) Received: from localhost ([::1]:45219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbqc-0003Bb-PC for importer@patchew.org; Wed, 20 Dec 2017 05:43:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbiZ-0004G8-0S for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbiW-0004RY-46 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46464) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbiT-0004NI-LF; Wed, 20 Dec 2017 05:35:13 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0410691C; Wed, 20 Dec 2017 10:35:12 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 271B818BAE; Wed, 20 Dec 2017 10:35:03 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:33:55 +0100 Message-Id: <20171220103412.13048-3-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 20 Dec 2017 10:35:12 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/19] block: Assert drain_all is only called from main AioContext X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng --- block/io.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/io.c b/block/io.c index cf780c3cb0..b94740b8ff 100644 --- a/block/io.c +++ b/block/io.c @@ -330,6 +330,12 @@ void bdrv_drain_all_begin(void) BdrvNextIterator it; GSList *aio_ctxs =3D NULL, *ctx; =20 + /* BDRV_POLL_WHILE() for a node can only be called from its own I/O th= read + * or the main loop AioContext. We potentially use BDRV_POLL_WHILE() on + * nodes in several different AioContexts, so make sure we're in the m= ain + * context. */ + assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); + block_job_pause_all(); =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766279497676.1566081955418; Wed, 20 Dec 2017 02:37:59 -0800 (PST) Received: from localhost ([::1]:45132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbkq-0005zw-EV for importer@patchew.org; Wed, 20 Dec 2017 05:37:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38943) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbih-0004Nw-Sq for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbie-0004hM-UH for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:4743) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbib-0004ZW-7J; Wed, 20 Dec 2017 05:35:21 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53EBB5DA0F; Wed, 20 Dec 2017 10:35:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DC9318B3A; Wed, 20 Dec 2017 10:35:12 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:33:56 +0100 Message-Id: <20171220103412.13048-4-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 20 Dec 2017 10:35:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 03/19] block: Make bdrv_drain() driver callbacks non-recursive X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_drain_begin() doesn't increase bs->quiesce_counter recursively, which means that the child nodes are not actually drained. To keep this consistent, we also shouldn't call the block driver callbacks. Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng --- block/io.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index b94740b8ff..91a52e2d82 100644 --- a/block/io.c +++ b/block/io.c @@ -158,7 +158,7 @@ static void coroutine_fn bdrv_drain_invoke_entry(void *= opaque) } =20 /* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */ -static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) +static void bdrv_drain_invoke(BlockDriverState *bs, bool begin, bool recur= sive) { BdrvChild *child, *tmp; BdrvCoDrainData data =3D { .bs =3D bs, .done =3D false, .begin =3D beg= in}; @@ -172,8 +172,10 @@ static void bdrv_drain_invoke(BlockDriverState *bs, bo= ol begin) bdrv_coroutine_enter(bs, data.co); BDRV_POLL_WHILE(bs, !data.done); =20 - QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { - bdrv_drain_invoke(child->bs, begin); + if (recursive) { + QLIST_FOREACH_SAFE(child, &bs->children, next, tmp) { + bdrv_drain_invoke(child->bs, begin, true); + } } } =20 @@ -265,7 +267,7 @@ void bdrv_drained_begin(BlockDriverState *bs) bdrv_parent_drained_begin(bs); } =20 - bdrv_drain_invoke(bs, true); + bdrv_drain_invoke(bs, true, false); bdrv_drain_recurse(bs); } =20 @@ -281,7 +283,7 @@ void bdrv_drained_end(BlockDriverState *bs) } =20 /* Re-enable things in child-to-parent order */ - bdrv_drain_invoke(bs, false); + bdrv_drain_invoke(bs, false, false); bdrv_parent_drained_end(bs); aio_enable_external(bdrv_get_aio_context(bs)); } @@ -345,7 +347,7 @@ void bdrv_drain_all_begin(void) aio_context_acquire(aio_context); aio_disable_external(aio_context); bdrv_parent_drained_begin(bs); - bdrv_drain_invoke(bs, true); + bdrv_drain_invoke(bs, true, true); aio_context_release(aio_context); =20 if (!g_slist_find(aio_ctxs, aio_context)) { @@ -388,7 +390,7 @@ void bdrv_drain_all_end(void) =20 /* Re-enable things in child-to-parent order */ aio_context_acquire(aio_context); - bdrv_drain_invoke(bs, false); + bdrv_drain_invoke(bs, false, true); bdrv_parent_drained_end(bs); aio_enable_external(aio_context); aio_context_release(aio_context); --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766336315925.9155845348005; Wed, 20 Dec 2017 02:38:56 -0800 (PST) Received: from localhost ([::1]:45174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbli-0006wW-2R for importer@patchew.org; Wed, 20 Dec 2017 05:38:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbil-0004RS-6I for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbij-0004ob-Sd for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44543) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbig-0004ih-A6; Wed, 20 Dec 2017 05:35:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63024CD246; Wed, 20 Dec 2017 10:35:25 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id A444718B3A; Wed, 20 Dec 2017 10:35:20 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:33:57 +0100 Message-Id: <20171220103412.13048-5-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Dec 2017 10:35:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 04/19] test-bdrv-drain: Test callback for bdrv_drain X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The existing test is for bdrv_drain_all_begin/end() only. Generalise the test case so that it can be run for the other variants as well. At the moment this is only bdrv_drain_begin/end(), but in a while, we'll add another one. Also, add a backing file to the test node to test whether the operations work recursively. Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 69 ++++++++++++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 67541438c1..c05203bba8 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -71,6 +71,8 @@ static BlockDriver bdrv_test =3D { =20 .bdrv_co_drain_begin =3D bdrv_test_co_drain_begin, .bdrv_co_drain_end =3D bdrv_test_co_drain_end, + + .bdrv_child_perm =3D bdrv_format_default_perms, }; =20 static void aio_ret_cb(void *opaque, int ret) @@ -79,11 +81,34 @@ static void aio_ret_cb(void *opaque, int ret) *aio_ret =3D ret; } =20 -static void test_drv_cb_drain_all(void) +enum drain_type { + BDRV_DRAIN_ALL, + BDRV_DRAIN, +}; + +static void do_drain_begin(enum drain_type drain_type, BlockDriverState *b= s) +{ + switch (drain_type) { + case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break; + case BDRV_DRAIN: bdrv_drained_begin(bs); break; + default: g_assert_not_reached(); + } +} + +static void do_drain_end(enum drain_type drain_type, BlockDriverState *bs) +{ + switch (drain_type) { + case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break; + case BDRV_DRAIN: bdrv_drained_end(bs); break; + default: g_assert_not_reached(); + } +} + +static void test_drv_cb_common(enum drain_type drain_type, bool recursive) { BlockBackend *blk; - BlockDriverState *bs; - BDRVTestState *s; + BlockDriverState *bs, *backing; + BDRVTestState *s, *backing_s; BlockAIOCB *acb; int aio_ret; =20 @@ -100,12 +125,23 @@ static void test_drv_cb_drain_all(void) s =3D bs->opaque; blk_insert_bs(blk, bs, &error_abort); =20 + 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); - bdrv_drain_all_begin(); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + + do_drain_begin(drain_type, bs); + g_assert_cmpint(s->drain_count, =3D=3D, 1); - bdrv_drain_all_end(); + g_assert_cmpint(backing_s->drain_count, =3D=3D, !!recursive); + + do_drain_end(drain_type, bs); + g_assert_cmpint(s->drain_count, =3D=3D, 0); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); =20 /* Now do the same while a request is pending */ aio_ret =3D -EINPROGRESS; @@ -114,16 +150,34 @@ static void test_drv_cb_drain_all(void) g_assert_cmpint(aio_ret, =3D=3D, -EINPROGRESS); =20 g_assert_cmpint(s->drain_count, =3D=3D, 0); - bdrv_drain_all_begin(); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + + do_drain_begin(drain_type, bs); + g_assert_cmpint(aio_ret, =3D=3D, 0); g_assert_cmpint(s->drain_count, =3D=3D, 1); - bdrv_drain_all_end(); + g_assert_cmpint(backing_s->drain_count, =3D=3D, !!recursive); + + do_drain_end(drain_type, bs); + 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); } =20 +static void test_drv_cb_drain_all(void) +{ + test_drv_cb_common(BDRV_DRAIN_ALL, true); +} + +static void test_drv_cb_drain(void) +{ + test_drv_cb_common(BDRV_DRAIN, false); +} + int main(int argc, char **argv) { bdrv_init(); @@ -132,6 +186,7 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); =20 g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_a= ll); + g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); =20 return g_test_run(); } --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766488374400.18679405607725; Wed, 20 Dec 2017 02:41:28 -0800 (PST) Received: from localhost ([::1]:45202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRboO-0000w3-69 for importer@patchew.org; Wed, 20 Dec 2017 05:41:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbir-0004XL-Do for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbiq-0004xA-Hh for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47936) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbik-0004pE-Rr; Wed, 20 Dec 2017 05:35:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF48D32DE37; Wed, 20 Dec 2017 10:35:29 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CFAC51C35; Wed, 20 Dec 2017 10:35:25 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:33:58 +0100 Message-Id: <20171220103412.13048-6-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 20 Dec 2017 10:35:30 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/19] test-bdrv-drain: Test bs->quiesce_counter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is currently only working correctly for bdrv_drain(), not for bdrv_drain_all(). Leave a comment for the drain_all case, we'll address it later. Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index c05203bba8..2aa2b9aa43 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -178,6 +178,48 @@ static void test_drv_cb_drain(void) test_drv_cb_common(BDRV_DRAIN, false); } =20 +static void test_quiesce_common(enum drain_type drain_type, bool recursive) +{ + BlockBackend *blk; + BlockDriverState *bs, *backing; + + blk =3D blk_new(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); + + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + + do_drain_begin(drain_type, bs); + + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, !!recursive); + + do_drain_end(drain_type, bs); + + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + + bdrv_unref(backing); + bdrv_unref(bs); + blk_unref(blk); +} + +static void test_quiesce_drain_all(void) +{ + // XXX drain_all doesn't quiesce + //test_quiesce_common(BDRV_DRAIN_ALL, true); +} + +static void test_quiesce_drain(void) +{ + test_quiesce_common(BDRV_DRAIN, false); +} + int main(int argc, char **argv) { bdrv_init(); @@ -188,5 +230,8 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_a= ll); g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); =20 + g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_al= l); + g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); + return g_test_run(); } --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766685290959.1396785774643; Wed, 20 Dec 2017 02:44:45 -0800 (PST) Received: from localhost ([::1]:45225 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbrO-0003sZ-0Q for importer@patchew.org; Wed, 20 Dec 2017 05:44:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbiz-0004fo-R6 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbix-000570-I1 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52548) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbio-0004tb-81; Wed, 20 Dec 2017 05:35:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57D5FB176; Wed, 20 Dec 2017 10:35:33 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1191D6E727; Wed, 20 Dec 2017 10:35:29 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:33:59 +0100 Message-Id: <20171220103412.13048-7-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 20 Dec 2017 10:35:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 06/19] blockjob: Pause job on draining any job BDS X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Block jobs already paused themselves when their main BlockBackend entered a drained section. This is not good enough: We also want to pause a block job and may not submit new requests if, for example, the mirror target node should be drained. This implements .drained_begin/end callbacks in child_job in order to consider all block nodes related to the job, and removes the BlockBackend callbacks which are unnecessary now because the root of the job main BlockBackend is always referenced with a child_job, too. Signed-off-by: Kevin Wolf --- blockjob.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/blockjob.c b/blockjob.c index 6173e4728c..f5cea84e73 100644 --- a/blockjob.c +++ b/blockjob.c @@ -234,26 +234,23 @@ static char *child_job_get_parent_desc(BdrvChild *c) job->id); } =20 -static const BdrvChildRole child_job =3D { - .get_parent_desc =3D child_job_get_parent_desc, - .stay_at_node =3D true, -}; - -static void block_job_drained_begin(void *opaque) +static void child_job_drained_begin(BdrvChild *c) { - BlockJob *job =3D opaque; + BlockJob *job =3D c->opaque; block_job_pause(job); } =20 -static void block_job_drained_end(void *opaque) +static void child_job_drained_end(BdrvChild *c) { - BlockJob *job =3D opaque; + BlockJob *job =3D c->opaque; block_job_resume(job); } =20 -static const BlockDevOps block_job_dev_ops =3D { - .drained_begin =3D block_job_drained_begin, - .drained_end =3D block_job_drained_end, +static const BdrvChildRole child_job =3D { + .get_parent_desc =3D child_job_get_parent_desc, + .drained_begin =3D child_job_drained_begin, + .drained_end =3D child_job_drained_end, + .stay_at_node =3D true, }; =20 void block_job_remove_all_bdrv(BlockJob *job) @@ -715,7 +712,6 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, block_job_add_bdrv(job, "main node", bs, 0, BLK_PERM_ALL, &error_abort= ); bs->job =3D job; =20 - blk_set_dev_ops(blk, &block_job_dev_ops, job); bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); =20 QLIST_INSERT_HEAD(&block_jobs, job, job_list); --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766596971366.0864453427869; Wed, 20 Dec 2017 02:43:16 -0800 (PST) Received: from localhost ([::1]:45217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbpu-0002M4-OJ for importer@patchew.org; Wed, 20 Dec 2017 05:42:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbiz-0004fU-H7 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbiu-00053E-9U for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44421) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbip-0004vl-SI; Wed, 20 Dec 2017 05:35:36 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 160D7D9629; Wed, 20 Dec 2017 10:35:35 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9034518BA9; Wed, 20 Dec 2017 10:35:33 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:00 +0100 Message-Id: <20171220103412.13048-8-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Dec 2017 10:35:35 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 07/19] test-bdrv-drain: Test drain vs. block jobs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Block jobs must be paused if any of the involved nodes are drained. Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 121 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 121 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 2aa2b9aa43..019fe9074d 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -24,6 +24,7 @@ =20 #include "qemu/osdep.h" #include "block/block.h" +#include "block/blockjob_int.h" #include "sysemu/block-backend.h" #include "qapi/error.h" =20 @@ -220,6 +221,123 @@ static void test_quiesce_drain(void) test_quiesce_common(BDRV_DRAIN, false); } =20 + +typedef struct TestBlockJob { + BlockJob common; + bool should_complete; +} TestBlockJob; + +static void test_job_completed(BlockJob *job, void *opaque) +{ + block_job_completed(job, 0); +} + +static void coroutine_fn test_job_start(void *opaque) +{ + TestBlockJob *s =3D opaque; + + while (!s->should_complete) { + block_job_sleep_ns(&s->common, 100000); + } + + block_job_defer_to_main_loop(&s->common, test_job_completed, NULL); +} + +static void test_job_complete(BlockJob *job, Error **errp) +{ + TestBlockJob *s =3D container_of(job, TestBlockJob, common); + s->should_complete =3D true; +} + +BlockJobDriver test_job_driver =3D { + .instance_size =3D sizeof(TestBlockJob), + .start =3D test_job_start, + .complete =3D test_job_complete, +}; + +static void test_blockjob_common(enum drain_type drain_type) +{ + BlockBackend *blk_src, *blk_target; + BlockDriverState *src, *target; + BlockJob *job; + int ret; + + src =3D bdrv_new_open_driver(&bdrv_test, "source", BDRV_O_RDWR, + &error_abort); + blk_src =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + blk_insert_bs(blk_src, src, &error_abort); + + target =3D bdrv_new_open_driver(&bdrv_test, "target", BDRV_O_RDWR, + &error_abort); + blk_target =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + blk_insert_bs(blk_target, target, &error_abort); + + job =3D block_job_create("job0", &test_job_driver, src, 0, BLK_PERM_AL= L, 0, + 0, NULL, NULL, &error_abort); + block_job_add_bdrv(job, "target", target, 0, BLK_PERM_ALL, &error_abor= t); + block_job_start(job); + + g_assert_cmpint(job->pause_count, =3D=3D, 0); + g_assert_false(job->paused); + g_assert_false(job->busy); /* We're in block_job_sleep_ns() */ + + do_drain_begin(drain_type, src); + + if (drain_type =3D=3D BDRV_DRAIN_ALL) { + /* bdrv_drain_all() drains both src and target, and involves an + * additional block_job_pause_all() */ + g_assert_cmpint(job->pause_count, =3D=3D, 3); + } else { + g_assert_cmpint(job->pause_count, =3D=3D, 1); + } + /* XXX We don't wait until the job is actually paused. Is this okay? */ + /* g_assert_true(job->paused); */ + g_assert_false(job->busy); /* The job is paused */ + + do_drain_end(drain_type, src); + + g_assert_cmpint(job->pause_count, =3D=3D, 0); + g_assert_false(job->paused); + g_assert_false(job->busy); /* We're in block_job_sleep_ns() */ + + do_drain_begin(drain_type, target); + + if (drain_type =3D=3D BDRV_DRAIN_ALL) { + /* bdrv_drain_all() drains both src and target, and involves an + * additional block_job_pause_all() */ + g_assert_cmpint(job->pause_count, =3D=3D, 3); + } else { + g_assert_cmpint(job->pause_count, =3D=3D, 1); + } + /* XXX We don't wait until the job is actually paused. Is this okay? */ + /* g_assert_true(job->paused); */ + g_assert_false(job->busy); /* The job is paused */ + + do_drain_end(drain_type, target); + + g_assert_cmpint(job->pause_count, =3D=3D, 0); + g_assert_false(job->paused); + g_assert_false(job->busy); /* We're in block_job_sleep_ns() */ + + ret =3D block_job_complete_sync(job, &error_abort); + g_assert_cmpint(ret, =3D=3D, 0); + + blk_unref(blk_src); + blk_unref(blk_target); + bdrv_unref(src); + bdrv_unref(target); +} + +static void test_blockjob_drain_all(void) +{ + test_blockjob_common(BDRV_DRAIN_ALL); +} + +static void test_blockjob_drain(void) +{ + test_blockjob_common(BDRV_DRAIN); +} + int main(int argc, char **argv) { bdrv_init(); @@ -233,5 +351,8 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_al= l); g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); =20 + g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_= all); + g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); + return g_test_run(); } --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766394878386.19245879348034; Wed, 20 Dec 2017 02:39:54 -0800 (PST) Received: from localhost ([::1]:45189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbmn-0007tr-RK for importer@patchew.org; Wed, 20 Dec 2017 05:39:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbiw-0004cz-RK for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbiv-00054I-8a for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48330) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbir-0004xb-O0; Wed, 20 Dec 2017 05:35:37 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D0A4433F7C7; Wed, 20 Dec 2017 10:35:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 626D350337; Wed, 20 Dec 2017 10:35:35 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:01 +0100 Message-Id: <20171220103412.13048-9-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 20 Dec 2017 10:35:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 08/19] block: Don't block_job_pause_all() in bdrv_drain_all() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Block jobs are already paused using the BdrvChildRole drain callbacks, so we don't need an additionall block_job_pause_all() call. Signed-off-by: Kevin Wolf --- block/io.c | 4 ---- tests/test-bdrv-drain.c | 10 ++++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/block/io.c b/block/io.c index 91a52e2d82..74d2e5278e 100644 --- a/block/io.c +++ b/block/io.c @@ -338,8 +338,6 @@ void bdrv_drain_all_begin(void) * context. */ assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); =20 - block_job_pause_all(); - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 @@ -395,8 +393,6 @@ void bdrv_drain_all_end(void) aio_enable_external(aio_context); aio_context_release(aio_context); } - - block_job_resume_all(); } =20 void bdrv_drain_all(void) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 019fe9074d..4571137928 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -284,9 +284,8 @@ static void test_blockjob_common(enum drain_type drain_= type) do_drain_begin(drain_type, src); =20 if (drain_type =3D=3D BDRV_DRAIN_ALL) { - /* bdrv_drain_all() drains both src and target, and involves an - * additional block_job_pause_all() */ - g_assert_cmpint(job->pause_count, =3D=3D, 3); + /* bdrv_drain_all() drains both src and target */ + g_assert_cmpint(job->pause_count, =3D=3D, 2); } else { g_assert_cmpint(job->pause_count, =3D=3D, 1); } @@ -303,9 +302,8 @@ static void test_blockjob_common(enum drain_type drain_= type) do_drain_begin(drain_type, target); =20 if (drain_type =3D=3D BDRV_DRAIN_ALL) { - /* bdrv_drain_all() drains both src and target, and involves an - * additional block_job_pause_all() */ - g_assert_cmpint(job->pause_count, =3D=3D, 3); + /* bdrv_drain_all() drains both src and target */ + g_assert_cmpint(job->pause_count, =3D=3D, 2); } else { g_assert_cmpint(job->pause_count, =3D=3D, 1); } --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151376680900677.57110559930834; Wed, 20 Dec 2017 02:46:49 -0800 (PST) Received: from localhost ([::1]:45298 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbta-0005ts-F2 for importer@patchew.org; Wed, 20 Dec 2017 05:46:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39415) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbj2-0004k0-8V for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbj0-0005BO-JU for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbiu-00051s-3t; Wed, 20 Dec 2017 05:35:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2E8064903D; Wed, 20 Dec 2017 10:35:39 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1821D18B34; Wed, 20 Dec 2017 10:35:36 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:02 +0100 Message-Id: <20171220103412.13048-10-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Dec 2017 10:35:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 09/19] block: Nested drain_end must still call callbacks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_do_drained_begin() restricts the call of parent callbacks and aio_disable_external() to the outermost drain section, but the block driver callbacks are always called. bdrv_do_drained_end() must match this behaviour, otherwise nodes stay drained even if begin/end calls were balanced. Signed-off-by: Kevin Wolf --- block/io.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index 74d2e5278e..6038a16c58 100644 --- a/block/io.c +++ b/block/io.c @@ -273,19 +273,21 @@ void bdrv_drained_begin(BlockDriverState *bs) =20 void bdrv_drained_end(BlockDriverState *bs) { + int old_quiesce_counter; + if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, false); return; } assert(bs->quiesce_counter > 0); - if (atomic_fetch_dec(&bs->quiesce_counter) > 1) { - return; - } + old_quiesce_counter =3D atomic_fetch_dec(&bs->quiesce_counter); =20 /* Re-enable things in child-to-parent order */ bdrv_drain_invoke(bs, false, false); - bdrv_parent_drained_end(bs); - aio_enable_external(bdrv_get_aio_context(bs)); + if (old_quiesce_counter =3D=3D 1) { + bdrv_parent_drained_end(bs); + aio_enable_external(bdrv_get_aio_context(bs)); + } } =20 /* --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513767004417717.344017311373; Wed, 20 Dec 2017 02:50:04 -0800 (PST) Received: from localhost ([::1]:45384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbwY-0000La-6Y for importer@patchew.org; Wed, 20 Dec 2017 05:49:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbj8-0004pg-Vc for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbj7-0005IP-7P for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbix-00056A-AQ; Wed, 20 Dec 2017 05:35:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52CC6C075D77; Wed, 20 Dec 2017 10:35:42 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8077618B3A; Wed, 20 Dec 2017 10:35:39 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:03 +0100 Message-Id: <20171220103412.13048-11-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 20 Dec 2017 10:35:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 10/19] test-bdrv-drain: Test nested drain sections X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 57 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 57 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 4571137928..ede5cf6e64 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -85,6 +85,7 @@ static void aio_ret_cb(void *opaque, int ret) enum drain_type { BDRV_DRAIN_ALL, BDRV_DRAIN, + DRAIN_TYPE_MAX, }; =20 static void do_drain_begin(enum drain_type drain_type, BlockDriverState *b= s) @@ -221,6 +222,60 @@ static void test_quiesce_drain(void) test_quiesce_common(BDRV_DRAIN, false); } =20 +static void test_nested(void) +{ + BlockBackend *blk; + BlockDriverState *bs, *backing; + BDRVTestState *s, *backing_s; + enum drain_type outer, inner; + + blk =3D blk_new(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); + + for (outer =3D 0; outer < DRAIN_TYPE_MAX; outer++) { + for (inner =3D 0; inner < DRAIN_TYPE_MAX; inner++) { + /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */ + int bs_quiesce =3D (outer !=3D BDRV_DRAIN_ALL) + + (inner !=3D BDRV_DRAIN_ALL); + int backing_quiesce =3D 0; + int backing_cb_cnt =3D (outer !=3D BDRV_DRAIN) + + (inner !=3D BDRV_DRAIN); + + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(s->drain_count, =3D=3D, 0); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + + do_drain_begin(outer, bs); + do_drain_begin(inner, bs); + + g_assert_cmpint(bs->quiesce_counter, =3D=3D, bs_quiesce); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, backing_quie= sce); + g_assert_cmpint(s->drain_count, =3D=3D, 2); + g_assert_cmpint(backing_s->drain_count, =3D=3D, backing_cb_cnt= ); + + do_drain_end(inner, bs); + do_drain_end(outer, bs); + + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(s->drain_count, =3D=3D, 0); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + } + } + + bdrv_unref(backing); + bdrv_unref(bs); + blk_unref(blk); +} + =20 typedef struct TestBlockJob { BlockJob common; @@ -349,6 +404,8 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_al= l); g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); =20 + g_test_add_func("/bdrv-drain/nested", test_nested); + g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_= all); g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); =20 --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151376675740463.63873259879347; Wed, 20 Dec 2017 02:45:57 -0800 (PST) Received: from localhost ([::1]:45283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbsd-00050X-67 for importer@patchew.org; Wed, 20 Dec 2017 05:45:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjC-0004t7-3M for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbj8-0005Jm-8v for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:24094) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbj0-00059m-8g; Wed, 20 Dec 2017 05:35:46 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46B8562E87; Wed, 20 Dec 2017 10:35:45 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84A14619AF; Wed, 20 Dec 2017 10:35:42 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:04 +0100 Message-Id: <20171220103412.13048-12-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 20 Dec 2017 10:35:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 11/19] block: Don't notify parents in drain call chain X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is in preparation for subtree drains, i.e. drained sections that affect not only a single node, but recursively all child nodes, too. Calling the parent callbacks for drain is pointless when we just came from that parent node recursively and leads to multiple increases of bs->quiesce_counter in a single drain call. Don't do it. In order for this to work correctly, the parent callback must be called for every bdrv_drain_begin/end() call, not only for the outermost one: If we have a node N with two parents A and B, recursive draining of A should cause the quiesce_counter of B to increased because its child N is drained independently of B. If now B is recursively drained, too, A must increase its quiesce_counter because N is drained independently of A only now, even if N is going from quiesce_counter 1 to 2. Signed-off-by: Kevin Wolf --- include/block/block.h | 4 ++-- block.c | 13 +++++++++---- block/io.c | 47 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index c05cac57e5..60c5d11029 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -585,7 +585,7 @@ void bdrv_io_unplug(BlockDriverState *bs); * Begin a quiesced section of all users of @bs. This is part of * bdrv_drained_begin. */ -void bdrv_parent_drained_begin(BlockDriverState *bs); +void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore); =20 /** * bdrv_parent_drained_end: @@ -593,7 +593,7 @@ void bdrv_parent_drained_begin(BlockDriverState *bs); * End a quiesced section of all users of @bs. This is part of * bdrv_drained_end. */ -void bdrv_parent_drained_end(BlockDriverState *bs); +void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore); =20 /** * bdrv_drained_begin: diff --git a/block.c b/block.c index ddb6836c52..5867a2a2a0 100644 --- a/block.c +++ b/block.c @@ -1972,13 +1972,16 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, BlockDriverState *new_bs) { BlockDriverState *old_bs =3D child->bs; + int i; =20 if (old_bs && new_bs) { assert(bdrv_get_aio_context(old_bs) =3D=3D bdrv_get_aio_context(ne= w_bs)); } if (old_bs) { if (old_bs->quiesce_counter && child->role->drained_end) { - child->role->drained_end(child); + for (i =3D 0; i < old_bs->quiesce_counter; i++) { + child->role->drained_end(child); + } } if (child->role->detach) { child->role->detach(child); @@ -1991,7 +1994,9 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, if (new_bs) { QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); if (new_bs->quiesce_counter && child->role->drained_begin) { - child->role->drained_begin(child); + for (i =3D 0; i < new_bs->quiesce_counter; i++) { + child->role->drained_begin(child); + } } =20 if (child->role->attach) { @@ -4750,7 +4755,7 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioCo= ntext *new_context) AioContext *ctx =3D bdrv_get_aio_context(bs); =20 aio_disable_external(ctx); - bdrv_parent_drained_begin(bs); + bdrv_parent_drained_begin(bs, NULL); bdrv_drain(bs); /* ensure there are no in-flight requests */ =20 while (aio_poll(ctx, false)) { @@ -4764,7 +4769,7 @@ void bdrv_set_aio_context(BlockDriverState *bs, AioCo= ntext *new_context) */ aio_context_acquire(new_context); bdrv_attach_aio_context(bs, new_context); - bdrv_parent_drained_end(bs); + bdrv_parent_drained_end(bs, NULL); aio_enable_external(ctx); aio_context_release(new_context); } diff --git a/block/io.c b/block/io.c index 6038a16c58..09de0a9070 100644 --- a/block/io.c +++ b/block/io.c @@ -40,22 +40,28 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags); =20 -void bdrv_parent_drained_begin(BlockDriverState *bs) +void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ignore) { BdrvChild *c, *next; =20 QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { + if (c =3D=3D ignore) { + continue; + } if (c->role->drained_begin) { c->role->drained_begin(c); } } } =20 -void bdrv_parent_drained_end(BlockDriverState *bs) +void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore) { BdrvChild *c, *next; =20 QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { + if (c =3D=3D ignore) { + continue; + } if (c->role->drained_end) { c->role->drained_end(c); } @@ -139,6 +145,7 @@ typedef struct { BlockDriverState *bs; bool done; bool begin; + BdrvChild *parent; } BdrvCoDrainData; =20 static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) @@ -211,6 +218,9 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) return waited; } =20 +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent); +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); + static void bdrv_co_drain_bh_cb(void *opaque) { BdrvCoDrainData *data =3D opaque; @@ -219,9 +229,9 @@ static void bdrv_co_drain_bh_cb(void *opaque) =20 bdrv_dec_in_flight(bs); if (data->begin) { - bdrv_drained_begin(bs); + bdrv_do_drained_begin(bs, data->parent); } else { - bdrv_drained_end(bs); + bdrv_do_drained_end(bs, data->parent); } =20 data->done =3D true; @@ -229,7 +239,7 @@ static void bdrv_co_drain_bh_cb(void *opaque) } =20 static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, - bool begin) + bool begin, BdrvChild *par= ent) { BdrvCoDrainData data; =20 @@ -243,6 +253,7 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .bs =3D bs, .done =3D false, .begin =3D begin, + .parent =3D parent, }; bdrv_inc_in_flight(bs); aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), @@ -254,29 +265,34 @@ static void coroutine_fn bdrv_co_yield_to_drain(Block= DriverState *bs, assert(data.done); } =20 -void bdrv_drained_begin(BlockDriverState *bs) +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) { if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, true); + bdrv_co_yield_to_drain(bs, true, parent); return; } =20 /* Stop things in parent-to-child order */ if (atomic_fetch_inc(&bs->quiesce_counter) =3D=3D 0) { aio_disable_external(bdrv_get_aio_context(bs)); - bdrv_parent_drained_begin(bs); } =20 + bdrv_parent_drained_begin(bs, parent); bdrv_drain_invoke(bs, true, false); bdrv_drain_recurse(bs); } =20 -void bdrv_drained_end(BlockDriverState *bs) +void bdrv_drained_begin(BlockDriverState *bs) +{ + bdrv_do_drained_begin(bs, NULL); +} + +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) { int old_quiesce_counter; =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, false); + bdrv_co_yield_to_drain(bs, false, parent); return; } assert(bs->quiesce_counter > 0); @@ -284,12 +300,17 @@ void bdrv_drained_end(BlockDriverState *bs) =20 /* Re-enable things in child-to-parent order */ bdrv_drain_invoke(bs, false, false); + bdrv_parent_drained_end(bs, parent); if (old_quiesce_counter =3D=3D 1) { - bdrv_parent_drained_end(bs); aio_enable_external(bdrv_get_aio_context(bs)); } } =20 +void bdrv_drained_end(BlockDriverState *bs) +{ + bdrv_do_drained_end(bs, NULL); +} + /* * Wait for pending requests to complete on a single BlockDriverState subt= ree, * and suspend block driver's internal I/O until next request arrives. @@ -346,7 +367,7 @@ void bdrv_drain_all_begin(void) /* Stop things in parent-to-child order */ aio_context_acquire(aio_context); aio_disable_external(aio_context); - bdrv_parent_drained_begin(bs); + bdrv_parent_drained_begin(bs, NULL); bdrv_drain_invoke(bs, true, true); aio_context_release(aio_context); =20 @@ -391,7 +412,7 @@ void bdrv_drain_all_end(void) /* Re-enable things in child-to-parent order */ aio_context_acquire(aio_context); bdrv_drain_invoke(bs, false, true); - bdrv_parent_drained_end(bs); + bdrv_parent_drained_end(bs, NULL); aio_enable_external(aio_context); aio_context_release(aio_context); } --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15137664944391002.5019936831494; Wed, 20 Dec 2017 02:41:34 -0800 (PST) Received: from localhost ([::1]:45201 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRboF-0000oG-5g for importer@patchew.org; Wed, 20 Dec 2017 05:41:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjC-0004tX-E6 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbj9-0005LV-LS for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54050) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbj2-0005Cw-WC; Wed, 20 Dec 2017 05:35:49 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1816C4903B; Wed, 20 Dec 2017 10:35:48 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7849318B2C; Wed, 20 Dec 2017 10:35:45 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:05 +0100 Message-Id: <20171220103412.13048-13-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 20 Dec 2017 10:35:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 12/19] block: Add bdrv_subtree_drained_begin/end() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" bdrv_drained_begin() waits for the completion of requests in the whole subtree, but it only actually keeps its immediate bs parameter quiesced until bdrv_drained_end(). Add a version that keeps the whole subtree drained. As of this commit, graph changes cannot be allowed during a subtree drained section, but this will be fixed soon. Signed-off-by: Kevin Wolf --- include/block/block.h | 13 +++++++++++++ block/io.c | 54 ++++++++++++++++++++++++++++++++++++++++-------= ---- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 60c5d11029..de9c5a2b9b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -608,12 +608,25 @@ void bdrv_parent_drained_end(BlockDriverState *bs, Bd= rvChild *ignore); void bdrv_drained_begin(BlockDriverState *bs); =20 /** + * Like bdrv_drained_begin, but recursively begins a quiesced section for + * exclusive access to all child nodes as well. + * + * Graph changes are not allowed during a subtree drain section. + */ +void bdrv_subtree_drained_begin(BlockDriverState *bs); + +/** * bdrv_drained_end: * * End a quiescent section started by bdrv_drained_begin(). */ void bdrv_drained_end(BlockDriverState *bs); =20 +/** + * End a quiescent section started by bdrv_subtree_drained_begin(). + */ +void bdrv_subtree_drained_end(BlockDriverState *bs); + void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child, Error **errp); void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **er= rp); diff --git a/block/io.c b/block/io.c index 09de0a9070..6befef166d 100644 --- a/block/io.c +++ b/block/io.c @@ -145,6 +145,7 @@ typedef struct { BlockDriverState *bs; bool done; bool begin; + bool recursive; BdrvChild *parent; } BdrvCoDrainData; =20 @@ -218,8 +219,10 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) return waited; } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent); -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); +static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, + BdrvChild *parent); +static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, + BdrvChild *parent); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -229,9 +232,9 @@ static void bdrv_co_drain_bh_cb(void *opaque) =20 bdrv_dec_in_flight(bs); if (data->begin) { - bdrv_do_drained_begin(bs, data->parent); + bdrv_do_drained_begin(bs, data->recursive, data->parent); } else { - bdrv_do_drained_end(bs, data->parent); + bdrv_do_drained_end(bs, data->recursive, data->parent); } =20 data->done =3D true; @@ -239,7 +242,8 @@ static void bdrv_co_drain_bh_cb(void *opaque) } =20 static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, - bool begin, BdrvChild *par= ent) + bool begin, bool recursive, + BdrvChild *parent) { BdrvCoDrainData data; =20 @@ -253,6 +257,7 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .bs =3D bs, .done =3D false, .begin =3D begin, + .recursive =3D recursive, .parent =3D parent, }; bdrv_inc_in_flight(bs); @@ -265,10 +270,13 @@ static void coroutine_fn bdrv_co_yield_to_drain(Block= DriverState *bs, assert(data.done); } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent) +static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, + BdrvChild *parent) { + BdrvChild *child, *next; + if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, true, parent); + bdrv_co_yield_to_drain(bs, true, recursive, parent); return; } =20 @@ -280,19 +288,32 @@ static void bdrv_do_drained_begin(BlockDriverState *b= s, BdrvChild *parent) bdrv_parent_drained_begin(bs, parent); bdrv_drain_invoke(bs, true, false); bdrv_drain_recurse(bs); + + if (recursive) { + QLIST_FOREACH_SAFE(child, &bs->children, next, next) { + bdrv_do_drained_begin(child->bs, true, child); + } + } } =20 void bdrv_drained_begin(BlockDriverState *bs) { - bdrv_do_drained_begin(bs, NULL); + bdrv_do_drained_begin(bs, false, NULL); +} + +void bdrv_subtree_drained_begin(BlockDriverState *bs) +{ + bdrv_do_drained_begin(bs, true, NULL); } =20 -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) +static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, + BdrvChild *parent) { + BdrvChild *child, *next; int old_quiesce_counter; =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, false, parent); + bdrv_co_yield_to_drain(bs, false, recursive, parent); return; } assert(bs->quiesce_counter > 0); @@ -304,11 +325,22 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= BdrvChild *parent) if (old_quiesce_counter =3D=3D 1) { aio_enable_external(bdrv_get_aio_context(bs)); } + + if (recursive) { + QLIST_FOREACH_SAFE(child, &bs->children, next, next) { + bdrv_do_drained_end(child->bs, true, child); + } + } } =20 void bdrv_drained_end(BlockDriverState *bs) { - bdrv_do_drained_end(bs, NULL); + bdrv_do_drained_end(bs, false, NULL); +} + +void bdrv_subtree_drained_end(BlockDriverState *bs) +{ + bdrv_do_drained_end(bs, true, NULL); } =20 /* --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766641249313.8116953226199; Wed, 20 Dec 2017 02:44:01 -0800 (PST) Received: from localhost ([::1]:45220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbqt-0003Rp-Jn for importer@patchew.org; Wed, 20 Dec 2017 05:43:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjG-0004y0-C1 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbjE-0005QZ-10 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbj5-0005Fl-Bh; Wed, 20 Dec 2017 05:35:51 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 771152D59E4; Wed, 20 Dec 2017 10:35:50 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 688F7619AF; Wed, 20 Dec 2017 10:35:48 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:06 +0100 Message-Id: <20171220103412.13048-14-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 20 Dec 2017 10:35:50 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 13/19] test-bdrv-drain: Tests for bdrv_subtree_drain X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a subtree drain version to the existing test cases. Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index ede5cf6e64..c00d96bb2f 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -85,6 +85,7 @@ static void aio_ret_cb(void *opaque, int ret) enum drain_type { BDRV_DRAIN_ALL, BDRV_DRAIN, + BDRV_SUBTREE_DRAIN, DRAIN_TYPE_MAX, }; =20 @@ -93,6 +94,7 @@ static void do_drain_begin(enum drain_type drain_type, Bl= ockDriverState *bs) switch (drain_type) { case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break; case BDRV_DRAIN: bdrv_drained_begin(bs); break; + case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_begin(bs); break; default: g_assert_not_reached(); } } @@ -102,6 +104,7 @@ static void do_drain_end(enum drain_type drain_type, Bl= ockDriverState *bs) switch (drain_type) { case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break; case BDRV_DRAIN: bdrv_drained_end(bs); break; + case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_end(bs); break; default: g_assert_not_reached(); } } @@ -180,6 +183,11 @@ static void test_drv_cb_drain(void) test_drv_cb_common(BDRV_DRAIN, false); } =20 +static void test_drv_cb_drain_subtree(void) +{ + test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); +} + static void test_quiesce_common(enum drain_type drain_type, bool recursive) { BlockBackend *blk; @@ -222,6 +230,11 @@ static void test_quiesce_drain(void) test_quiesce_common(BDRV_DRAIN, false); } =20 +static void test_quiesce_drain_subtree(void) +{ + test_quiesce_common(BDRV_SUBTREE_DRAIN, true); +} + static void test_nested(void) { BlockBackend *blk; @@ -244,7 +257,8 @@ static void test_nested(void) /* XXX bdrv_drain_all() doesn't increase the quiesce_counter */ int bs_quiesce =3D (outer !=3D BDRV_DRAIN_ALL) + (inner !=3D BDRV_DRAIN_ALL); - int backing_quiesce =3D 0; + int backing_quiesce =3D (outer =3D=3D BDRV_SUBTREE_DRAIN) + + (inner =3D=3D BDRV_SUBTREE_DRAIN); int backing_cb_cnt =3D (outer !=3D BDRV_DRAIN) + (inner !=3D BDRV_DRAIN); =20 @@ -391,6 +405,11 @@ static void test_blockjob_drain(void) test_blockjob_common(BDRV_DRAIN); } =20 +static void test_blockjob_drain_subtree(void) +{ + test_blockjob_common(BDRV_SUBTREE_DRAIN); +} + int main(int argc, char **argv) { bdrv_init(); @@ -400,14 +419,20 @@ int main(int argc, char **argv) =20 g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_a= ll); g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); + g_test_add_func("/bdrv-drain/driver-cb/drain_subtree", + test_drv_cb_drain_subtree); =20 g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_al= l); g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); + g_test_add_func("/bdrv-drain/quiesce/drain_subtree", + test_quiesce_drain_subtree); =20 g_test_add_func("/bdrv-drain/nested", test_nested); =20 g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_= all); g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); + g_test_add_func("/bdrv-drain/blockjob/drain_subtree", + test_blockjob_drain_subtree); =20 return g_test_run(); } --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766927220985.3904977534265; Wed, 20 Dec 2017 02:48:47 -0800 (PST) Received: from localhost ([::1]:45372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbvX-0007uR-5K for importer@patchew.org; Wed, 20 Dec 2017 05:48:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjD-0004uc-E7 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbjB-0005O5-RH for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:35:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39348) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbj7-0005Hl-35; Wed, 20 Dec 2017 05:35:53 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39E9AC00D899; Wed, 20 Dec 2017 10:35:52 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id C906918B2F; Wed, 20 Dec 2017 10:35:50 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:07 +0100 Message-Id: <20171220103412.13048-15-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 20 Dec 2017 10:35:52 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 14/19] test-bdrv-drain: Test behaviour in coroutine context X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If bdrv_do_drained_begin/end() are called in coroutine context, they first use a BH to get out of the coroutine context. Call some existing tests again from a coroutine to cover this code path. Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 51 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 51 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index c00d96bb2f..a1e5693f33 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -188,6 +188,30 @@ static void test_drv_cb_drain_subtree(void) test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); } =20 +static coroutine_fn void test_drv_cb_coroutine_entry(void *opaque) +{ + bool *done =3D opaque; + + // XXX bdrv_drain_all() doesn't work in coroutine context + //test_drv_cb_drain_all(); + test_drv_cb_drain(); + test_drv_cb_drain_subtree(); + + *done =3D true; +} + +static void test_drv_cb_coroutine(void) +{ + Coroutine *co; + bool done; + + co =3D qemu_coroutine_create(test_drv_cb_coroutine_entry, &done); + qemu_coroutine_enter(co); + while (!done) { + aio_poll(qemu_get_aio_context(), true); + } +} + static void test_quiesce_common(enum drain_type drain_type, bool recursive) { BlockBackend *blk; @@ -235,6 +259,30 @@ static void test_quiesce_drain_subtree(void) test_quiesce_common(BDRV_SUBTREE_DRAIN, true); } =20 +static coroutine_fn void test_quiesce_coroutine_entry(void *opaque) +{ + bool *done =3D opaque; + + // XXX bdrv_drain_all() doesn't work in coroutine context + //test_quiesce_drain_all(); + test_quiesce_drain(); + test_quiesce_drain_subtree(); + + *done =3D true; +} + +static void test_quiesce_coroutine(void) +{ + Coroutine *co; + bool done; + + co =3D qemu_coroutine_create(test_quiesce_coroutine_entry, &done); + qemu_coroutine_enter(co); + while (!done) { + aio_poll(qemu_get_aio_context(), true); + } +} + static void test_nested(void) { BlockBackend *blk; @@ -421,11 +469,14 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); g_test_add_func("/bdrv-drain/driver-cb/drain_subtree", test_drv_cb_drain_subtree); + g_test_add_func("/bdrv-drain/driver-cb/coroutine", test_drv_cb_corouti= ne); + =20 g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_al= l); g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); g_test_add_func("/bdrv-drain/quiesce/drain_subtree", test_quiesce_drain_subtree); + g_test_add_func("/bdrv-drain/quiesce/coroutine", test_quiesce_coroutin= e); =20 g_test_add_func("/bdrv-drain/nested", test_nested); =20 --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513766898237401.03471732131516; Wed, 20 Dec 2017 02:48:18 -0800 (PST) Received: from localhost ([::1]:45304 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbv3-0007Kg-7L for importer@patchew.org; Wed, 20 Dec 2017 05:48:13 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjL-00053M-4E for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbjD-0005Q4-Jm for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32279) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbj8-0005Jd-Vh; Wed, 20 Dec 2017 05:35:55 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5E15356D1; Wed, 20 Dec 2017 10:35:53 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85990619AF; Wed, 20 Dec 2017 10:35:52 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:08 +0100 Message-Id: <20171220103412.13048-16-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 20 Dec 2017 10:35:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 15/19] test-bdrv-drain: Recursive draining with multiple parents X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Test that drain sections are correctly propagated through the graph. Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 74 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 74 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index a1e5693f33..b7322c5826 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -338,6 +338,79 @@ static void test_nested(void) blk_unref(blk); } =20 +static void test_multiparent(void) +{ + BlockBackend *blk_a, *blk_b; + BlockDriverState *bs_a, *bs_b, *backing; + BDRVTestState *a_s, *b_s, *backing_s; + + blk_a =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + bs_a =3D bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, + &error_abort); + a_s =3D bs_a->opaque; + blk_insert_bs(blk_a, bs_a, &error_abort); + + blk_b =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + bs_b =3D bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR, + &error_abort); + b_s =3D bs_b->opaque; + blk_insert_bs(blk_b, bs_b, &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_a, backing, &error_abort); + bdrv_set_backing_hd(bs_b, backing, &error_abort); + + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(a_s->drain_count, =3D=3D, 0); + g_assert_cmpint(b_s->drain_count, =3D=3D, 0); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); + + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(a_s->drain_count, =3D=3D, 1); + g_assert_cmpint(b_s->drain_count, =3D=3D, 1); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 1); + + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); + + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 2); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 2); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 2); + g_assert_cmpint(a_s->drain_count, =3D=3D, 2); + g_assert_cmpint(b_s->drain_count, =3D=3D, 2); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 2); + + do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); + + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(a_s->drain_count, =3D=3D, 1); + g_assert_cmpint(b_s->drain_count, =3D=3D, 1); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 1); + + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); + + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(a_s->drain_count, =3D=3D, 0); + g_assert_cmpint(b_s->drain_count, =3D=3D, 0); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + + bdrv_unref(backing); + bdrv_unref(bs_a); + bdrv_unref(bs_b); + blk_unref(blk_a); + blk_unref(blk_b); +} + =20 typedef struct TestBlockJob { BlockJob common; @@ -479,6 +552,7 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/quiesce/coroutine", test_quiesce_coroutin= e); =20 g_test_add_func("/bdrv-drain/nested", test_nested); + g_test_add_func("/bdrv-drain/multiparent", test_multiparent); =20 g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_= all); g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513767262810766.8217951282867; Wed, 20 Dec 2017 02:54:22 -0800 (PST) Received: from localhost ([::1]:45741 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRc0p-0004Rk-O4 for importer@patchew.org; Wed, 20 Dec 2017 05:54:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjM-00054j-AT for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbjJ-0005Wz-Ki for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39038) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbjB-0005M8-1C; Wed, 20 Dec 2017 05:35:57 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E10C2806B0; Wed, 20 Dec 2017 10:35:55 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3494818B2B; Wed, 20 Dec 2017 10:35:54 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:09 +0100 Message-Id: <20171220103412.13048-17-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 20 Dec 2017 10:35:55 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 16/19] block: Allow graph changes in subtree drained section X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We need to remember how many of the drain sections in which a node is were recursive (i.e. subtree drain rather than node drain), so that they can be correctly applied when children are added or removed during the drained section. With this change, it is safe to modify the graph even inside a bdrv_subtree_drained_begin/end() section. Signed-off-by: Kevin Wolf --- include/block/block.h | 7 +++++-- include/block/block_int.h | 2 ++ block.c | 40 +++++++++++++++++++++++++++++++++++++--- block/io.c | 15 ++++++--------- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index de9c5a2b9b..c8e6163cf7 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -610,8 +610,6 @@ void bdrv_drained_begin(BlockDriverState *bs); /** * Like bdrv_drained_begin, but recursively begins a quiesced section for * exclusive access to all child nodes as well. - * - * Graph changes are not allowed during a subtree drain section. */ void bdrv_subtree_drained_begin(BlockDriverState *bs); =20 @@ -627,6 +625,11 @@ void bdrv_drained_end(BlockDriverState *bs); */ void bdrv_subtree_drained_end(BlockDriverState *bs); =20 +void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, + BdrvChild *parent); +void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, + BdrvChild *parent); + void bdrv_add_child(BlockDriverState *parent, BlockDriverState *child, Error **errp); void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **er= rp); diff --git a/include/block/block_int.h b/include/block/block_int.h index e107163594..c2d3956633 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -717,6 +717,8 @@ struct BlockDriverState { =20 /* Accessed with atomic ops. */ int quiesce_counter; + int recursive_quiesce_counter; + unsigned int write_gen; /* Current data generation */ =20 /* Protected by reqs_lock. */ diff --git a/block.c b/block.c index 5867a2a2a0..37f8639fe9 100644 --- a/block.c +++ b/block.c @@ -822,6 +822,26 @@ static void bdrv_child_cb_drained_end(BdrvChild *child) bdrv_drained_end(bs); } =20 +static void bdrv_child_cb_attach(BdrvChild *child) +{ + BlockDriverState *bs =3D child->opaque; + int i; + + for (i =3D 0; i < bs->recursive_quiesce_counter; i++) { + bdrv_do_drained_begin(child->bs, true, child); + } +} + +static void bdrv_child_cb_detach(BdrvChild *child) +{ + BlockDriverState *bs =3D child->opaque; + int i; + + for (i =3D 0; i < bs->recursive_quiesce_counter; i++) { + bdrv_do_drained_end(child->bs, true, child); + } +} + static int bdrv_child_cb_inactivate(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; @@ -889,6 +909,8 @@ const BdrvChildRole child_file =3D { .inherit_options =3D bdrv_inherited_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, + .attach =3D bdrv_child_cb_attach, + .detach =3D bdrv_child_cb_detach, .inactivate =3D bdrv_child_cb_inactivate, }; =20 @@ -911,6 +933,8 @@ const BdrvChildRole child_format =3D { .inherit_options =3D bdrv_inherited_fmt_options, .drained_begin =3D bdrv_child_cb_drained_begin, .drained_end =3D bdrv_child_cb_drained_end, + .attach =3D bdrv_child_cb_attach, + .detach =3D bdrv_child_cb_detach, .inactivate =3D bdrv_child_cb_inactivate, }; =20 @@ -953,6 +977,8 @@ static void bdrv_backing_attach(BdrvChild *c) parent->backing_blocker); bdrv_op_unblock(backing_hd, BLOCK_OP_TYPE_BACKUP_TARGET, parent->backing_blocker); + + bdrv_child_cb_attach(c); } =20 static void bdrv_backing_detach(BdrvChild *c) @@ -963,6 +989,8 @@ static void bdrv_backing_detach(BdrvChild *c) bdrv_op_unblock_all(c->bs, parent->backing_blocker); error_free(parent->backing_blocker); parent->backing_blocker =3D NULL; + + bdrv_child_cb_detach(c); } =20 /* @@ -1978,14 +2006,17 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, assert(bdrv_get_aio_context(old_bs) =3D=3D bdrv_get_aio_context(ne= w_bs)); } if (old_bs) { + /* Detach first so that the recursive drain sections coming from @= child + * are already gone and we only end the drain sections that came f= rom + * elsewhere. */ + if (child->role->detach) { + child->role->detach(child); + } if (old_bs->quiesce_counter && child->role->drained_end) { for (i =3D 0; i < old_bs->quiesce_counter; i++) { child->role->drained_end(child); } } - if (child->role->detach) { - child->role->detach(child); - } QLIST_REMOVE(child, next_parent); } =20 @@ -1999,6 +2030,9 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, } } =20 + /* Attach only after starting new drained sections, so that recurs= ive + * drain sections coming from @child don't get an extra .drained_b= egin + * callback. */ if (child->role->attach) { child->role->attach(child); } diff --git a/block/io.c b/block/io.c index 6befef166d..2eb0783506 100644 --- a/block/io.c +++ b/block/io.c @@ -219,11 +219,6 @@ static bool bdrv_drain_recurse(BlockDriverState *bs) return waited; } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, - BdrvChild *parent); -static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent); - static void bdrv_co_drain_bh_cb(void *opaque) { BdrvCoDrainData *data =3D opaque; @@ -270,8 +265,8 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, assert(data.done); } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, - BdrvChild *parent) +void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, + BdrvChild *parent) { BdrvChild *child, *next; =20 @@ -290,6 +285,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, bdrv_drain_recurse(bs); =20 if (recursive) { + bs->recursive_quiesce_counter++; QLIST_FOREACH_SAFE(child, &bs->children, next, next) { bdrv_do_drained_begin(child->bs, true, child); } @@ -306,8 +302,8 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs) bdrv_do_drained_begin(bs, true, NULL); } =20 -static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent) +void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, + BdrvChild *parent) { BdrvChild *child, *next; int old_quiesce_counter; @@ -327,6 +323,7 @@ static void bdrv_do_drained_end(BlockDriverState *bs, b= ool recursive, } =20 if (recursive) { + bs->recursive_quiesce_counter--; QLIST_FOREACH_SAFE(child, &bs->children, next, next) { bdrv_do_drained_end(child->bs, true, child); } --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151376714185195.4605680489326; Wed, 20 Dec 2017 02:52:21 -0800 (PST) Received: from localhost ([::1]:45492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbys-0002JL-18 for importer@patchew.org; Wed, 20 Dec 2017 05:52:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjJ-000523-P6 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbjH-0005Uv-VR for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:8116) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbjC-0005OB-JB; Wed, 20 Dec 2017 05:35:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BDF95D5EA; Wed, 20 Dec 2017 10:35:57 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E986619AF; Wed, 20 Dec 2017 10:35:56 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:10 +0100 Message-Id: <20171220103412.13048-18-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 20 Dec 2017 10:35:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 17/19] test-bdrv-drain: Test graph changes in drained section X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 80 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 80 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index b7322c5826..6803e64950 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -411,6 +411,85 @@ static void test_multiparent(void) blk_unref(blk_b); } =20 +static void test_graph_change(void) +{ + BlockBackend *blk_a, *blk_b; + BlockDriverState *bs_a, *bs_b, *backing; + BDRVTestState *a_s, *b_s, *backing_s; + + blk_a =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + bs_a =3D bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, + &error_abort); + a_s =3D bs_a->opaque; + blk_insert_bs(blk_a, bs_a, &error_abort); + + blk_b =3D blk_new(BLK_PERM_ALL, BLK_PERM_ALL); + bs_b =3D bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR, + &error_abort); + b_s =3D bs_b->opaque; + blk_insert_bs(blk_b, bs_b, &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_a, backing, &error_abort); + + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(a_s->drain_count, =3D=3D, 0); + g_assert_cmpint(b_s->drain_count, =3D=3D, 0); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); + do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); + + bdrv_set_backing_hd(bs_b, backing, &error_abort); + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 5); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 5); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 5); + g_assert_cmpint(a_s->drain_count, =3D=3D, 5); + g_assert_cmpint(b_s->drain_count, =3D=3D, 5); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 5); + + bdrv_set_backing_hd(bs_b, NULL, &error_abort); + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 3); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 2); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 3); + g_assert_cmpint(a_s->drain_count, =3D=3D, 3); + g_assert_cmpint(b_s->drain_count, =3D=3D, 2); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 3); + + bdrv_set_backing_hd(bs_b, backing, &error_abort); + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 5); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 5); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 5); + g_assert_cmpint(a_s->drain_count, =3D=3D, 5); + g_assert_cmpint(b_s->drain_count, =3D=3D, 5); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 5); + + do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); + do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); + do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); + + g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(a_s->drain_count, =3D=3D, 0); + g_assert_cmpint(b_s->drain_count, =3D=3D, 0); + g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); + + bdrv_unref(backing); + bdrv_unref(bs_a); + bdrv_unref(bs_b); + blk_unref(blk_a); + blk_unref(blk_b); +} + =20 typedef struct TestBlockJob { BlockJob common; @@ -553,6 +632,7 @@ int main(int argc, char **argv) =20 g_test_add_func("/bdrv-drain/nested", test_nested); g_test_add_func("/bdrv-drain/multiparent", test_multiparent); + g_test_add_func("/bdrv-drain/graph-change", test_graph_change); =20 g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_= all); g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151376704670777.49132255638472; Wed, 20 Dec 2017 02:50:46 -0800 (PST) Received: from localhost ([::1]:45397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbxQ-00013T-Lr for importer@patchew.org; Wed, 20 Dec 2017 05:50:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjP-000580-JD for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbjO-0005cR-I7 for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46732) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbjE-0005QF-F0; Wed, 20 Dec 2017 05:36:00 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6813081DE8; Wed, 20 Dec 2017 10:35:59 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD92318B28; Wed, 20 Dec 2017 10:35:57 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:11 +0100 Message-Id: <20171220103412.13048-19-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 20 Dec 2017 10:35:59 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 18/19] commit: Simplify reopen of base X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Since commit bde70715, base is the only node that is reopened in commit_start(). This means that the code, which still involves an explicit BlockReopenQueue, can now be simplified by using bdrv_reopen(). Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng --- block/commit.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/block/commit.c b/block/commit.c index c5327551ce..bb6c904704 100644 --- a/block/commit.c +++ b/block/commit.c @@ -277,7 +277,6 @@ void commit_start(const char *job_id, BlockDriverState = *bs, const char *filter_node_name, Error **errp) { CommitBlockJob *s; - BlockReopenQueue *reopen_queue =3D NULL; int orig_base_flags; BlockDriverState *iter; BlockDriverState *commit_top_bs =3D NULL; @@ -299,12 +298,7 @@ void commit_start(const char *job_id, BlockDriverState= *bs, /* convert base to r/w, if necessary */ orig_base_flags =3D bdrv_get_flags(base); if (!(orig_base_flags & BDRV_O_RDWR)) { - reopen_queue =3D bdrv_reopen_queue(reopen_queue, base, NULL, - orig_base_flags | BDRV_O_RDWR); - } - - if (reopen_queue) { - bdrv_reopen_multiple(bdrv_get_aio_context(bs), reopen_queue, &loca= l_err); + bdrv_reopen(base, orig_base_flags | BDRV_O_RDWR, &local_err); if (local_err !=3D NULL) { error_propagate(errp, local_err); goto fail; --=20 2.13.6 From nobody Sat May 4 07:41:50 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1513767103874130.4424944665717; Wed, 20 Dec 2017 02:51:43 -0800 (PST) Received: from localhost ([::1]:45412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRby8-0001jJ-P1 for importer@patchew.org; Wed, 20 Dec 2017 05:51:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRbjS-0005BN-Ci for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRbjR-0005fc-9Q for qemu-devel@nongnu.org; Wed, 20 Dec 2017 05:36:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49142) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRbjI-0005Uo-Gn; Wed, 20 Dec 2017 05:36:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B41A550B0; Wed, 20 Dec 2017 10:36:03 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-136.ams2.redhat.com [10.36.116.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id B845060C80; Wed, 20 Dec 2017 10:35:59 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 20 Dec 2017 11:34:12 +0100 Message-Id: <20171220103412.13048-20-kwolf@redhat.com> In-Reply-To: <20171220103412.13048-1-kwolf@redhat.com> References: <20171220103412.13048-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 20 Dec 2017 10:36:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 19/19] block: Keep nodes drained between reopen_queue/multiple X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The bdrv_reopen*() implementation doesn't like it if the graph is changed between queuing nodes for reopen and actually reopening them (one of the reasons is that queuing can be recursive). So instead of draining the device only in bdrv_reopen_multiple(), require that callers already drained all affected nodes, and assert this in bdrv_reopen_queue(). Signed-off-by: Kevin Wolf Reviewed-by: Fam Zheng --- block.c | 23 ++++++++++++++++------- block/replication.c | 6 ++++++ qemu-io-cmds.c | 3 +++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 37f8639fe9..cfd39bea10 100644 --- a/block.c +++ b/block.c @@ -2774,6 +2774,7 @@ BlockDriverState *bdrv_open(const char *filename, con= st char *reference, * returns a pointer to bs_queue, which is either the newly allocated * bs_queue, or the existing bs_queue being used. * + * bs must be drained between bdrv_reopen_queue() and bdrv_reopen_multiple= (). */ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queu= e, BlockDriverState *bs, @@ -2789,6 +2790,11 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Blo= ckReopenQueue *bs_queue, BdrvChild *child; QDict *old_options, *explicit_options; =20 + /* Make sure that the caller remembered to use a drained section. This= is + * important to avoid graph changes between the recursive queuing here= and + * bdrv_reopen_multiple(). */ + assert(bs->quiesce_counter > 0); + if (bs_queue =3D=3D NULL) { bs_queue =3D g_new0(BlockReopenQueue, 1); QSIMPLEQ_INIT(bs_queue); @@ -2913,6 +2919,8 @@ BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue = *bs_queue, * If all devices prepare successfully, then the changes are committed * to all devices. * + * All affected nodes must be drained between bdrv_reopen_queue() and + * bdrv_reopen_multiple(). */ int bdrv_reopen_multiple(AioContext *ctx, BlockReopenQueue *bs_queue, Erro= r **errp) { @@ -2922,11 +2930,8 @@ int bdrv_reopen_multiple(AioContext *ctx, BlockReope= nQueue *bs_queue, Error **er =20 assert(bs_queue !=3D NULL); =20 - aio_context_release(ctx); - bdrv_drain_all_begin(); - aio_context_acquire(ctx); - QSIMPLEQ_FOREACH(bs_entry, bs_queue, entry) { + assert(bs_entry->state.bs->quiesce_counter > 0); if (bdrv_reopen_prepare(&bs_entry->state, bs_queue, &local_err)) { error_propagate(errp, local_err); goto cleanup; @@ -2955,8 +2960,6 @@ cleanup: } g_free(bs_queue); =20 - bdrv_drain_all_end(); - return ret; } =20 @@ -2966,12 +2969,18 @@ int bdrv_reopen(BlockDriverState *bs, int bdrv_flag= s, Error **errp) { int ret =3D -1; Error *local_err =3D NULL; - BlockReopenQueue *queue =3D bdrv_reopen_queue(NULL, bs, NULL, bdrv_fla= gs); + BlockReopenQueue *queue; =20 + bdrv_subtree_drained_begin(bs); + + queue =3D bdrv_reopen_queue(NULL, bs, NULL, bdrv_flags); ret =3D bdrv_reopen_multiple(bdrv_get_aio_context(bs), queue, &local_e= rr); if (local_err !=3D NULL) { error_propagate(errp, local_err); } + + bdrv_subtree_drained_end(bs); + return ret; } =20 diff --git a/block/replication.c b/block/replication.c index e41e293d2b..b1ea3caa4b 100644 --- a/block/replication.c +++ b/block/replication.c @@ -394,6 +394,9 @@ static void reopen_backing_file(BlockDriverState *bs, b= ool writable, new_secondary_flags =3D s->orig_secondary_flags; } =20 + bdrv_subtree_drained_begin(s->hidden_disk->bs); + bdrv_subtree_drained_begin(s->secondary_disk->bs); + if (orig_hidden_flags !=3D new_hidden_flags) { reopen_queue =3D bdrv_reopen_queue(reopen_queue, s->hidden_disk->b= s, NULL, new_hidden_flags); @@ -409,6 +412,9 @@ static void reopen_backing_file(BlockDriverState *bs, b= ool writable, reopen_queue, &local_err); error_propagate(errp, local_err); } + + bdrv_subtree_drained_end(s->hidden_disk->bs); + bdrv_subtree_drained_end(s->secondary_disk->bs); } =20 static void backup_job_cleanup(BlockDriverState *bs) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index de8e3de726..a6a70fc3dc 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2013,8 +2013,11 @@ static int reopen_f(BlockBackend *blk, int argc, cha= r **argv) opts =3D qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL; qemu_opts_reset(&reopen_opts); =20 + bdrv_subtree_drained_begin(bs); brq =3D bdrv_reopen_queue(NULL, bs, opts, flags); bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err); + bdrv_subtree_drained_end(bs); + if (local_err) { error_report_err(local_err); } else { --=20 2.13.6