From nobody Thu May 2 11:25:52 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 1510655979935432.78714821623703; Tue, 14 Nov 2017 02:39:39 -0800 (PST) Received: from localhost ([::1]:58725 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYck-0003JP-3j for importer@patchew.org; Tue, 14 Nov 2017 05:39:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYb8-0002Rj-0H for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEYb4-0004Jb-Tb for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEYb4-0004IQ-NE for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:38 -0500 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 D9CC54E4C0; Tue, 14 Nov 2017 10:37:37 +0000 (UTC) Received: from localhost (unknown [10.36.118.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDC21A2940; Tue, 14 Nov 2017 10:37:28 +0000 (UTC) From: Stefan Hajnoczi To: Date: Tue, 14 Nov 2017 10:37:17 +0000 Message-Id: <20171114103721.13869-2-stefanha@redhat.com> In-Reply-To: <20171114103721.13869-1-stefanha@redhat.com> References: <20171114103721.13869-1-stefanha@redhat.com> 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.38]); Tue, 14 Nov 2017 10:37:37 +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] [PULL for-2.11-rc2 1/5] block: all I/O should be completed before removing throttle timers. 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: Peter Maydell , Zhengui , Stefan Hajnoczi 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: Zhengui In blk_remove_bs, all I/O should be completed before removing throttle timers. If there has inflight I/O, removing throttle timers here will cause the inflight I/O never return. This patch add bdrv_drained_begin before throttle_timers_detach_aio_context to let all I/O completed before removing throttle timers. [Moved declaration of bs as suggested by Alberto Garcia . --Stefan] Signed-off-by: Zhengui Reviewed-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Message-id: 1508564040-120700-1-git-send-email-lizhengui@huawei.com Signed-off-by: Stefan Hajnoczi --- block/block-backend.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 45d9101be3..18e543780d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -655,12 +655,16 @@ BlockBackend *blk_by_public(BlockBackendPublic *publi= c) */ void blk_remove_bs(BlockBackend *blk) { + BlockDriverState *bs; ThrottleTimers *tt; =20 notifier_list_notify(&blk->remove_bs_notifiers, blk); if (blk->public.throttle_group_member.throttle_state) { tt =3D &blk->public.throttle_group_member.throttle_timers; + bs =3D blk_bs(blk); + bdrv_drained_begin(bs); throttle_timers_detach_aio_context(tt); + bdrv_drained_end(bs); } =20 blk_update_root_state(blk); --=20 2.13.6 From nobody Thu May 2 11:25:52 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 1510655979976309.5509677900401; Tue, 14 Nov 2017 02:39:39 -0800 (PST) Received: from localhost ([::1]:58726 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYcj-0003KW-Es for importer@patchew.org; Tue, 14 Nov 2017 05:39:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYbC-0002Sh-Jh for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEYb6-0004LJ-Ug for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEYb6-0004Ko-Os for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:40 -0500 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 E3CB87EA97; Tue, 14 Nov 2017 10:37:39 +0000 (UTC) Received: from localhost (unknown [10.36.118.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13AE7A294A; Tue, 14 Nov 2017 10:37:38 +0000 (UTC) From: Stefan Hajnoczi To: Date: Tue, 14 Nov 2017 10:37:18 +0000 Message-Id: <20171114103721.13869-3-stefanha@redhat.com> In-Reply-To: <20171114103721.13869-1-stefanha@redhat.com> References: <20171114103721.13869-1-stefanha@redhat.com> 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.28]); Tue, 14 Nov 2017 10:37: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] [PULL for-2.11-rc2 2/5] throttle-groups: drain before detaching ThrottleState 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: Peter Maydell , Stefan Hajnoczi 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" I/O requests hang after stop/cont commands at least since QEMU 2.10.0 with -drive iops=3D100: (guest)$ dd if=3D/dev/zero of=3D/dev/vdb oflag=3Ddirect count=3D1000 (qemu) stop (qemu) cont ...I/O is stuck... This happens because blk_set_aio_context() detaches the ThrottleState while requests may still be in flight: if (tgm->throttle_state) { throttle_group_detach_aio_context(tgm); throttle_group_attach_aio_context(tgm, new_context); } This patch encloses the detach/attach calls in a drained region so no I/O request is left hanging. Also add assertions so we don't make the same mistake again in the future. Reported-by: Yongxue Hong Signed-off-by: Stefan Hajnoczi Reviewed-by: Alberto Garcia Message-id: 20171110151934.16883-1-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi --- block/block-backend.c | 2 ++ block/throttle-groups.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index 18e543780d..ab75da32c9 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1752,8 +1752,10 @@ void blk_set_aio_context(BlockBackend *blk, AioConte= xt *new_context) =20 if (bs) { if (tgm->throttle_state) { + bdrv_drained_begin(bs); throttle_group_detach_aio_context(tgm); throttle_group_attach_aio_context(tgm, new_context); + bdrv_drained_end(bs); } bdrv_set_aio_context(bs, new_context); } diff --git a/block/throttle-groups.c b/block/throttle-groups.c index b291a88481..2587f19ca3 100644 --- a/block/throttle-groups.c +++ b/block/throttle-groups.c @@ -594,6 +594,12 @@ void throttle_group_attach_aio_context(ThrottleGroupMe= mber *tgm, void throttle_group_detach_aio_context(ThrottleGroupMember *tgm) { ThrottleTimers *tt =3D &tgm->throttle_timers; + + /* Requests must have been drained */ + assert(tgm->pending_reqs[0] =3D=3D 0 && tgm->pending_reqs[1] =3D=3D 0); + assert(qemu_co_queue_empty(&tgm->throttled_reqs[0])); + assert(qemu_co_queue_empty(&tgm->throttled_reqs[1])); + throttle_timers_detach_aio_context(tt); tgm->aio_context =3D NULL; } --=20 2.13.6 From nobody Thu May 2 11:25:52 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 1510656088001832.1536827143475; Tue, 14 Nov 2017 02:41:28 -0800 (PST) Received: from localhost ([::1]:58736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYeW-0004nt-56 for importer@patchew.org; Tue, 14 Nov 2017 05:41:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60513) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYbD-0002T1-5H for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEYbC-0004P6-AM for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52190) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEYbC-0004Oc-47 for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:37:46 -0500 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 420FBA999; Tue, 14 Nov 2017 10:37:45 +0000 (UTC) Received: from localhost (unknown [10.36.118.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51AF2C14B0; Tue, 14 Nov 2017 10:37:41 +0000 (UTC) From: Stefan Hajnoczi To: Date: Tue, 14 Nov 2017 10:37:19 +0000 Message-Id: <20171114103721.13869-4-stefanha@redhat.com> In-Reply-To: <20171114103721.13869-1-stefanha@redhat.com> References: <20171114103721.13869-1-stefanha@redhat.com> 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.25]); Tue, 14 Nov 2017 10:37: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] [PULL for-2.11-rc2 3/5] block: Check for inserted BlockDriverState in blk_io_limits_disable() 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: Peter Maydell , Alberto Garcia , Stefan Hajnoczi 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: Alberto Garcia When you set I/O limits using block_set_io_throttle or the command line throttling.* options they are kept in the BlockBackend regardless of whether a BlockDriverState is attached to the backend or not. Therefore when removing the limits using blk_io_limits_disable() we need to check if there's a BDS before attempting to drain it, else it will crash QEMU. This can be reproduced very easily using HMP: (qemu) drive_add 0 if=3Dnone,throttling.iops-total=3D5000 (qemu) drive_del none0 Reported-by: sochin jiang Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Message-id: 0d3a67ce8d948bb33e08672564714dcfb76a3d8c.1510339534.git.berto@i= galia.com Signed-off-by: Stefan Hajnoczi --- block/block-backend.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index ab75da32c9..df92a6280d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1980,10 +1980,16 @@ void blk_set_io_limits(BlockBackend *blk, ThrottleC= onfig *cfg) =20 void blk_io_limits_disable(BlockBackend *blk) { - assert(blk->public.throttle_group_member.throttle_state); - bdrv_drained_begin(blk_bs(blk)); - throttle_group_unregister_tgm(&blk->public.throttle_group_member); - bdrv_drained_end(blk_bs(blk)); + BlockDriverState *bs =3D blk_bs(blk); + ThrottleGroupMember *tgm =3D &blk->public.throttle_group_member; + assert(tgm->throttle_state); + if (bs) { + bdrv_drained_begin(bs); + } + throttle_group_unregister_tgm(tgm); + if (bs) { + bdrv_drained_end(bs); + } } =20 /* should be called before blk_set_io_limits if a limit is set */ --=20 2.13.6 From nobody Thu May 2 11:25:52 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 1510656057787969.989912691215; Tue, 14 Nov 2017 02:40:57 -0800 (PST) Received: from localhost ([::1]:58735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYeC-0004b2-1O for importer@patchew.org; Tue, 14 Nov 2017 05:40:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60646) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYbV-0002jd-LR for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:38:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEYbS-0004YV-GO for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:38:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEYbS-0004Y1-7B for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:38:02 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 344BFA04F2; Tue, 14 Nov 2017 10:38:01 +0000 (UTC) Received: from localhost (unknown [10.36.118.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EEAE8B162; Tue, 14 Nov 2017 10:37:46 +0000 (UTC) From: Stefan Hajnoczi To: Date: Tue, 14 Nov 2017 10:37:20 +0000 Message-Id: <20171114103721.13869-5-stefanha@redhat.com> In-Reply-To: <20171114103721.13869-1-stefanha@redhat.com> References: <20171114103721.13869-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 14 Nov 2017 10:38:01 +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] [PULL for-2.11-rc2 4/5] block: Leave valid throttle timers when removing a BDS from a backend 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: Peter Maydell , Alberto Garcia , Stefan Hajnoczi 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" From: Alberto Garcia If a BlockBackend has I/O limits set then its ThrottleGroupMember structure uses the AioContext from its attached BlockDriverState. Those two contexts must be kept in sync manually. This is not ideal and will be fixed in the future by removing the throttling configuration from the BlockBackend and storing it in an implicit filter node instead, but for now we have to live with this. When you remove the BlockDriverState from the backend then the throttle timers are destroyed. If a new BlockDriverState is later inserted then they are created again using the new AioContext. There are a couple of problems with this: a) The code manipulates the timers directly, leaving the ThrottleGroupMember.aio_context field in an inconsisent state. b) If you remove the I/O limits (e.g by destroying the backend) when the timers are gone then throttle_group_unregister_tgm() will attempt to destroy them again, crashing QEMU. While b) could be fixed easily by allowing the timers to be freed twice, this would result in a situation in which we can no longer guarantee that a valid ThrottleState has a valid AioContext and timers. This patch ensures that the timers and AioContext are always valid when I/O limits are set, regardless of whether the BlockBackend has a BlockDriverState inserted or not. [Fixed "There'a" typo as suggested by Max Reitz --Stefan] Reported-by: sochin jiang Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Message-id: e089c66e7c20289b046d782cea4373b765c5bc1d.1510339534.git.berto@i= galia.com Signed-off-by: Stefan Hajnoczi --- block/block-backend.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index df92a6280d..f10b1db612 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -655,15 +655,15 @@ BlockBackend *blk_by_public(BlockBackendPublic *publi= c) */ void blk_remove_bs(BlockBackend *blk) { + ThrottleGroupMember *tgm =3D &blk->public.throttle_group_member; BlockDriverState *bs; - ThrottleTimers *tt; =20 notifier_list_notify(&blk->remove_bs_notifiers, blk); - if (blk->public.throttle_group_member.throttle_state) { - tt =3D &blk->public.throttle_group_member.throttle_timers; + if (tgm->throttle_state) { bs =3D blk_bs(blk); bdrv_drained_begin(bs); - throttle_timers_detach_aio_context(tt); + throttle_group_detach_aio_context(tgm); + throttle_group_attach_aio_context(tgm, qemu_get_aio_context()); bdrv_drained_end(bs); } =20 @@ -678,6 +678,7 @@ void blk_remove_bs(BlockBackend *blk) */ int blk_insert_bs(BlockBackend *blk, BlockDriverState *bs, Error **errp) { + ThrottleGroupMember *tgm =3D &blk->public.throttle_group_member; blk->root =3D bdrv_root_attach_child(bs, "root", &child_root, blk->perm, blk->shared_perm, blk, e= rrp); if (blk->root =3D=3D NULL) { @@ -686,10 +687,9 @@ int blk_insert_bs(BlockBackend *blk, BlockDriverState = *bs, Error **errp) bdrv_ref(bs); =20 notifier_list_notify(&blk->insert_bs_notifiers, blk); - if (blk->public.throttle_group_member.throttle_state) { - throttle_timers_attach_aio_context( - &blk->public.throttle_group_member.throttle_timers, - bdrv_get_aio_context(bs)); + if (tgm->throttle_state) { + throttle_group_detach_aio_context(tgm); + throttle_group_attach_aio_context(tgm, bdrv_get_aio_context(bs)); } =20 return 0; --=20 2.13.6 From nobody Thu May 2 11:25:52 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 1510656151830194.5334404576463; Tue, 14 Nov 2017 02:42:31 -0800 (PST) Received: from localhost ([::1]:58739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYfY-0005Zx-2U for importer@patchew.org; Tue, 14 Nov 2017 05:42:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60676) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eEYbX-0002ku-7w for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:38:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eEYbW-0004b2-1m for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:38:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eEYbV-0004a4-OU for qemu-devel@nongnu.org; Tue, 14 Nov 2017 05:38:05 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7E082C7D2; Tue, 14 Nov 2017 10:38:04 +0000 (UTC) Received: from localhost (unknown [10.36.118.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id CCD768B164; Tue, 14 Nov 2017 10:38:02 +0000 (UTC) From: Stefan Hajnoczi To: Date: Tue, 14 Nov 2017 10:37:21 +0000 Message-Id: <20171114103721.13869-6-stefanha@redhat.com> In-Reply-To: <20171114103721.13869-1-stefanha@redhat.com> References: <20171114103721.13869-1-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 14 Nov 2017 10:38:04 +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] [PULL for-2.11-rc2 5/5] qemu-iotests: Test I/O limits with removable media 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: Peter Maydell , Alberto Garcia , Stefan Hajnoczi 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: Alberto Garcia This test hotplugs a CD drive to a VM and checks that I/O limits can be set only when the drive has media inserted and that they are kept when the media is replaced. This also tests the removal of a device with valid I/O limits set but no media inserted. This involves deleting and disabling the limits of a BlockBackend without BlockDriverState, a scenario that has been crashing until the fixes from the last couple of patches. [Python PEP8 fixup: "Don't use spaces are the =3D sign when used to indicate a keyword argument or a default parameter value" --Stefan] Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz Message-id: 071eb397118ed207c5a7f01d58766e415ee18d6a.1510339534.git.berto@i= galia.com Signed-off-by: Stefan Hajnoczi --- tests/qemu-iotests/093 | 62 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/093.out | 4 +-- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/093 b/tests/qemu-iotests/093 index ef3997206b..5c36a5fb4d 100755 --- a/tests/qemu-iotests/093 +++ b/tests/qemu-iotests/093 @@ -308,6 +308,68 @@ class ThrottleTestGroupNames(iotests.QMPTestCase): groupname =3D "group%d" % i self.verify_name(devname, groupname) =20 +class ThrottleTestRemovableMedia(iotests.QMPTestCase): + def setUp(self): + self.vm =3D iotests.VM() + if iotests.qemu_default_machine =3D=3D 's390-ccw-virtio': + self.vm.add_device("virtio-scsi-ccw,id=3Dvirtio-scsi") + else: + self.vm.add_device("virtio-scsi-pci,id=3Dvirtio-scsi") + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + + def test_removable_media(self): + # Add a couple of dummy nodes named cd0 and cd1 + result =3D self.vm.qmp("blockdev-add", driver=3D"null-aio", + node_name=3D"cd0") + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp("blockdev-add", driver=3D"null-aio", + node_name=3D"cd1") + self.assert_qmp(result, 'return', {}) + + # Attach a CD drive with cd0 inserted + result =3D self.vm.qmp("device_add", driver=3D"scsi-cd", + id=3D"dev0", drive=3D"cd0") + self.assert_qmp(result, 'return', {}) + + # Set I/O limits + args =3D { "id": "dev0", "iops": 100, "iops_rd": 0, "iops_wr": 0, + "bps": 50, "bps_rd": 0, "bps_wr": 0 } + result =3D self.vm.qmp("block_set_io_throttle", conv_keys=3DFalse,= **args) + self.assert_qmp(result, 'return', {}) + + # Check that the I/O limits have been set + result =3D self.vm.qmp("query-block") + self.assert_qmp(result, 'return[0]/inserted/iops', 100) + self.assert_qmp(result, 'return[0]/inserted/bps', 50) + + # Now eject cd0 and insert cd1 + result =3D self.vm.qmp("blockdev-open-tray", id=3D'dev0') + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp("x-blockdev-remove-medium", id=3D'dev0') + self.assert_qmp(result, 'return', {}) + result =3D self.vm.qmp("x-blockdev-insert-medium", id=3D'dev0', no= de_name=3D'cd1') + self.assert_qmp(result, 'return', {}) + + # Check that the I/O limits are still the same + result =3D self.vm.qmp("query-block") + self.assert_qmp(result, 'return[0]/inserted/iops', 100) + self.assert_qmp(result, 'return[0]/inserted/bps', 50) + + # Eject cd1 + result =3D self.vm.qmp("x-blockdev-remove-medium", id=3D'dev0') + self.assert_qmp(result, 'return', {}) + + # Check that we can't set limits if the device has no medium + result =3D self.vm.qmp("block_set_io_throttle", conv_keys=3DFalse,= **args) + self.assert_qmp(result, 'error/class', 'GenericError') + + # Remove the CD drive + result =3D self.vm.qmp("device_del", id=3D'dev0') + self.assert_qmp(result, 'return', {}) + =20 if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D["raw"]) diff --git a/tests/qemu-iotests/093.out b/tests/qemu-iotests/093.out index 2f7d3902f2..594c16f49f 100644 --- a/tests/qemu-iotests/093.out +++ b/tests/qemu-iotests/093.out @@ -1,5 +1,5 @@ -....... +........ ---------------------------------------------------------------------- -Ran 7 tests +Ran 8 tests =20 OK --=20 2.13.6