From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958326; cv=none; d=zoho.com; s=zohoarc; b=X/XNjpNibq1CbYasuJrPU7czTpSULgj5ipPXxPL6o42JzARh+CCDSWah+NDnoZO6oEEbv0k1rvelYimUBes04UvJKI50AmwRWMAybIbbSk9a87taqs9PrqOD9pMxhf3+uRvBq/VxMDny2CS9hzdA3k5Y89ODYGRNfLXLjUGZs+0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958326; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=hZb8N209AelKC7WeV9hlfAl3ZOmix+1VRor5+bqaJv8=; b=dkTxm2rrSwz/7K5WQPFfrVSXjd00GTuac6cZIcp+mW9igY2Sk0QYYEvk3xY0Z+tYe58DHjPnDTn5lNV3RTDEGpwHjduY40OHPcbgdfPX9z1GMM+cW7/Jqh5sOW1jVXaKVV1C6SEGIQ5AEIXWMcq/07oiiM42Q6u7aj9xXCsf5I0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958326880154.04035114660326; Wed, 19 Jun 2019 08:32:06 -0700 (PDT) Received: from localhost ([::1]:39470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcZ6-0000rB-RU for importer@patchew.org; Wed, 19 Jun 2019 11:32:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42496) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcTx-0003Jp-N6 for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTv-0002Ce-Uw for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49456) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTs-0001y1-Ox; Wed, 19 Jun 2019 11:26:36 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA3B82E97C5; Wed, 19 Jun 2019 15:26:14 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BCF0019C79; Wed, 19 Jun 2019 15:26:11 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:25:55 +0200 Message-Id: <20190619152603.5937-2-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 19 Jun 2019 15:26:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/9] block: Introduce BdrvChild.parent_quiesce_counter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Commit 5cb2737e925042e6c7cd3fb0b01313950b03cddf laid out why bdrv_do_drained_end() must decrement the quiesce_counter after bdrv_drain_invoke(). It did not give a very good reason why it has to happen after bdrv_parent_drained_end(), instead only claiming symmetry to bdrv_do_drained_begin(). It turns out that delaying it for so long is wrong. Situation: We have an active commit job (i.e. a mirror job) from top to base for the following graph: filter | [file] | v top --[backing]--> base Now the VM is closed, which results in the job being cancelled and a bdrv_drain_all() happening pretty much simultaneously. Beginning the drain means the job is paused once whenever one of its nodes is quiesced. This is reversed when the drain ends. With how the code currently is, after base's drain ends (which means that it will have unpaused the job once), its quiesce_counter remains at 1 while it goes to undrain its parents (bdrv_parent_drained_end()). For some reason or another, undraining filter causes the job to be kicked and enter mirror_exit_common(), where it proceeds to invoke block_job_remove_all_bdrv(). Now base will be detached from the job. Because its quiesce_counter is still 1, it will unpause the job once more. So in total, undraining base will unpause the job twice. Eventually, this will lead to the job's pause_count going negative -- well, it would, were there not an assertion against this, which crashes qemu. The general problem is that if in bdrv_parent_drained_end() we undrain parent A, and then undrain parent B, which then leads to A detaching the child, bdrv_replace_child_noperm() will undrain A as if we had not done so yet; that is, one time too many. It follows that we cannot decrement the quiesce_counter after invoking bdrv_parent_drained_end(). Unfortunately, decrementing it before bdrv_parent_drained_end() would be wrong, too. Imagine the above situation in reverse: Undraining A leads to B detaching the child. If we had already decremented the quiesce_counter by that point, bdrv_replace_child_noperm() would undrain B one time too little; because it expects bdrv_parent_drained_end() to issue this undrain. But bdrv_parent_drained_end() won't do that, because B is no longer a parent. Therefore, we have to do something else. This patch opts for introducing a second quiesce_counter that counts how many times a child's parent has been quiesced (though c->role->drained_*). With that, bdrv_replace_child_noperm() just has to undrain the parent exactly that many times when removing a child, and it will always be right. Signed-off-by: Max Reitz --- include/block/block.h | 7 +++++++ include/block/block_int.h | 9 +++++++++ block.c | 15 +++++---------- block/io.c | 14 +++++++++++--- 4 files changed, 32 insertions(+), 13 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index f9415ed740..3c084e8222 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -616,6 +616,13 @@ void bdrv_parent_drained_begin(BlockDriverState *bs, B= drvChild *ignore, */ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll); =20 +/** + * bdrv_parent_drained_end_single: + * + * End a quiesced section for the parent of @c. + */ +void bdrv_parent_drained_end_single(BdrvChild *c); + /** * bdrv_parent_drained_end: * diff --git a/include/block/block_int.h b/include/block/block_int.h index d6415b53c1..7f62907932 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -729,6 +729,15 @@ struct BdrvChild { */ bool frozen; =20 + /* + * How many times the parent of this child has been drained + * (through role->drained_*). + * Usually, this is equal to bs->quiesce_counter (potentially + * reduced by bdrv_drain_all_count). It may differ while the + * child is entering or leaving a drained section. + */ + int parent_quiesce_counter; + QLIST_ENTRY(BdrvChild) next; QLIST_ENTRY(BdrvChild) next_parent; }; diff --git a/block.c b/block.c index c139540f2b..f7d7d8ccef 100644 --- a/block.c +++ b/block.c @@ -2251,24 +2251,19 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, if (child->role->detach) { child->role->detach(child); } - if (old_bs->quiesce_counter && child->role->drained_end) { - int num =3D old_bs->quiesce_counter; - if (child->role->parent_is_bds) { - num -=3D bdrv_drain_all_count; - } - assert(num >=3D 0); - for (i =3D 0; i < num; i++) { - child->role->drained_end(child); - } + while (child->parent_quiesce_counter) { + bdrv_parent_drained_end_single(child); } QLIST_REMOVE(child, next_parent); + } else { + assert(child->parent_quiesce_counter =3D=3D 0); } =20 child->bs =3D new_bs; =20 if (new_bs) { QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); - if (new_bs->quiesce_counter && child->role->drained_begin) { + if (new_bs->quiesce_counter) { int num =3D new_bs->quiesce_counter; if (child->role->parent_is_bds) { num -=3D bdrv_drain_all_count; diff --git a/block/io.c b/block/io.c index 9ba1bada36..112eed385c 100644 --- a/block/io.c +++ b/block/io.c @@ -55,6 +55,15 @@ void bdrv_parent_drained_begin(BlockDriverState *bs, Bdr= vChild *ignore, } } =20 +void bdrv_parent_drained_end_single(BdrvChild *c) +{ + assert(c->parent_quiesce_counter > 0); + c->parent_quiesce_counter--; + if (c->role->drained_end) { + c->role->drained_end(c); + } +} + void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignore, bool ignore_bds_parents) { @@ -64,9 +73,7 @@ void bdrv_parent_drained_end(BlockDriverState *bs, BdrvCh= ild *ignore, if (c =3D=3D ignore || (ignore_bds_parents && c->role->parent_is_b= ds)) { continue; } - if (c->role->drained_end) { - c->role->drained_end(c); - } + bdrv_parent_drained_end_single(c); } } =20 @@ -96,6 +103,7 @@ static bool bdrv_parent_drained_poll(BlockDriverState *b= s, BdrvChild *ignore, =20 void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) { + c->parent_quiesce_counter++; if (c->role->drained_begin) { c->role->drained_begin(c); } --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958473; cv=none; d=zoho.com; s=zohoarc; b=U7qJyRaaUlIMai7Ymmcv0xPKNDOo+xTazAqWdofLjGmkFuK1TN2CjMwYtW+w6Nd6Nuphcg6QII/O9qf7OHFVj9W/QJ48NSSnkcOUFrpbo1vPmoOITAemBuanJSmjcfP5lju6k6egMBkq4phAr/2VLEto7W4+PKvWl/BsBXUlyAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958473; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=NGJ/zNT6D7IIfWCAalB5o1SFh1jaKqrWzO3WEi4winY=; b=Lw8zrN7QkI9BQCZdxelEYD3KV43DJf7yvHv80vx8FzxkM8IKdEcbXt8YNrxFPgKASlw4sXpvR51IY+Nz7ga+MQuQMpvs1UJIwDA9OmEEDJo8AbrKeV8vD38sSw6H/P6ruHLj2b5QWZ+YhSsURv0N5U9RciGvma1iXJ+TPMfDkd8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958473546743.9675580589821; Wed, 19 Jun 2019 08:34:33 -0700 (PDT) Received: from localhost ([::1]:39512 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcbY-0003eX-Bo for importer@patchew.org; Wed, 19 Jun 2019 11:34:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42395) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcTs-00038e-PF for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTr-00029Q-4Q for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36402) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTn-0001z6-LX; Wed, 19 Jun 2019 11:26:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 042AA3082B69; Wed, 19 Jun 2019 15:26:17 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F79C19C6F; Wed, 19 Jun 2019 15:26:16 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:25:56 +0200 Message-Id: <20190619152603.5937-3-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 19 Jun 2019 15:26:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/9] block: Add @data_objs to bdrv_drain_invoke() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Callers can now pass a pointer to a GSList that bdrv_drain_invoke() (and its recursive callees) will fill with all BdrvCoDrainData objects they create. This will allow us to move the polling for BdrvCoDrainData.done to become true out of bdrv_drain_invoke() and into the root drain_end function. Signed-off-by: Max Reitz --- block/io.c | 65 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/block/io.c b/block/io.c index 112eed385c..6b518e5eb0 100644 --- a/block/io.c +++ b/block/io.c @@ -194,12 +194,14 @@ typedef struct { bool poll; BdrvChild *parent; bool ignore_bds_parents; + GSList **data_objs; } BdrvCoDrainData; =20 static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) { BdrvCoDrainData *data =3D opaque; BlockDriverState *bs =3D data->bs; + bool data_owned_by_caller =3D data->data_objs || !data->begin; =20 if (data->begin) { bs->drv->bdrv_co_drain_begin(bs); @@ -211,13 +213,14 @@ static void coroutine_fn bdrv_drain_invoke_entry(void= *opaque) atomic_mb_set(&data->done, true); bdrv_dec_in_flight(bs); =20 - if (data->begin) { + if (!data_owned_by_caller) { g_free(data); } } =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, + GSList **data_objs) { BdrvCoDrainData *data; =20 @@ -230,16 +233,23 @@ static void bdrv_drain_invoke(BlockDriverState *bs, b= ool begin) *data =3D (BdrvCoDrainData) { .bs =3D bs, .done =3D false, - .begin =3D begin + .begin =3D begin, + .data_objs =3D data_objs, }; =20 + if (data_objs) { + *data_objs =3D g_slist_prepend(*data_objs, data); + } + /* Make sure the driver callback completes during the polling phase for * drain_begin. */ bdrv_inc_in_flight(bs); data->co =3D qemu_coroutine_create(bdrv_drain_invoke_entry, data); aio_co_schedule(bdrv_get_aio_context(bs), data->co); =20 + /* TODO: Drop this and make callers pass @data_objs and poll */ if (!begin) { + assert(!data_objs); BDRV_POLL_WHILE(bs, !data->done); g_free(data); } @@ -281,7 +291,8 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, BdrvChild *parent, bool ignore_bds_paren= ts, bool poll); static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_parents= ); + BdrvChild *parent, bool ignore_bds_parents, + GSList **data_objs); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -308,7 +319,7 @@ static void bdrv_co_drain_bh_cb(void *opaque) data->ignore_bds_parents, data->poll); } else { bdrv_do_drained_end(bs, data->recursive, data->parent, - data->ignore_bds_parents); + data->ignore_bds_parents, data->data_objs); } if (ctx =3D=3D co_ctx) { aio_context_release(ctx); @@ -326,15 +337,15 @@ static void coroutine_fn bdrv_co_yield_to_drain(Block= DriverState *bs, bool begin, bool recursive, BdrvChild *parent, bool ignore_bds_parents, - bool poll) + bool poll, GSList **data_o= bjs) { - BdrvCoDrainData data; + BdrvCoDrainData *data =3D g_new(BdrvCoDrainData, 1); =20 /* Calling bdrv_drain() from a BH ensures the current coroutine yields= and * other coroutines run if they were queued by aio_co_enter(). */ =20 assert(qemu_in_coroutine()); - data =3D (BdrvCoDrainData) { + *data =3D (BdrvCoDrainData) { .co =3D qemu_coroutine_self(), .bs =3D bs, .done =3D false, @@ -343,17 +354,27 @@ static void coroutine_fn bdrv_co_yield_to_drain(Block= DriverState *bs, .parent =3D parent, .ignore_bds_parents =3D ignore_bds_parents, .poll =3D poll, + .data_objs =3D data_objs, }; + + if (data_objs) { + *data_objs =3D g_slist_prepend(*data_objs, data); + } + if (bs) { bdrv_inc_in_flight(bs); } aio_bh_schedule_oneshot(bdrv_get_aio_context(bs), - bdrv_co_drain_bh_cb, &data); + bdrv_co_drain_bh_cb, data); =20 qemu_coroutine_yield(); /* If we are resumed from some other event (such as an aio completion = or a * timer callback), it is a bug in the caller that should be fixed. */ - assert(data.done); + assert(data->done); + + if (!data_objs) { + g_free(data); + } } =20 void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, @@ -367,7 +388,7 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, } =20 bdrv_parent_drained_begin(bs, parent, ignore_bds_parents); - bdrv_drain_invoke(bs, true); + bdrv_drain_invoke(bs, true, NULL); } =20 static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, @@ -378,7 +399,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, =20 if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, true, recursive, parent, ignore_bds_par= ents, - poll); + poll, NULL); return; } =20 @@ -419,20 +440,21 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs) } =20 static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_parents) + BdrvChild *parent, bool ignore_bds_parents, + GSList **data_objs) { BdrvChild *child, *next; int old_quiesce_counter; =20 if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, false, recursive, parent, ignore_bds_pa= rents, - false); + false, data_objs); return; } assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ - bdrv_drain_invoke(bs, false); + bdrv_drain_invoke(bs, false, data_objs); bdrv_parent_drained_end(bs, parent, ignore_bds_parents); =20 old_quiesce_counter =3D atomic_fetch_dec(&bs->quiesce_counter); @@ -444,19 +466,20 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= bool recursive, assert(!ignore_bds_parents); bs->recursive_quiesce_counter--; QLIST_FOREACH_SAFE(child, &bs->children, next, next) { - bdrv_do_drained_end(child->bs, true, child, ignore_bds_parents= ); + bdrv_do_drained_end(child->bs, true, child, ignore_bds_parents, + data_objs); } } } =20 void bdrv_drained_end(BlockDriverState *bs) { - bdrv_do_drained_end(bs, false, NULL, false); + bdrv_do_drained_end(bs, false, NULL, false, NULL); } =20 void bdrv_subtree_drained_end(BlockDriverState *bs) { - bdrv_do_drained_end(bs, true, NULL, false); + bdrv_do_drained_end(bs, true, NULL, false, NULL); } =20 void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt) @@ -473,7 +496,7 @@ void bdrv_unapply_subtree_drain(BdrvChild *child, Block= DriverState *old_parent) int i; =20 for (i =3D 0; i < old_parent->recursive_quiesce_counter; i++) { - bdrv_do_drained_end(child->bs, true, child, false); + bdrv_do_drained_end(child->bs, true, child, false, NULL); } } =20 @@ -543,7 +566,7 @@ void bdrv_drain_all_begin(void) BlockDriverState *bs =3D NULL; =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(NULL, true, false, NULL, true, true); + bdrv_co_yield_to_drain(NULL, true, false, NULL, true, true, NULL); return; } =20 @@ -579,7 +602,7 @@ void bdrv_drain_all_end(void) AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 aio_context_acquire(aio_context); - bdrv_do_drained_end(bs, false, NULL, true); + bdrv_do_drained_end(bs, false, NULL, true, NULL); aio_context_release(aio_context); } =20 --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958762; cv=none; d=zoho.com; s=zohoarc; b=lq9mJrBOTsyYNTUtNK/gu0GTImnIULA3+AiU/IoLEZbO+yYRxcCslvUxU4xX6oRwBgysfdj8U/6KupC9bPFcOGgcMf/Cl7iLhaFZ+YusVmQRbA2jqf6ay7wrMdJUpzOeJsC2y02O5p8KzUdke5AZCvhQDPr86iHfhWAAl2T3BZM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958762; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=FMsRkha06iQLKcQtIo5COPxqTlVTGPo64DnHKt0cxH4=; b=ZtNYVFNMi4m3Ikv8K4lmc2rJJQaruNjZxGuOF8Hk6nq5TYjJX3FDpizVm7/puKncdrQoeo8xDjA2iTi3HNab+UUtp1ec+LmqwznzrgN+oEotbhKSKmph7GCbBh1VtIlKn1Pwy8zscmdYNgyVcVOwLaIUf3dG61u3ZjTEXb9KPGs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958762407891.8105213522756; Wed, 19 Jun 2019 08:39:22 -0700 (PDT) Received: from localhost ([::1]:39534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcgB-0008Sh-8O for importer@patchew.org; Wed, 19 Jun 2019 11:39:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42578) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcU1-0003TJ-BD for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcU0-0002G1-9E for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56020) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTx-00020a-NH; Wed, 19 Jun 2019 11:26:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 261BBF74CE; Wed, 19 Jun 2019 15:26:19 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B209B601A5; Wed, 19 Jun 2019 15:26:18 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:25:57 +0200 Message-Id: <20190619152603.5937-4-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 19 Jun 2019 15:26:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/9] block: Add bdrv_poll_drain_data_objs() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This function polls all of the involved AioContexts for a GSList of BdrvCoDrainData objects until all objects' .done is true. Signed-off-by: Max Reitz --- block/io.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/block/io.c b/block/io.c index 6b518e5eb0..eb84774abd 100644 --- a/block/io.c +++ b/block/io.c @@ -255,6 +255,63 @@ static void bdrv_drain_invoke(BlockDriverState *bs, bo= ol begin, } } =20 +/* TODO: Actually use this function and drop this forward declaration */ +static void bdrv_poll_drain_data_objs(GSList **data_objs, bool acquire_ctx) + __attribute__((unused)); + +/* + * Poll the AioContexts in the given list of BdrvCoDrainData objects + * until all of those objects are "done" (i.e. their .done field is + * true). + * Also, free all objects and the list. + * + * If @acquire_ctx is true, the AioContexts are locked while they are + * polled. + */ +static void bdrv_poll_drain_data_objs(GSList **data_objs, bool acquire_ctx) +{ + GSList *contexts =3D NULL; + GSList *iter; + + /* First collect the contexts while the BDSs are not gone */ + for (iter =3D *data_objs; iter; iter =3D iter->next) { + BdrvCoDrainData *drain_data =3D iter->data; + contexts =3D g_slist_prepend(contexts, + bdrv_get_aio_context(drain_data->bs)); + } + + /* + * Reverse the list so it is in the same order as *data_objs + * (prepend and then reverse has better performance than appending) + */ + contexts =3D g_slist_reverse(contexts); + + /* The BDSs may disappear here, but we only need their contexts */ + while (*data_objs) { + GSList *next; + BdrvCoDrainData *drain_data =3D (*data_objs)->data; + AioContext *ctx =3D contexts->data; + + if (acquire_ctx) { + aio_context_acquire(ctx); + } + AIO_WAIT_WHILE(ctx, !drain_data->done); + if (acquire_ctx) { + aio_context_release(ctx); + } + + g_free(drain_data); + + next =3D (*data_objs)->next; + g_slist_free_1(*data_objs); + *data_objs =3D next; + + next =3D contexts->next; + g_slist_free_1(contexts); + contexts =3D next; + } +} + /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() = */ bool bdrv_drain_poll(BlockDriverState *bs, bool recursive, BdrvChild *ignore_parent, bool ignore_bds_parents) --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958124; cv=none; d=zoho.com; s=zohoarc; b=IHjbKivzTv+vkDOx3TZsgSxOgjQu+RZX9/YinVdlarEwlf8UuOzwJ55oPmoDf28fudaydqIO8RrkCwW6W5FK2uVTMCjP29YB/ZH5Q3m6UaFgqBXuKz04yoANjYv9cGMANx7sbPyrfC0wTFiFfqpbEUiq97oc3sBPcFcp+ywMc0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958124; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=1QChxnOph93cDrwxCVnj/0Ln2K4M6PUUD17KO+s9yOE=; b=On4bbsQ3MgcGt3jjc5ORDaHFzIpd2GxbQcuZVkpx9DNW/gm7D9USBQsm2+rAH6xjrQOvOqnZf5qlPsvIGGPGf5Jfobl9WYR8WpNbXJsb8kkKhU6eTWPJWBuYp1R6/LYkEH0kpG8AbfoG4lLaBjEYV5eL4Nlj2JLwbntA1/TVNkU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958124063288.48486919126685; Wed, 19 Jun 2019 08:28:44 -0700 (PDT) Received: from localhost ([::1]:39408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcVr-00055T-BM for importer@patchew.org; Wed, 19 Jun 2019 11:28:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42392) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcTs-00037l-Cv for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTq-00029I-Uq for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49600) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTn-000227-Nc; Wed, 19 Jun 2019 11:26:31 -0400 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 7890F2E95A2; Wed, 19 Jun 2019 15:26:23 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF39451DDF; Wed, 19 Jun 2019 15:26:20 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:25:58 +0200 Message-Id: <20190619152603.5937-5-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 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, 19 Jun 2019 15:26:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/9] block: Move polling out of bdrv_drain_invoke() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead, let the root drained_end functions poll after the whole subtree has been undrained. These are bdrv_drain_all_end() and sometimes bdrv_do_drained_end(); the "sometimes" implies that the latter needs a parameter to tell whether it should poll or not. Note that bdrv_do_drained_end() now always receives either poll=3Dtrue (for the root level) or a pointer to a BdrvCoDrainData object list (as a recursive call from the root bdrv_do_drained_end() invocation). In the future, we will have callers that pass poll=3Dfalse and no list, because they do not care about polling at all. Signed-off-by: Max Reitz --- block/io.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/block/io.c b/block/io.c index eb84774abd..426ad5b4a1 100644 --- a/block/io.c +++ b/block/io.c @@ -201,7 +201,7 @@ static void coroutine_fn bdrv_drain_invoke_entry(void *= opaque) { BdrvCoDrainData *data =3D opaque; BlockDriverState *bs =3D data->bs; - bool data_owned_by_caller =3D data->data_objs || !data->begin; + bool data_owned_by_caller =3D data->data_objs; =20 if (data->begin) { bs->drv->bdrv_co_drain_begin(bs); @@ -246,19 +246,8 @@ static void bdrv_drain_invoke(BlockDriverState *bs, bo= ol begin, bdrv_inc_in_flight(bs); data->co =3D qemu_coroutine_create(bdrv_drain_invoke_entry, data); aio_co_schedule(bdrv_get_aio_context(bs), data->co); - - /* TODO: Drop this and make callers pass @data_objs and poll */ - if (!begin) { - assert(!data_objs); - BDRV_POLL_WHILE(bs, !data->done); - g_free(data); - } } =20 -/* TODO: Actually use this function and drop this forward declaration */ -static void bdrv_poll_drain_data_objs(GSList **data_objs, bool acquire_ctx) - __attribute__((unused)); - /* * Poll the AioContexts in the given list of BdrvCoDrainData objects * until all of those objects are "done" (i.e. their .done field is @@ -349,7 +338,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, bool poll); static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, BdrvChild *parent, bool ignore_bds_parents, - GSList **data_objs); + bool poll, GSList **data_objs); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -376,7 +365,8 @@ static void bdrv_co_drain_bh_cb(void *opaque) data->ignore_bds_parents, data->poll); } else { bdrv_do_drained_end(bs, data->recursive, data->parent, - data->ignore_bds_parents, data->data_objs); + data->ignore_bds_parents, data->poll, + data->data_objs); } if (ctx =3D=3D co_ctx) { aio_context_release(ctx); @@ -498,18 +488,24 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs) =20 static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, BdrvChild *parent, bool ignore_bds_parents, - GSList **data_objs) + bool poll, GSList **data_objs) { BdrvChild *child, *next; int old_quiesce_counter; + GSList *poll_data_objs =3D NULL; =20 if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, false, recursive, parent, ignore_bds_pa= rents, - false, data_objs); + poll, data_objs); return; } assert(bs->quiesce_counter > 0); =20 + if (poll) { + assert(data_objs =3D=3D NULL); + data_objs =3D &poll_data_objs; + } + /* Re-enable things in child-to-parent order */ bdrv_drain_invoke(bs, false, data_objs); bdrv_parent_drained_end(bs, parent, ignore_bds_parents); @@ -524,19 +520,24 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= bool recursive, bs->recursive_quiesce_counter--; QLIST_FOREACH_SAFE(child, &bs->children, next, next) { bdrv_do_drained_end(child->bs, true, child, ignore_bds_parents, - data_objs); + false, data_objs); } } + + if (poll) { + assert(data_objs =3D=3D &poll_data_objs); + bdrv_poll_drain_data_objs(data_objs, false); + } } =20 void bdrv_drained_end(BlockDriverState *bs) { - bdrv_do_drained_end(bs, false, NULL, false, NULL); + bdrv_do_drained_end(bs, false, NULL, false, true, NULL); } =20 void bdrv_subtree_drained_end(BlockDriverState *bs) { - bdrv_do_drained_end(bs, true, NULL, false, NULL); + bdrv_do_drained_end(bs, true, NULL, false, true, NULL); } =20 void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt) @@ -553,7 +554,7 @@ void bdrv_unapply_subtree_drain(BdrvChild *child, Block= DriverState *old_parent) int i; =20 for (i =3D 0; i < old_parent->recursive_quiesce_counter; i++) { - bdrv_do_drained_end(child->bs, true, child, false, NULL); + bdrv_do_drained_end(child->bs, true, child, false, true, NULL); } } =20 @@ -654,15 +655,18 @@ void bdrv_drain_all_begin(void) void bdrv_drain_all_end(void) { BlockDriverState *bs =3D NULL; + GSList *poll_data_objs =3D NULL; =20 while ((bs =3D bdrv_next_all_states(bs))) { AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 aio_context_acquire(aio_context); - bdrv_do_drained_end(bs, false, NULL, true, NULL); + bdrv_do_drained_end(bs, false, NULL, true, false, &poll_data_objs); aio_context_release(aio_context); } =20 + bdrv_poll_drain_data_objs(&poll_data_objs, true); + assert(bdrv_drain_all_count > 0); bdrv_drain_all_count--; } --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958330; cv=none; d=zoho.com; s=zohoarc; b=apgzrdMreEGLrEI5h64f8Q4OIrB/yB034sI47RzZ5b72AkanNXYBbFEzXnH/xUrCVmylRtLxiCrasDgT6NZYXOIx34eKTd7UhOijtWGvIkY4uchv7jHfnlfwq3HtjF46OHYilotkCj3UzZ07YCrFyQ5xr++9FQGHexT15ox41gA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958330; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=asAof73C/gNI4Lzv9lDYngMJP41yrfPK2KV38oEf2WU=; b=kJNJ4GfII9l6DLSoHTTtvn+MelPOn7QpXWT3vijKbjIIRURbfp4lUFzout9WCJy6bUxk5WpkWG515E5IQ0KlRWsiGJbDp48XkElpQWXTzIvXI/v0G6V+24uyefxak8kpiibcTlTstLgdlWTaokjhCSb5BwL6OIhSGDW8d7sVHFg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958330992747.0892149456025; Wed, 19 Jun 2019 08:32:10 -0700 (PDT) Received: from localhost ([::1]:39476 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcZB-0000yL-1o for importer@patchew.org; Wed, 19 Jun 2019 11:32:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42475) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcTw-0003Hk-QR for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTv-0002CQ-KZ for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39970) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTs-00026V-SY; Wed, 19 Jun 2019 11:26:37 -0400 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 A9030981D3; Wed, 19 Jun 2019 15:26:25 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47E7A5C2E8; Wed, 19 Jun 2019 15:26:25 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:25:59 +0200 Message-Id: <20190619152603.5937-6-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 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, 19 Jun 2019 15:26:25 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/9] block: Add @poll to bdrv_parent_drained_end_single() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This function has two callers; one wants it to poll, the other does not. To implement this parameter, we also need a new BdrvChildRole method, namely .drained_end_unquiesce(). This function differs from .drained_end() in that it should poll and is thus allowed to modify the block graph. Note that currently every BDS child's .drained_end() implementation is simply broken in exactly that regard; the current implementation is actually fit for .drained_end_unquiesce(). However, at this point we cannot implement .drained_end() correctly, so a later patch in this series will address that issue. Signed-off-by: Max Reitz --- include/block/block.h | 5 ++++- include/block/block_int.h | 14 ++++++++++++++ block.c | 2 +- block/io.c | 10 +++++++--- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 3c084e8222..d98237f0f1 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -620,8 +620,11 @@ void bdrv_parent_drained_begin_single(BdrvChild *c, bo= ol poll); * bdrv_parent_drained_end_single: * * End a quiesced section for the parent of @c. + * + * If @poll is true, poll until the parent is unquiesced. This may + * lead to changes in the block graph. */ -void bdrv_parent_drained_end_single(BdrvChild *c); +void bdrv_parent_drained_end_single(BdrvChild *c, bool poll); =20 /** * bdrv_parent_drained_end: diff --git a/include/block/block_int.h b/include/block/block_int.h index 7f62907932..fce9a9e7ee 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -670,6 +670,20 @@ struct BdrvChildRole { void (*drained_begin)(BdrvChild *child); void (*drained_end)(BdrvChild *child); =20 + /* + * Parents that require polling to actually become unquiesced + * should implement this function in addition to .drained_end(). + * In it, the parent should end the drain and aio_poll() until it + * is no longer quiesced. + * + * Thus, in contrast to .drained_end(), this function is allowed + * to change the graph. + * + * (This pointer may be NULL, in which case .drained_end() is + * called instead.) + */ + void (*drained_end_unquiesce)(BdrvChild *child); + /* * Returns whether the parent has pending requests for the child. This * callback is polled after .drained_begin() has been called until all diff --git a/block.c b/block.c index f7d7d8ccef..31b85df0f0 100644 --- a/block.c +++ b/block.c @@ -2252,7 +2252,7 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, child->role->detach(child); } while (child->parent_quiesce_counter) { - bdrv_parent_drained_end_single(child); + bdrv_parent_drained_end_single(child, true); } QLIST_REMOVE(child, next_parent); } else { diff --git a/block/io.c b/block/io.c index 426ad5b4a1..5f30baa8e5 100644 --- a/block/io.c +++ b/block/io.c @@ -55,12 +55,16 @@ void bdrv_parent_drained_begin(BlockDriverState *bs, Bd= rvChild *ignore, } } =20 -void bdrv_parent_drained_end_single(BdrvChild *c) +void bdrv_parent_drained_end_single(BdrvChild *c, bool poll) { assert(c->parent_quiesce_counter > 0); c->parent_quiesce_counter--; if (c->role->drained_end) { - c->role->drained_end(c); + if (poll && c->role->drained_end_unquiesce) { + c->role->drained_end_unquiesce(c); + } else { + c->role->drained_end(c); + } } } =20 @@ -73,7 +77,7 @@ void bdrv_parent_drained_end(BlockDriverState *bs, BdrvCh= ild *ignore, if (c =3D=3D ignore || (ignore_bds_parents && c->role->parent_is_b= ds)) { continue; } - bdrv_parent_drained_end_single(c); + bdrv_parent_drained_end_single(c, false); } } =20 --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958145; cv=none; d=zoho.com; s=zohoarc; b=KLU0MaeRzL3zXQYO5+LDnovRh/ZKG6zBK+JaGQCYA7yBEYCQplaNQTMR7KWWTWBHEHXYR0zO/5OnuVnm347oqj/kHw9V0YkqSBc4vl6M6t4qQpVf4Bowb2fiwsanz9iL5b2aBZy06Ft21IPeU2uzFkelCVHBbiDpzK6jeKttW7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958145; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=QpreHFkQ8oYgQvNkkmxmzRAx7yQDB+Q4Ws+gbT6NTz8=; b=fOrDDAyXuj6d5q+lNI5jgF0YhatHUOcYIUhobIpwWrGsWp4FtIUuPmViZj0ZIIMXyLlP+BGmBNCuKco8Qgl1uNwmjGmyjSk3lS+Sj4YVTcTrr7LHR3y/kM1VurRwtgikQqaBvq81P0VyV2C1A0qtyVR6HDFNY4l7ixipsuwcsSw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958145169860.5317501426562; Wed, 19 Jun 2019 08:29:05 -0700 (PDT) Received: from localhost ([::1]:39410 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcWG-0005WX-5z for importer@patchew.org; Wed, 19 Jun 2019 11:29:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42463) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcTw-0003GA-43 for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTv-0002Bq-3u for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58844) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTs-00024W-Oy; Wed, 19 Jun 2019 11:26:36 -0400 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 C27AE81DE1; Wed, 19 Jun 2019 15:26:27 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 643CB60FAB; Wed, 19 Jun 2019 15:26:27 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:26:00 +0200 Message-Id: <20190619152603.5937-7-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 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, 19 Jun 2019 15:26:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 6/9] block: Add bdrv_drained_end_no_poll() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In contrast to bdrv_drained_end(), which does poll and may thus lead to graph changes, this new interface to bdrv_do_drained_end() will not poll. Signed-off-by: Max Reitz --- include/block/block.h | 12 +++++++++++- block/io.c | 5 +++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/block/block.h b/include/block/block.h index d98237f0f1..422448d773 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -680,10 +680,20 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs); /** * bdrv_drained_end: * - * End a quiescent section started by bdrv_drained_begin(). + * End a quiescent section started by bdrv_drained_begin(). This may + * result in block graph changes. */ void bdrv_drained_end(BlockDriverState *bs); =20 +/** + * bdrv_drained_end_no_poll: + * + * Same as bdrv_drained_end(), but do not poll for the subgraph to + * actually become unquiesced. Therefore, no graph changes will occur + * with this function. + */ +void bdrv_drained_end_no_poll(BlockDriverState *bs); + /** * End a quiescent section started by bdrv_subtree_drained_begin(). */ diff --git a/block/io.c b/block/io.c index 5f30baa8e5..188dea22bc 100644 --- a/block/io.c +++ b/block/io.c @@ -539,6 +539,11 @@ void bdrv_drained_end(BlockDriverState *bs) bdrv_do_drained_end(bs, false, NULL, false, true, NULL); } =20 +void bdrv_drained_end_no_poll(BlockDriverState *bs) +{ + bdrv_do_drained_end(bs, false, NULL, false, false, NULL); +} + void bdrv_subtree_drained_end(BlockDriverState *bs) { bdrv_do_drained_end(bs, true, NULL, false, true, NULL); --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958559; cv=none; d=zoho.com; s=zohoarc; b=OuQesWxN91BiVguc0ioA1uSip5saYGlhwAiB5gqU05x+yTQ8lR4z7m5q05DJotQ1RKXKxiPjNufsiqTjnHdWh6DiublyzXc7j/ix/b5HspwFoMJMjf0dQ/wYmE8c2UjIgmaby9lUxYgLJW/Sgys7mYQenZeisw1BIx1cKJR8zGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958559; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=N0x4AeouD35WQ+9JrD5mjiilGtX5gl/8W6vs3NsxSMQ=; b=DRwhmY4kfe9ETlT8k2HTNZkRFtF0MPMrL4k+utvfseS8cfyVjrRy17hupk2TgKmZSqB05tiXlfSIMLLaaEJcA/0SquiQWHaZ8s46KhGG4h94S140XbzuIzaoGu0NzUzIhuzoco1g3Dml558KqgCgnOi6eOLkyAGT145grcfdpRk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958559174134.89245961739528; Wed, 19 Jun 2019 08:35:59 -0700 (PDT) Received: from localhost ([::1]:39516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdccw-0004YD-4Y for importer@patchew.org; Wed, 19 Jun 2019 11:35:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42524) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcTy-0003Ln-Kh for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTx-0002Dg-Hq for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46356) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTv-0002BR-4s; Wed, 19 Jun 2019 11:26:39 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BEB8305E237; Wed, 19 Jun 2019 15:26:33 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82841608C2; Wed, 19 Jun 2019 15:26:29 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:26:01 +0200 Message-Id: <20190619152603.5937-8-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 19 Jun 2019 15:26:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 7/9] block: Fix BDS children's .drained_end() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" BdrvChildRole.drained_end() must not poll, bdrv_child_cb_drained_end() should use bdrv_drained_end_no_poll() instead of bdrv_drained_end(). The existing implementation works perfectly well for .drained_end_unquiesce(), though, so use it there. Signed-off-by: Max Reitz --- block.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block.c b/block.c index 31b85df0f0..1652f3d29b 100644 --- a/block.c +++ b/block.c @@ -912,6 +912,12 @@ static bool bdrv_child_cb_drained_poll(BdrvChild *chil= d) } =20 static void bdrv_child_cb_drained_end(BdrvChild *child) +{ + BlockDriverState *bs =3D child->opaque; + bdrv_drained_end_no_poll(bs); +} + +static void bdrv_child_cb_drained_end_unquiesce(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; bdrv_drained_end(bs); @@ -1014,6 +1020,7 @@ const BdrvChildRole child_file =3D { .drained_begin =3D bdrv_child_cb_drained_begin, .drained_poll =3D bdrv_child_cb_drained_poll, .drained_end =3D bdrv_child_cb_drained_end, + .drained_end_unquiesce =3D bdrv_child_cb_drained_end_unquiesce, .attach =3D bdrv_child_cb_attach, .detach =3D bdrv_child_cb_detach, .inactivate =3D bdrv_child_cb_inactivate, @@ -1042,6 +1049,7 @@ const BdrvChildRole child_format =3D { .drained_begin =3D bdrv_child_cb_drained_begin, .drained_poll =3D bdrv_child_cb_drained_poll, .drained_end =3D bdrv_child_cb_drained_end, + .drained_end_unquiesce =3D bdrv_child_cb_drained_end_unquiesce, .attach =3D bdrv_child_cb_attach, .detach =3D bdrv_child_cb_detach, .inactivate =3D bdrv_child_cb_inactivate, @@ -1168,6 +1176,7 @@ const BdrvChildRole child_backing =3D { .drained_begin =3D bdrv_child_cb_drained_begin, .drained_poll =3D bdrv_child_cb_drained_poll, .drained_end =3D bdrv_child_cb_drained_end, + .drained_end_unquiesce =3D bdrv_child_cb_drained_end_unquiesce, .inactivate =3D bdrv_child_cb_inactivate, .update_filename =3D bdrv_backing_update_filename, .can_set_aio_ctx =3D bdrv_child_cb_can_set_aio_ctx, --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958555; cv=none; d=zoho.com; s=zohoarc; b=DZ29Sdb7OMzKLNS/XC/AkL7wxHU5JyXhYqPgig2mRBqtG7gi9Ms1XRRM5XDmkF+IH1c0VswpI2ESdEaUxdq+vBqYdFBdZVO/bFXvrpCvWrZa9I/54rmTyJmyFv1k8tcMX2x2YyGNbjeYW2pH7mTFIajN/6stl5XRG7JhEjtezyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958555; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=PlS+OOdNcwEXR8a8OyJyixooJuIzWm2iEEmcBO0VRbw=; b=ivL9C16Z/a3hT4ePWFORO7ARzRDaWAywcbDfcs6M9cCIjMVFuxb3yud87ORkilJIumD8bUiXyUdCBPFI5WKu8DM1dPB0hvVkMBJnQgDSiJoi+jRHVKLd3qLzxXQHEmE2Dt8/FFvfOwXUT7htGnvSicyGShPRczqh8EHNkD6L/Aw= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1560958555868784.0361734352801; Wed, 19 Jun 2019 08:35:55 -0700 (PDT) Received: from localhost ([::1]:39514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdccm-0004Hw-Rt for importer@patchew.org; Wed, 19 Jun 2019 11:35:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42562) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcU0-0003Qx-EA for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTz-0002FS-EU for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17405) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTx-0002D3-4D; Wed, 19 Jun 2019 11:26:41 -0400 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 66110308622C; Wed, 19 Jun 2019 15:26:35 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 084DB5C2E9; Wed, 19 Jun 2019 15:26:34 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:26:02 +0200 Message-Id: <20190619152603.5937-9-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 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.42]); Wed, 19 Jun 2019 15:26:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 8/9] iotests: Add @has_quit to vm.shutdown() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If a test has issued a quit command already (which may be useful to do explicitly because the test wants to show its effects), QEMUMachine.shutdown() should not do so again. Otherwise, the VM may well return an ECONNRESET which will lead QEMUMachine.shutdown() to killing it, which then turns into a "qemu received signal 9" line. Signed-off-by: Max Reitz --- python/qemu/__init__.py | 5 +++-- tests/qemu-iotests/255 | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/python/qemu/__init__.py b/python/qemu/__init__.py index dbaf8a5311..25207a2970 100644 --- a/python/qemu/__init__.py +++ b/python/qemu/__init__.py @@ -332,13 +332,14 @@ class QEMUMachine(object): self._load_io_log() self._post_shutdown() =20 - def shutdown(self): + def shutdown(self, has_quit=3DFalse): """ Terminate the VM and clean up """ if self.is_running(): try: - self._qmp.cmd('quit') + if not has_quit: + self._qmp.cmd('quit') self._qmp.close() except: self._popen.kill() diff --git a/tests/qemu-iotests/255 b/tests/qemu-iotests/255 index 49433ec122..3632d507d0 100755 --- a/tests/qemu-iotests/255 +++ b/tests/qemu-iotests/255 @@ -132,4 +132,4 @@ with iotests.FilePath('src.qcow2') as src_path, \ vm.qmp_log('block-job-cancel', device=3D'job0') vm.qmp_log('quit') =20 - vm.shutdown() + vm.shutdown(has_quit=3DTrue) --=20 2.21.0 From nobody Tue Nov 11 03:18:53 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560958765; cv=none; d=zoho.com; s=zohoarc; b=gAjH9q80imM/eTBJfQjCg1k5fQcBzEcEX3Iqi34vVS4yfc2Kasp3LMlmwXMEDlUETGmYX+a/MhdG6DFdGFJwKtN4b1VFk5XI898KEiInib0AuxKIpAz1w6fPTpX0IU3A7MEJh9hm+Jj/9byDKZtacshMaEZBQpUbEJBf4holt0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560958765; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=4hBOPyIuUMJtnLcAgCyaBmi1vX6fe8EYCt4Pu3u6vfE=; b=l8ilY90ZIQyMtOggYO1vwDj+bg/9NUEHLd+YTQXPl4WVFyDeze6cDoCz0DdtJhMgcJTjubm2XWEdfzzFLXovJz9YUJ3UnswMfv6APqqBH1+/q/X8ifJGV/JqCVcv47UWO6LBHdTa/SokNlcySSy4QfYzIXfmUVIPCfWe3IlDq4o= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15609587655417.9532527975649145; Wed, 19 Jun 2019 08:39:25 -0700 (PDT) Received: from localhost ([::1]:39536 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcgE-0000AE-Jd for importer@patchew.org; Wed, 19 Jun 2019 11:39:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42569) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hdcU0-0003Rq-Pn for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hdcTz-0002Fj-Mb for qemu-devel@nongnu.org; Wed, 19 Jun 2019 11:26:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49848) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hdcTw-0002Cr-NY; Wed, 19 Jun 2019 11:26:40 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F341E2E95B0; Wed, 19 Jun 2019 15:26:39 +0000 (UTC) Received: from localhost (ovpn-116-121.ams2.redhat.com [10.36.116.121]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1CDD7604CC; Wed, 19 Jun 2019 15:26:36 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Wed, 19 Jun 2019 17:26:03 +0200 Message-Id: <20190619152603.5937-10-mreitz@redhat.com> In-Reply-To: <20190619152603.5937-1-mreitz@redhat.com> References: <20190619152603.5937-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 19 Jun 2019 15:26:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 9/9] iotests: Test commit with a filter on the chain X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Before the previous patches, the first case resulted in a failed assertion (which is noted as qemu receiving a SIGABRT in the test output), and the second usually triggered a segmentation fault. Signed-off-by: Max Reitz --- tests/qemu-iotests/040 | 40 +++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/040.out | 4 ++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/040 b/tests/qemu-iotests/040 index b81133a474..aa0b1847e3 100755 --- a/tests/qemu-iotests/040 +++ b/tests/qemu-iotests/040 @@ -92,9 +92,10 @@ class TestSingleDrive(ImageCommitTestCase): =20 self.vm.add_device("scsi-hd,id=3Dscsi0,drive=3Ddrive0") self.vm.launch() + self.has_quit =3D False =20 def tearDown(self): - self.vm.shutdown() + self.vm.shutdown(has_quit=3Dself.has_quit) os.remove(test_img) os.remove(mid_img) os.remove(backing_img) @@ -109,6 +110,43 @@ class TestSingleDrive(ImageCommitTestCase): self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xab 0 52= 4288', backing_img).find("verification failed")) self.assertEqual(-1, qemu_io('-f', 'raw', '-c', 'read -P 0xef 5242= 88 524288', backing_img).find("verification failed")) =20 + def test_commit_with_filter_and_quit(self): + result =3D self.vm.qmp('object-add', qom_type=3D'throttle-group', = id=3D'tg') + self.assert_qmp(result, 'return', {}) + + # Add a filter outside of the backing chain + result =3D self.vm.qmp('blockdev-add', driver=3D'throttle', node_n= ame=3D'filter', throttle_group=3D'tg', file=3D'mid') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('block-commit', device=3D'drive0') + self.assert_qmp(result, 'return', {}) + + # Quit immediately, thus forcing a simultaneous cancel of the + # block job and a bdrv_drain_all() + result =3D self.vm.qmp('quit') + self.assert_qmp(result, 'return', {}) + + self.has_quit =3D True + + # Same as above, but this time we add the filter after starting the job + def test_commit_plus_filter_and_quit(self): + result =3D self.vm.qmp('object-add', qom_type=3D'throttle-group', = id=3D'tg') + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('block-commit', device=3D'drive0') + self.assert_qmp(result, 'return', {}) + + # Add a filter outside of the backing chain + result =3D self.vm.qmp('blockdev-add', driver=3D'throttle', node_n= ame=3D'filter', throttle_group=3D'tg', file=3D'mid') + self.assert_qmp(result, 'return', {}) + + # Quit immediately, thus forcing a simultaneous cancel of the + # block job and a bdrv_drain_all() + result =3D self.vm.qmp('quit') + self.assert_qmp(result, 'return', {}) + + self.has_quit =3D True + def test_device_not_found(self): result =3D self.vm.qmp('block-commit', device=3D'nonexistent', top= =3D'%s' % mid_img) self.assert_qmp(result, 'error/class', 'DeviceNotFound') diff --git a/tests/qemu-iotests/040.out b/tests/qemu-iotests/040.out index 802ffaa0c0..220a5fa82c 100644 --- a/tests/qemu-iotests/040.out +++ b/tests/qemu-iotests/040.out @@ -1,5 +1,5 @@ -........................................... +............................................... ---------------------------------------------------------------------- -Ran 43 tests +Ran 47 tests =20 OK --=20 2.21.0