From nobody Sun May 5 05:32:38 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; dkim=fail; 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 1510340222886706.1356441436657; Fri, 10 Nov 2017 10:57:02 -0800 (PST) Received: from localhost ([::1]:43078 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDEU5-0001v8-SE for importer@patchew.org; Fri, 10 Nov 2017 13:56:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDESO-0000m5-SA for qemu-devel@nongnu.org; Fri, 10 Nov 2017 13:55:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDESK-0001sw-V6 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 13:55:12 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56033) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eDESK-0001rB-Hi; Fri, 10 Nov 2017 13:55:08 -0500 Received: from a88-114-101-76.elisa-laajakaista.fi ([88.114.101.76] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1eDESG-0000sY-Oo; Fri, 10 Nov 2017 19:55:04 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eDES3-0004PR-3j; Fri, 10 Nov 2017 20:54:51 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=aIzwfQt+IbN4QTONgimZ5hNlmghFLAuGJvb0PiETn74=; b=doA+4wDPnyUx+5sIfoOEDP5RKno+e+kFPRXPQiqBusnn3RxTpFD/pdImcLkNX2spN5kcjLOgcRgNLMYDMKf9YayhujI48lYdRuotoKV9gdJdjYC1Smac2pj2c+U/+8wDpm3N1MBMWr4hft/NRO/ih2q+CLEIgd82rpH33mG04vd60xm+V5XZLRvgXbo8SbuHYBpmYjANJCrcKrd54AFABm6eRS1A0lko8vC/IU2AlWwvhdHNNByVi7gy7zwWS6FmRNYox3skNbe34fwzAtzjbLqFAZ6NOOlO0tpAvuaeEu0TrYJeMqJLTAWAcaoqbtDmyNbTg731tVpwF45sRuJgpA==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 10 Nov 2017 20:54:46 +0200 Message-Id: <0d3a67ce8d948bb33e08672564714dcfb76a3d8c.1510339534.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 1/3] 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: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , sochin jiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 18e543780d..193a080096 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1978,10 +1978,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.11.0 From nobody Sun May 5 05:32:38 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; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510340351707897.7061923918935; Fri, 10 Nov 2017 10:59:11 -0800 (PST) Received: from localhost ([::1]:43084 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDEVw-0003bz-Ml for importer@patchew.org; Fri, 10 Nov 2017 13:58:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDESO-0000m7-Si for qemu-devel@nongnu.org; Fri, 10 Nov 2017 13:55:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDESK-0001t1-Vg for qemu-devel@nongnu.org; Fri, 10 Nov 2017 13:55:12 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56037) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eDESK-0001r9-Hn; Fri, 10 Nov 2017 13:55:08 -0500 Received: from a88-114-101-76.elisa-laajakaista.fi ([88.114.101.76] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1eDESG-0000sW-Hb; Fri, 10 Nov 2017 19:55:04 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eDES3-0004PT-59; Fri, 10 Nov 2017 20:54:51 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=nzcW8tZCCtnjfCpI/Op9g1owXzLVv3zPg6oMivsQIkw=; b=GBRUBCx8AOaiNrIrsV1EapB8+PWKJbmuvk3uW/1OlNEc+Pu5zpos1RdIQ3MAFf/vZi9JWsjfzRW5PJ8M3xL/Ca6pLkFvnpvwMSCffSpx0eBtZS4E2FXxgWCiUQpPZmEPOdwwamgoj7QKbeEq7J/MppYC/VKtaHje0VuUHx/tqZmHHmiEfQsYrcOOp3n/yN6QQ/k+/7M+UJu6PV6qLbNP1AsCgPBCR6ueqN8wME5ut8FpmS67QkVzdUcaBk0nv/ui9kBR/qOsImHBQ7BNduqeMu1tOSfzfT9cIuAPLd1bWIN5LNseMLfJV6f2yP+djytYmiZsvFC8wsMFgzH2FTUgbw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 10 Nov 2017 20:54:47 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 2/3] 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: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , sochin jiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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'a 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. Reported-by: sochin jiang Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- 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 193a080096..38db6e639b 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.11.0 From nobody Sun May 5 05:32:38 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; dkim=fail; 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 1510340442982439.91699488183474; Fri, 10 Nov 2017 11:00:42 -0800 (PST) Received: from localhost ([::1]:43092 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDEXZ-0004on-5R for importer@patchew.org; Fri, 10 Nov 2017 14:00:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36877) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDESO-0000m9-TL for qemu-devel@nongnu.org; Fri, 10 Nov 2017 13:55:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDESK-0001t6-W6 for qemu-devel@nongnu.org; Fri, 10 Nov 2017 13:55:12 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56031) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eDESK-0001rA-Hh; Fri, 10 Nov 2017 13:55:08 -0500 Received: from a88-114-101-76.elisa-laajakaista.fi ([88.114.101.76] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1eDESG-0000sZ-QQ; Fri, 10 Nov 2017 19:55:04 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1eDES3-0004PV-7H; Fri, 10 Nov 2017 20:54:51 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=oQnpi2fxKsJuc5rc5TbTmIFO+k0SBTpKxbltTvbxvcw=; b=d0/P9bWb0kQ3vCIflAA/8CMgtOPIo2JeBgNA7maR2+wT5cHUo01XDj8KFCJVX13RAjkJOcxgNT6YdWpt+N4efQNq6sFHJecLPUtHSNEWB889aHACKnpIQi4TdDovGFtVI5vfcMRg044liUNl833ea+B3QOls8Omyo3S8tolATYgV+Af3eS4wJY9H0HBknG3JBNBwHQsy+7+bVhAARCOwKn76ZD34mf9ymxwlJQi8k4+SsC/OjJwKvIPkgNOPRit52uOqXAviSXpwB5gtUNz9k1MFZejKC8uxPa2F84r6cJiS8MVxKSq9q5DhE922oJhmCLbbKv/xIRn+oJO00VTLmg==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 10 Nov 2017 20:54:48 +0200 Message-Id: <071eb397118ed207c5a7f01d58766e415ee18d6a.1510339534.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH 3/3] 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: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , sochin jiang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- 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..7862f2ba94 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 =3D Fals= e, **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', = node_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 =3D Fals= e, **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.11.0