From nobody Mon May 6 21:54:06 2024 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=1565948407; cv=none; d=zoho.com; s=zohoarc; b=E75GjWT8zbooh/gNxdlwn5pAIHII313dwi4qlSNAY5MywLqHEHu6mRshaUlOSgT8o+Du6/zUBR3Cu47obVmGi/r3DM1qOzXx4wCfCTXnandLqs1ys9y4TnKB3ZHiz0o3d62ZWtBfOMSsjuy8lSWsfHj+zcfekGEZwBbFZfyzvjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948407; 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=W55sZ/06TZHRTsRzxkqwn9OaYgk51YjGSQ8g8rXH8DQ=; b=d5Fr0K952/qgmuXheoBY5X5R7ORlhxvZP4kW+Nrj99KY05YFz2wDMhIklLA+WODqALUyUsK8pRUxbwjTUaTzP0/OGk6Dpd44RMBQ84/UH/tQFI38eQwimvJvtpPW6O27IoO4gHYKufwaIRPCVTPkbYIdrirPtE4IUWvVJ81bVSk= 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 1565948407225836.3416350596829; Fri, 16 Aug 2019 02:40:07 -0700 (PDT) Received: from localhost ([::1]:52518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYiE-0005ag-LW for importer@patchew.org; Fri, 16 Aug 2019 05:39:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59382) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdI-0008Gp-L7 for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdH-0003Yn-F6 for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40722) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdD-0003QP-9S; Fri, 16 Aug 2019 05:34:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3570B7FDE5; Fri, 16 Aug 2019 09:34:45 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 700595C1D6; Fri, 16 Aug 2019 09:34:44 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:24 +0200 Message-Id: <20190816093439.14262-2-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 16 Aug 2019 09:34:45 +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] [PULL 01/16] iotests/118: Test media change for scsi-cd 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The test covered only floppy and ide-cd. Add scsi-cd as well. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/118 | 20 ++++++++++++++++++++ tests/qemu-iotests/118.out | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118 index 499c5f0901..3c20d2d61f 100755 --- a/tests/qemu-iotests/118 +++ b/tests/qemu-iotests/118 @@ -33,6 +33,8 @@ def interface_to_device_name(interface): return 'ide-cd' elif interface =3D=3D 'floppy': return 'floppy' + elif interface =3D=3D 'scsi': + return 'scsi-cd' else: return None =20 @@ -297,6 +299,8 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass): qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') self.vm =3D iotests.VM() self.vm.add_drive(old_img, 'media=3D%s' % media, 'none') + if interface =3D=3D 'scsi': + self.vm.add_device('virtio-scsi-pci') self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % (interface_to_device_name(interface), self.device_name)) @@ -330,6 +334,8 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass): def setUp(self, media, interface): qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') self.vm =3D iotests.VM().add_drive(None, 'media=3D%s' % media, 'no= ne') + if interface =3D=3D 'scsi': + self.vm.add_device('virtio-scsi-pci') self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % (interface_to_device_name(interface), self.device_name)) @@ -363,6 +369,20 @@ class TestCDInitiallyEmpty(TestInitiallyEmpty): def setUp(self): self.TestInitiallyEmpty.setUp(self, 'cdrom', 'ide') =20 +class TestSCSICDInitiallyFilled(TestInitiallyFilled): + TestInitiallyFilled =3D TestInitiallyFilled + has_real_tray =3D True + + def setUp(self): + self.TestInitiallyFilled.setUp(self, 'cdrom', 'scsi') + +class TestSCSICDInitiallyEmpty(TestInitiallyEmpty): + TestInitiallyEmpty =3D TestInitiallyEmpty + has_real_tray =3D True + + def setUp(self): + self.TestInitiallyEmpty.setUp(self, 'cdrom', 'scsi') + class TestFloppyInitiallyFilled(TestInitiallyFilled): TestInitiallyFilled =3D TestInitiallyFilled has_real_tray =3D False diff --git a/tests/qemu-iotests/118.out b/tests/qemu-iotests/118.out index 4823c113d5..b4ff997a8c 100644 --- a/tests/qemu-iotests/118.out +++ b/tests/qemu-iotests/118.out @@ -1,5 +1,5 @@ -............................................................... +..........................................................................= ............... ---------------------------------------------------------------------- -Ran 63 tests +Ran 89 tests =20 OK --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948273; cv=none; d=zoho.com; s=zohoarc; b=lM8QZafi+sdVkNM+9Zg3tz2OwukPlVvwH6zhjYBSjzbSExXfAzJylKY0o4D080GlLOzUhbKSqZjO7dZU2POB4uigosn4RH4HYAvf38/WzgKvyGLLlYqBYVccaHBYAK4Bh/oiTXMvqqFXASNFvXnvvS1L0TZivqnoi03JP4vFWdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948273; 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=AvJR0F50Zo0H216KDBfgYb7ST4j5/iQ0JBTu4T9GfPk=; b=ZmaEFIZkXJZ4D0jburJzPNBz9fDPoQ+XiY4M9xgGfqQqjDWwjNikiGU5lUccqgjvaD510urHwsdpfgDY/73jEOr54z4PpE0MyvO9+0vNIXQpvAyyEmMypw5a4lgj6FH7579A01hho097l9IADlsz0MVWSYKBAfp7UYjw6LEGJ8o= 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 1565948273902267.0421752044464; Fri, 16 Aug 2019 02:37:53 -0700 (PDT) Received: from localhost ([::1]:52488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYgC-0002W4-7h for importer@patchew.org; Fri, 16 Aug 2019 05:37:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59427) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdJ-0008IE-KF for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdH-0003ZM-W7 for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdD-0003U8-Af; Fri, 16 Aug 2019 05:34:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BCA23082133; Fri, 16 Aug 2019 09:34:46 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76AB75C1D6; Fri, 16 Aug 2019 09:34:45 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:25 +0200 Message-Id: <20190816093439.14262-3-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 16 Aug 2019 09:34:46 +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] [PULL 02/16] iotests/118: Create test classes dynamically 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We're getting a ridiculous number of child classes of TestInitiallyFilled and TestInitiallyEmpty that differ only in a few attributes that we want to test in all combinations. Instead of explicitly writing down every combination, let's use a loop and create those classes dynamically. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/118 | 69 +++++++++++++----------------------------- 1 file changed, 21 insertions(+), 48 deletions(-) diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118 index 3c20d2d61f..c281259215 100755 --- a/tests/qemu-iotests/118 +++ b/tests/qemu-iotests/118 @@ -294,15 +294,15 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass): class TestInitiallyFilled(GeneralChangeTestsBaseClass): was_empty =3D False =20 - def setUp(self, media, interface): + def setUp(self): qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k') qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') self.vm =3D iotests.VM() - self.vm.add_drive(old_img, 'media=3D%s' % media, 'none') - if interface =3D=3D 'scsi': + self.vm.add_drive(old_img, 'media=3D%s' % self.media, 'none') + if self.interface =3D=3D 'scsi': self.vm.add_device('virtio-scsi-pci') self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % - (interface_to_device_name(interface), + (interface_to_device_name(self.interface), self.device_name)) self.vm.launch() =20 @@ -331,13 +331,13 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass= ): class TestInitiallyEmpty(GeneralChangeTestsBaseClass): was_empty =3D True =20 - def setUp(self, media, interface): + def setUp(self): qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') - self.vm =3D iotests.VM().add_drive(None, 'media=3D%s' % media, 'no= ne') - if interface =3D=3D 'scsi': + self.vm =3D iotests.VM().add_drive(None, 'media=3D%s' % self.media= , 'none') + if self.interface =3D=3D 'scsi': self.vm.add_device('virtio-scsi-pci') self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % - (interface_to_device_name(interface), + (interface_to_device_name(self.interface), self.device_name)) self.vm.launch() =20 @@ -355,50 +355,23 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass): # Should be a no-op self.assert_qmp(result, 'return', {}) =20 -class TestCDInitiallyFilled(TestInitiallyFilled): - TestInitiallyFilled =3D TestInitiallyFilled - has_real_tray =3D True - - def setUp(self): - self.TestInitiallyFilled.setUp(self, 'cdrom', 'ide') - -class TestCDInitiallyEmpty(TestInitiallyEmpty): - TestInitiallyEmpty =3D TestInitiallyEmpty - has_real_tray =3D True - - def setUp(self): - self.TestInitiallyEmpty.setUp(self, 'cdrom', 'ide') +# Do this in a function to avoid leaking variables like case into the glob= al +# name space (otherwise tests would be run for the abstract base classes) +def create_basic_test_classes(): + for (media, interface, has_real_tray) in [ ('cdrom', 'ide', True), + ('cdrom', 'scsi', True), + ('disk', 'floppy', False) ]: =20 -class TestSCSICDInitiallyFilled(TestInitiallyFilled): - TestInitiallyFilled =3D TestInitiallyFilled - has_real_tray =3D True + for case in [ TestInitiallyFilled, TestInitiallyEmpty ]: =20 - def setUp(self): - self.TestInitiallyFilled.setUp(self, 'cdrom', 'scsi') + attr =3D { 'media': media, + 'interface': interface, + 'has_real_tray': has_real_tray } =20 -class TestSCSICDInitiallyEmpty(TestInitiallyEmpty): - TestInitiallyEmpty =3D TestInitiallyEmpty - has_real_tray =3D True + name =3D '%s_%s_%s' % (case.__name__, media, interface) + globals()[name] =3D type(name, (case, ), attr) =20 - def setUp(self): - self.TestInitiallyEmpty.setUp(self, 'cdrom', 'scsi') - -class TestFloppyInitiallyFilled(TestInitiallyFilled): - TestInitiallyFilled =3D TestInitiallyFilled - has_real_tray =3D False - - def setUp(self): - self.TestInitiallyFilled.setUp(self, 'disk', 'floppy') - -class TestFloppyInitiallyEmpty(TestInitiallyEmpty): - TestInitiallyEmpty =3D TestInitiallyEmpty - has_real_tray =3D False - - def setUp(self): - self.TestInitiallyEmpty.setUp(self, 'disk', 'floppy') - # FDDs not having a real tray and there not being a medium inside = the - # tray at startup means the tray will be considered open - self.has_opened =3D True +create_basic_test_classes() =20 class TestChangeReadOnly(ChangeBaseClass): device_name =3D 'qdev0' --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948294; cv=none; d=zoho.com; s=zohoarc; b=T2JWDn3Uzcpw/ln7MZ5QvYiSwoOcgu8JAgacqCps+sBIFy2Pw+7GaSoI0Te1Dvoy5LWU4oS5nKs9fUqxWiL5Iits+S1w1mSQ1n6gV+MnWefaMTd9ulJXn3/8hNYvr/YaOqQsEyO7PrTrtMk6idSdH0T+a0mpoQwjDIRzIOuMBJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948294; 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=3iv6b3iyRD425na6cP6HVt9BW2R6TKTIVLEBvPXVjUI=; b=UcmdCAgDIVqeCVnP6KKK49TNP/3D4cA6qOEWfnY4kcyWZTYEBK98RYtxWCWiMBljn5OTRX2R2nGu7e7CgAYItb7jk0Y2ixtGfYTfvxE+57tOXS1FLn4f/sQD5duXlQEnXQsBIOnoYYaWcZ5EAPLOq1v7ct/gcfZ2Jo0B98MqT0Y= 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 1565948294229800.9850715056348; Fri, 16 Aug 2019 02:38:14 -0700 (PDT) Received: from localhost ([::1]:52490 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYgW-00035X-Na for importer@patchew.org; Fri, 16 Aug 2019 05:38:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59431) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdJ-0008Ia-St for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdI-0003a3-DK for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdF-0003VR-7u; Fri, 16 Aug 2019 05:34:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44D0B4ACA7; Fri, 16 Aug 2019 09:34:47 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E1EF5C1D6; Fri, 16 Aug 2019 09:34:46 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:26 +0200 Message-Id: <20190816093439.14262-4-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 16 Aug 2019 09:34:47 +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] [PULL 03/16] iotests/118: Add -blockdev based tests 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The code path for -device drive=3D or without a drive=3D... option for empty drives, which is supposed to be used with -blockdev differs enough from the -drive based path with a user-owned BlockBackend, so we want to test both paths at least for the basic tests implemented by TestInitiallyFilled and TestInitiallyEmpty. This would have caught the bug recently fixed for inserting read-only nodes into a scsi-cd created without a drive=3D... option. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/118 | 43 ++++++++++++++++++++++++++------------ tests/qemu-iotests/118.out | 4 ++-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118 index c281259215..6f45779ee9 100755 --- a/tests/qemu-iotests/118 +++ b/tests/qemu-iotests/118 @@ -42,10 +42,14 @@ class ChangeBaseClass(iotests.QMPTestCase): has_opened =3D False has_closed =3D False =20 + device_name =3D 'qdev0' + use_drive =3D False + def process_events(self): for event in self.vm.get_qmp_events(wait=3DFalse): if (event['event'] =3D=3D 'DEVICE_TRAY_MOVED' and - event['data']['device'] =3D=3D 'drive0'): + (event['data']['device'] =3D=3D 'drive0' or + event['data']['id'] =3D=3D self.device_name)): if event['data']['tray-open'] =3D=3D False: self.has_closed =3D True else: @@ -69,9 +73,11 @@ class ChangeBaseClass(iotests.QMPTestCase): =20 class GeneralChangeTestsBaseClass(ChangeBaseClass): =20 - device_name =3D 'qdev0' - def test_change(self): + # 'change' requires a drive name, so skip the test for blockdev + if not self.use_drive: + return + result =3D self.vm.qmp('change', device=3D'drive0', target=3Dnew_i= mg, arg=3Diotests.imgfmt) self.assert_qmp(result, 'return', {}) @@ -298,7 +304,13 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass): qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k') qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') self.vm =3D iotests.VM() - self.vm.add_drive(old_img, 'media=3D%s' % self.media, 'none') + if self.use_drive: + self.vm.add_drive(old_img, 'media=3D%s' % self.media, 'none') + else: + self.vm.add_blockdev([ 'node-name=3Ddrive0', + 'driver=3D%s' % iotests.imgfmt, + 'file.driver=3Dfile', + 'file.filename=3D%s' % old_img ]) if self.interface =3D=3D 'scsi': self.vm.add_device('virtio-scsi-pci') self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % @@ -333,11 +345,14 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass): =20 def setUp(self): qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k') - self.vm =3D iotests.VM().add_drive(None, 'media=3D%s' % self.media= , 'none') + self.vm =3D iotests.VM() + if self.use_drive: + self.vm.add_drive(None, 'media=3D%s' % self.media, 'none') if self.interface =3D=3D 'scsi': self.vm.add_device('virtio-scsi-pci') - self.vm.add_device('%s,drive=3Ddrive0,id=3D%s' % + self.vm.add_device('%s,%sid=3D%s' % (interface_to_device_name(self.interface), + 'drive=3Ddrive0,' if self.use_drive else '', self.device_name)) self.vm.launch() =20 @@ -363,13 +378,15 @@ def create_basic_test_classes(): ('disk', 'floppy', False) ]: =20 for case in [ TestInitiallyFilled, TestInitiallyEmpty ]: - - attr =3D { 'media': media, - 'interface': interface, - 'has_real_tray': has_real_tray } - - name =3D '%s_%s_%s' % (case.__name__, media, interface) - globals()[name] =3D type(name, (case, ), attr) + for use_drive in [ True, False ]: + attr =3D { 'media': media, + 'interface': interface, + 'has_real_tray': has_real_tray, + 'use_drive': use_drive } + + name =3D '%s_%s_%s_%s' % (case.__name__, media, interface, + 'drive' if use_drive else 'blockde= v') + globals()[name] =3D type(name, (case, ), attr) =20 create_basic_test_classes() =20 diff --git a/tests/qemu-iotests/118.out b/tests/qemu-iotests/118.out index b4ff997a8c..bf5bfd5aca 100644 --- a/tests/qemu-iotests/118.out +++ b/tests/qemu-iotests/118.out @@ -1,5 +1,5 @@ -..........................................................................= ............... +..........................................................................= ...........................................................................= .................. ---------------------------------------------------------------------- -Ran 89 tests +Ran 167 tests =20 OK --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948270; cv=none; d=zoho.com; s=zohoarc; b=lwdIPn1NqntN4m8Q9Z8wWFnHyzChMeRpaGY+rPDTinLacDF5riJWNcpeWCAMTU8LLLjmpxTmPmhg2A6iQjQVNci3EpOKgd1KSL1UEznNdecpxpHaN8zzc+9I14ZHpwEmnC4a/JpgzkGqgrogEkVqvwLimq24MLyulGQ+BLMTkhA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948270; 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=qgpdCf8IA8ZiLCoxR/1aX23P2OQ86hN5fYczRnNoSGI=; b=cnvcf8GG+vFzh/i1QyjOcIu7CCvkOJ7rj9jxKDlL9lqVsanPLXFNuhy461OqBy28xG7yEWQDogBRtJ46Z7Q8C5cpxjriW87a7JLAv5HJW9qwzjItQBSg+2obqCq3974CCYnx+h3+3J2CBzzF5xnqYkh5pxCbWQo882Ojq8layUo= 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 1565948270306435.02890154253885; Fri, 16 Aug 2019 02:37:50 -0700 (PDT) Received: from localhost ([::1]:52486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYg8-0002Nm-K3 for importer@patchew.org; Fri, 16 Aug 2019 05:37:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59425) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdJ-0008IA-IQ for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdI-0003ZU-3E for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37464) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdF-0003Vz-8h; Fri, 16 Aug 2019 05:34:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C80F86D; Fri, 16 Aug 2019 09:34:48 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 849D55C1D6; Fri, 16 Aug 2019 09:34:47 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:27 +0200 Message-Id: <20190816093439.14262-5-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 16 Aug 2019 09:34:48 +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] [PULL 04/16] iotests: Move migration helpers to iotests.py 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 234 implements functions that are useful for doing migration between two VMs. Move them to iotests.py so that other test cases can use them, too. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/234 | 30 +++++++----------------------- tests/qemu-iotests/iotests.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/qemu-iotests/234 b/tests/qemu-iotests/234 index c4c26bc21e..34c818c485 100755 --- a/tests/qemu-iotests/234 +++ b/tests/qemu-iotests/234 @@ -26,22 +26,6 @@ import os iotests.verify_image_format(supported_fmts=3D['qcow2']) iotests.verify_platform(['linux']) =20 -def enable_migration_events(vm, name): - iotests.log('Enabling migration QMP events on %s...' % name) - iotests.log(vm.qmp('migrate-set-capabilities', capabilities=3D[ - { - 'capability': 'events', - 'state': True - } - ])) - -def wait_migration(vm): - while True: - event =3D vm.event_wait('MIGRATION') - iotests.log(event, filters=3D[iotests.filter_qmp_event]) - if event['data']['status'] =3D=3D 'completed': - break - with iotests.FilePath('img') as img_path, \ iotests.FilePath('backing') as backing_path, \ iotests.FilePath('mig_fifo_a') as fifo_a, \ @@ -62,7 +46,7 @@ with iotests.FilePath('img') as img_path, \ .add_blockdev('%s,file=3Ddrive0-backing-file,node-name=3Ddrive0-b= acking' % (iotests.imgfmt)) .launch()) =20 - enable_migration_events(vm_a, 'A') + vm_a.enable_migration_events('A') =20 iotests.log('Launching destination VM...') (vm_b.add_blockdev('file,filename=3D%s,node-name=3Ddrive0-file' % (img= _path)) @@ -72,7 +56,7 @@ with iotests.FilePath('img') as img_path, \ .add_incoming("exec: cat '%s'" % (fifo_a)) .launch()) =20 - enable_migration_events(vm_b, 'B') + vm_b.enable_migration_events('B') =20 # Add a child node that was created after the parent node. The reverse= case # is covered by the -blockdev options above. @@ -85,9 +69,9 @@ with iotests.FilePath('img') as img_path, \ iotests.log(vm_a.qmp('migrate', uri=3D'exec:cat >%s' % (fifo_a))) with iotests.Timeout(3, 'Migration does not complete'): # Wait for the source first (which includes setup=3Dsetup) - wait_migration(vm_a) + vm_a.wait_migration() # Wait for the destination second (which does not) - wait_migration(vm_b) + vm_b.wait_migration() =20 iotests.log(vm_a.qmp('query-migrate')['return']['status']) iotests.log(vm_b.qmp('query-migrate')['return']['status']) @@ -105,7 +89,7 @@ with iotests.FilePath('img') as img_path, \ .add_incoming("exec: cat '%s'" % (fifo_b)) .launch()) =20 - enable_migration_events(vm_a, 'A') + vm_a.enable_migration_events('A') =20 iotests.log(vm_a.qmp('blockdev-snapshot', node=3D'drive0-backing', overlay=3D'drive0')) @@ -114,9 +98,9 @@ with iotests.FilePath('img') as img_path, \ iotests.log(vm_b.qmp('migrate', uri=3D'exec:cat >%s' % (fifo_b))) with iotests.Timeout(3, 'Migration does not complete'): # Wait for the source first (which includes setup=3Dsetup) - wait_migration(vm_b) + vm_b.wait_migration() # Wait for the destination second (which does not) - wait_migration(vm_a) + vm_a.wait_migration() =20 iotests.log(vm_a.qmp('query-migrate')['return']['status']) iotests.log(vm_b.qmp('query-migrate')['return']['status']) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index ce74177ab1..91172c39a5 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -583,6 +583,22 @@ class VM(qtest.QEMUQtestMachine): elif status =3D=3D 'null': return error =20 + def enable_migration_events(self, name): + log('Enabling migration QMP events on %s...' % name) + log(self.qmp('migrate-set-capabilities', capabilities=3D[ + { + 'capability': 'events', + 'state': True + } + ])) + + def wait_migration(self): + while True: + event =3D self.event_wait('MIGRATION') + log(event, filters=3D[filter_qmp_event]) + if event['data']['status'] =3D=3D 'completed': + break + def node_info(self, node_name): nodes =3D self.qmp('query-named-block-nodes') for x in nodes['return']: --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948728; cv=none; d=zoho.com; s=zohoarc; b=O6QTvieNZPX0mx7AzyY2FCSPkz8HXAUqpqCAfIf46tQnfkO3gKjwYpiApVEOHXZrKFIPEl7NeV/y/g85N+CzVXSBI3+7Hn25mjaOaoondpFfgRF7j4I9M5t8S67T1EgcpeR0wEZn6HhzWFWglSDnj1GSc6imtO803/X1XzbF2mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948728; 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=Dh6hWY2xQzlfBcBx74HXT3dz6knjXvTU+KMTDLGjai4=; b=Pby+L75RhgJg8TAw6Pyj+FRdO1rHXFuuAXwWFq3BSruly7KoejbSdHwcH0Y6ef9xSTaAie35cWxMpnqF+I8mMPeSyZCvwOAfNg+e1qWPojU5k1uNIeGUz+zfdckeWNJcl2aooNYO5vgPxRCILUVQVYGdEtaHvvsv42pqvC7avLI= 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 1565948728990759.512786224532; Fri, 16 Aug 2019 02:45:28 -0700 (PDT) Received: from localhost ([::1]:52598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYnU-0003Yq-OI for importer@patchew.org; Fri, 16 Aug 2019 05:45:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59479) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdL-0008Kw-Ba for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdJ-0003ao-Ch for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdF-0003Wa-W8; Fri, 16 Aug 2019 05:34:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 506C73082B40; Fri, 16 Aug 2019 09:34:49 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BD575C1B2; Fri, 16 Aug 2019 09:34:48 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:28 +0200 Message-Id: <20190816093439.14262-6-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 16 Aug 2019 09:34:49 +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] [PULL 05/16] iotests: Test migration with all kinds of filter nodes 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This test case is motivated by commit 2b23f28639 ('block/copy-on-read: Fix permissions for inactive node'). Instead of just testing copy-on-read on migration, let's stack all sorts of filter nodes on top of each other and try if the resulting VM can still migrate successfully. For good measure, put everything into an iothread, because why not? Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- tests/qemu-iotests/262 | 82 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/262.out | 17 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 100 insertions(+) create mode 100755 tests/qemu-iotests/262 create mode 100644 tests/qemu-iotests/262.out diff --git a/tests/qemu-iotests/262 b/tests/qemu-iotests/262 new file mode 100755 index 0000000000..398f63587e --- /dev/null +++ b/tests/qemu-iotests/262 @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# +# Copyright (C) 2019 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Kevin Wolf +# +# Test migration with filter drivers present. Keep everything in an +# iothread just for fun. + +import iotests +import os + +iotests.verify_image_format(supported_fmts=3D['qcow2']) +iotests.verify_platform(['linux']) + +with iotests.FilePath('img') as img_path, \ + iotests.FilePath('mig_fifo') as fifo, \ + iotests.VM(path_suffix=3D'a') as vm_a, \ + iotests.VM(path_suffix=3D'b') as vm_b: + + def add_opts(vm): + vm.add_object('iothread,id=3Diothread0') + vm.add_object('throttle-group,id=3Dtg0,x-bps-total=3D65536') + vm.add_blockdev('file,filename=3D%s,node-name=3Ddrive0-file' % (im= g_path)) + vm.add_blockdev('%s,file=3Ddrive0-file,node-name=3Ddrive0-fmt' % (= iotests.imgfmt)) + vm.add_blockdev('copy-on-read,file=3Ddrive0-fmt,node-name=3Ddrive0= -cor') + vm.add_blockdev('throttle,file=3Ddrive0-cor,node-name=3Ddrive0-thr= ottle,throttle-group=3Dtg0') + vm.add_blockdev('blkdebug,image=3Ddrive0-throttle,node-name=3Ddriv= e0-dbg') + vm.add_blockdev('null-co,node-name=3Dnull,read-zeroes=3Don') + vm.add_blockdev('blkverify,test=3Ddrive0-dbg,raw=3Dnull,node-name= =3Ddrive0-verify') + + if iotests.supports_quorum(): + vm.add_blockdev('quorum,children.0=3Ddrive0-verify,vote-thresh= old=3D1,node-name=3Ddrive0-quorum') + root =3D "drive0-quorum" + else: + root =3D "drive0-verify" + + vm.add_device('virtio-blk,drive=3D%s,iothread=3Diothread0' % root) + + iotests.qemu_img_pipe('create', '-f', iotests.imgfmt, img_path, '64M') + + os.mkfifo(fifo) + + iotests.log('Launching source VM...') + add_opts(vm_a) + vm_a.launch() + + vm_a.enable_migration_events('A') + + iotests.log('Launching destination VM...') + add_opts(vm_b) + vm_b.add_incoming("exec: cat '%s'" % (fifo)) + vm_b.launch() + + vm_b.enable_migration_events('B') + + iotests.log('Starting migration to B...') + iotests.log(vm_a.qmp('migrate', uri=3D'exec:cat >%s' % (fifo))) + with iotests.Timeout(3, 'Migration does not complete'): + # Wait for the source first (which includes setup=3Dsetup) + vm_a.wait_migration() + # Wait for the destination second (which does not) + vm_b.wait_migration() + + iotests.log(vm_a.qmp('query-migrate')['return']['status']) + iotests.log(vm_b.qmp('query-migrate')['return']['status']) + + iotests.log(vm_a.qmp('query-status')) + iotests.log(vm_b.qmp('query-status')) diff --git a/tests/qemu-iotests/262.out b/tests/qemu-iotests/262.out new file mode 100644 index 0000000000..5a58e5e9f8 --- /dev/null +++ b/tests/qemu-iotests/262.out @@ -0,0 +1,17 @@ +Launching source VM... +Enabling migration QMP events on A... +{"return": {}} +Launching destination VM... +Enabling migration QMP events on B... +{"return": {}} +Starting migration to B... +{"return": {}} +{"data": {"status": "setup"}, "event": "MIGRATION", "timestamp": {"microse= conds": "USECS", "seconds": "SECS"}} +{"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"micros= econds": "USECS", "seconds": "SECS"}} +{"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"mic= roseconds": "USECS", "seconds": "SECS"}} +{"data": {"status": "active"}, "event": "MIGRATION", "timestamp": {"micros= econds": "USECS", "seconds": "SECS"}} +{"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"mic= roseconds": "USECS", "seconds": "SECS"}} +completed +completed +{"return": {"running": false, "singlestep": false, "status": "postmigrate"= }} +{"return": {"running": true, "singlestep": false, "status": "running"}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index f13e5f2e23..71ba3c05dc 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -271,3 +271,4 @@ 254 rw backing quick 255 rw quick 256 rw quick +262 rw quick migration --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948459; cv=none; d=zoho.com; s=zohoarc; b=P3oQiT/Zi14kBayJ6QTA7UQwOSh+lOBtcLdR5D00xRk++I//BtLYIrsRIM7/0Pjy2A4Rsgiwx/sZvnL8c0YBVedX6B9B+kj1Q09BzYE4xDzPJKnCzoJ+6iTqgwOeRw9sB1MWvdrrkYysin17iVKMX+G72IMVO9iHjBSfYrJe5mU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948459; 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=kGYJiaauj8gRavWf4harSgH/yXWGXCoFU24aN8LRoJ0=; b=TwbS4gsAE1Dhtl0CYVmZtgNXnvkMiOI6h9OoDaPnA7bQ0joyCdXAdkUj0YBvoREB5jHkM8GIBdQuwPgU+pZFZp7fjGsP6ZYRUO6mv8CL3JTVmkHd2WruxPeg4mMRsvhBQtt8S8joMCskwM3clwMJC06MIP+gg7ID0vxsWdcimxA= 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 1565948459069953.7810563257882; Fri, 16 Aug 2019 02:40:59 -0700 (PDT) Received: from localhost ([::1]:52520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYjB-00060P-Hc for importer@patchew.org; Fri, 16 Aug 2019 05:40:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59464) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdK-0008K1-RN for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdJ-0003at-DF for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56218) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdH-0003Xw-1r; Fri, 16 Aug 2019 05:34:51 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58D0F306046D; Fri, 16 Aug 2019 09:34:50 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 924B35C1D6; Fri, 16 Aug 2019 09:34:49 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:29 +0200 Message-Id: <20190816093439.14262-7-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 16 Aug 2019 09:34:50 +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] [PULL 06/16] block: Simplify bdrv_filter_default_perms() 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The same change as commit 2b23f28639 ('block/copy-on-read: Fix permissions for inactive node') made for the copy-on-read driver can be made for bdrv_filter_default_perms(): Retaining the old permissions from the BdrvChild if it is given complicates things unnecessarily when in the end this only means that the options set in the c =3D=3D NULL case (i.e. during child creation) are retained. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Max Reitz --- block.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/block.c b/block.c index cbd8da5f3b..6db8ecd62b 100644 --- a/block.c +++ b/block.c @@ -2168,16 +2168,8 @@ void bdrv_filter_default_perms(BlockDriverState *bs,= BdrvChild *c, uint64_t perm, uint64_t shared, uint64_t *nperm, uint64_t *nshared) { - if (c =3D=3D NULL) { - *nperm =3D perm & DEFAULT_PERM_PASSTHROUGH; - *nshared =3D (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UN= CHANGED; - return; - } - - *nperm =3D (perm & DEFAULT_PERM_PASSTHROUGH) | - (c->perm & DEFAULT_PERM_UNCHANGED); - *nshared =3D (shared & DEFAULT_PERM_PASSTHROUGH) | - (c->shared_perm & DEFAULT_PERM_UNCHANGED); + *nperm =3D perm & DEFAULT_PERM_PASSTHROUGH; + *nshared =3D (shared & DEFAULT_PERM_PASSTHROUGH) | DEFAULT_PERM_UNCHAN= GED; } =20 void bdrv_format_default_perms(BlockDriverState *bs, BdrvChild *c, --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948626; cv=none; d=zoho.com; s=zohoarc; b=WOxsfNsZ0u/3BtprqSP8KKgq+oKYWZWNrVvxFJEFb3z8NqKlXi1wP3A+19ipMbBEM8LfR/0VuZoldaG/LizjSXIj2aBXoAcoyI+aG8i69R73yh+oPbEyEP7+/yYhpgHNPM3Rnt86sLlta5kgbj5pabiAIsOArFG4VcB2nHGGVh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948626; 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=M6aj0LhbZoG876b96CPeUk2l84zTTry19LKrxQv8Kyc=; b=VqENvH3vK8+EiO23UU/qvvs6Nb9PeX9lWG4YhTU5Fm5bjetW3dP1QtSYm/+dr2rK2ZEW6+CqMjVySj8MLlCU1S8aAvgXh655mbKxYt1XdMmdPDxWYJBfgfapbXDbJsumGjJP/1ahavdogNZxv+zU+D9PvAVPlCumOfHTS0rbYFY= 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 1565948626325227.79723287530567; Fri, 16 Aug 2019 02:43:46 -0700 (PDT) Received: from localhost ([::1]:52554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYlp-0000gn-DN for importer@patchew.org; Fri, 16 Aug 2019 05:43:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59492) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdL-0008LU-PI for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdK-0003cC-MO for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12048) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdI-0003Yy-1z; Fri, 16 Aug 2019 05:34:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6266630842A9; Fri, 16 Aug 2019 09:34:51 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DE4A5C1B2; Fri, 16 Aug 2019 09:34:50 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:30 +0200 Message-Id: <20190816093439.14262-8-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Fri, 16 Aug 2019 09:34:51 +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] [PULL 07/16] block: Keep subtree drained in drop_intermediate 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Max Reitz bdrv_drop_intermediate() calls BdrvChildRole.update_filename(). That may poll, thus changing the graph, which potentially breaks the QLIST_FOREACH_SAFE() loop. Just keep the whole subtree drained. This is probably the right thing to do anyway (dropping nodes while the subtree is not drained seems wrong). Signed-off-by: Max Reitz Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block.c b/block.c index 6db8ecd62b..df3407934b 100644 --- a/block.c +++ b/block.c @@ -4491,6 +4491,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, Blo= ckDriverState *base, int ret =3D -EIO; =20 bdrv_ref(top); + bdrv_subtree_drained_begin(top); =20 if (!top->drv || !base->drv) { goto exit; @@ -4562,6 +4563,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, Blo= ckDriverState *base, =20 ret =3D 0; exit: + bdrv_subtree_drained_end(top); bdrv_unref(top); return ret; } --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948517; cv=none; d=zoho.com; s=zohoarc; b=OpwnS4FmUiLn600RYp2FuxXxlJVaIG/JagxnSEmExr8/b+lN3oPaRioABzpep/VWhV9NOFmecW8JNX90Kvs5+NHA42kVAFDCvMnzE2VMJ45EKFu1xydCFMolPNaZAtjr2cFF2an8fzJOfapN01zo7tBuEv9ZEFdzEEcp3v6V8vE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948517; 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=vOkJdgs+tJcoVmkxzJRuLpCYfNVyZMYF2ezxPMhYAC0=; b=k73fxMHi4Vg9BCCXBywRGd4Rn3LLouul8PLYPtwvPeXqdP/AJeHesffJ/nkVvCHqzzc9gFN+1S8Ihe2HPj6Z45pyNYyPXwFjbQ6BGFGwl6Qtj4BWgzKSuIZlwGWsdoJaoHh3goY4czB7t/i2h9fFL9NQI6H08eGBvaMWn47rXXs= 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 1565948517218525.1089907760851; Fri, 16 Aug 2019 02:41:57 -0700 (PDT) Received: from localhost ([::1]:52524 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYk6-0006YO-Gs for importer@patchew.org; Fri, 16 Aug 2019 05:41:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59523) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdN-0008O1-DS for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdM-0003eh-4Z for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdJ-0003aC-3e; Fri, 16 Aug 2019 05:34:53 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69D383091753; Fri, 16 Aug 2019 09:34:52 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id A560C5C1B2; Fri, 16 Aug 2019 09:34:51 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:31 +0200 Message-Id: <20190816093439.14262-9-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 16 Aug 2019 09:34:52 +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] [PULL 08/16] block: Reduce (un)drains when replacing a child 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Max Reitz Currently, bdrv_replace_child_noperm() undrains the parent until it is completely undrained, then re-drains it after attaching the new child node. This is a problem with bdrv_drop_intermediate(): We want to keep the whole subtree drained, including parents, while the operation is under way. bdrv_replace_child_noperm() breaks this by allowing every parent to become unquiesced briefly, and then redraining it. In fact, there is no reason why the parent should become unquiesced and be allowed to submit requests to the new child node if that new node is supposed to be kept drained. So if anything, we have to drain the parent before detaching the old child node. Conversely, we have to undrain it only after attaching the new child node. Thus, change the whole drain algorithm here: Calculate the number of times we have to drain/undrain the parent before replacing the child node then drain it (if necessary), replace the child node, and then undrain it. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- block.c | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index df3407934b..66e8602e68 100644 --- a/block.c +++ b/block.c @@ -2230,13 +2230,27 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, BlockDriverState *new_bs) { BlockDriverState *old_bs =3D child->bs; - int i; + int new_bs_quiesce_counter; + int drain_saldo; =20 assert(!child->frozen); =20 if (old_bs && new_bs) { assert(bdrv_get_aio_context(old_bs) =3D=3D bdrv_get_aio_context(ne= w_bs)); } + + new_bs_quiesce_counter =3D (new_bs ? new_bs->quiesce_counter : 0); + drain_saldo =3D new_bs_quiesce_counter - child->parent_quiesce_counter; + + /* + * If the new child node is drained but the old one was not, flush + * all outstanding requests to the old child node. + */ + while (drain_saldo > 0 && child->role->drained_begin) { + bdrv_parent_drained_begin_single(child, true); + drain_saldo--; + } + if (old_bs) { /* Detach first so that the recursive drain sections coming from @= child * are already gone and we only end the drain sections that came f= rom @@ -2244,28 +2258,22 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, if (child->role->detach) { child->role->detach(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) { - int num =3D new_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++) { - bdrv_parent_drained_begin_single(child, true); - } - } + + /* + * Detaching the old node may have led to the new node's + * quiesce_counter having been decreased. Not a problem, we + * just need to recognize this here and then invoke + * drained_end appropriately more often. + */ + assert(new_bs->quiesce_counter <=3D new_bs_quiesce_counter); + drain_saldo +=3D new_bs->quiesce_counter - new_bs_quiesce_counter; =20 /* Attach only after starting new drained sections, so that recurs= ive * drain sections coming from @child don't get an extra .drained_b= egin @@ -2274,6 +2282,15 @@ static void bdrv_replace_child_noperm(BdrvChild *chi= ld, child->role->attach(child); } } + + /* + * If the old child node was drained but the new one is not, allow + * requests to come in only after the new node has been attached. + */ + while (drain_saldo < 0 && child->role->drained_end) { + bdrv_parent_drained_end_single(child); + drain_saldo++; + } } =20 /* --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948806; cv=none; d=zoho.com; s=zohoarc; b=D0YUlfrKnPySECPRvYqKNs4X3wwUV57+84gAIfgY+VDZJDQLEanCXIsWEtcbsPYiAGmZib5gicrFFXhUT0yAuCjMBRC+MWLPgdj4185IcQXFde7G2jFpOypdHrLd+o4Yz3MWT0pXHsMQ6yOPKxRic9CLQmXTuzf0mz/HyVrpI/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948806; 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=5/7Ck/LO5tUeXq9y8MJS14ItURPF2CIdT9PTZL4zuOw=; b=HoaeGp/imC+6rH4uz71a87qOQrswABOTDpp7unXBpE/edLyAyYgCCXkB1UxWnxVenUgbWkwwmV+BlGaFJL6breua0kA+lw6NB5P1mY6PS+H29ypRddr/IHMpAsndYm0Cindth9EcgLxnnf7pCIuBQEqhvH2HRkYngJoXDlZ1wwQ= 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 1565948806989831.2056230022737; Fri, 16 Aug 2019 02:46:46 -0700 (PDT) Received: from localhost ([::1]:52618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYon-0005Gj-Se for importer@patchew.org; Fri, 16 Aug 2019 05:46:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59541) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdP-0008Rm-4q for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdN-0003fr-GP for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:34:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47776) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdK-0003bF-4P; Fri, 16 Aug 2019 05:34:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F972693C8; Fri, 16 Aug 2019 09:34:53 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACB1A5C1B2; Fri, 16 Aug 2019 09:34:52 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:32 +0200 Message-Id: <20190816093439.14262-10-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 16 Aug 2019 09:34:53 +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] [PULL 09/16] tests: Test polling in bdrv_drop_intermediate() 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Max Reitz Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 167 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 03fa1142a1..1600d41e9a 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -100,6 +100,13 @@ static void bdrv_test_child_perm(BlockDriverState *bs,= BdrvChild *c, nperm, nshared); } =20 +static int bdrv_test_change_backing_file(BlockDriverState *bs, + const char *backing_file, + const char *backing_fmt) +{ + return 0; +} + static BlockDriver bdrv_test =3D { .format_name =3D "test", .instance_size =3D sizeof(BDRVTestState), @@ -111,6 +118,8 @@ static BlockDriver bdrv_test =3D { .bdrv_co_drain_end =3D bdrv_test_co_drain_end, =20 .bdrv_child_perm =3D bdrv_test_child_perm, + + .bdrv_change_backing_file =3D bdrv_test_change_backing_file, }; =20 static void aio_ret_cb(void *opaque, int ret) @@ -1671,6 +1680,161 @@ static void test_blockjob_commit_by_drained_end(voi= d) bdrv_unref(bs_child); } =20 + +typedef struct TestSimpleBlockJob { + BlockJob common; + bool should_complete; + bool *did_complete; +} TestSimpleBlockJob; + +static int coroutine_fn test_simple_job_run(Job *job, Error **errp) +{ + TestSimpleBlockJob *s =3D container_of(job, TestSimpleBlockJob, common= .job); + + while (!s->should_complete) { + job_sleep_ns(job, 0); + } + + return 0; +} + +static void test_simple_job_clean(Job *job) +{ + TestSimpleBlockJob *s =3D container_of(job, TestSimpleBlockJob, common= .job); + *s->did_complete =3D true; +} + +static const BlockJobDriver test_simple_job_driver =3D { + .job_driver =3D { + .instance_size =3D sizeof(TestSimpleBlockJob), + .free =3D block_job_free, + .user_resume =3D block_job_user_resume, + .drain =3D block_job_drain, + .run =3D test_simple_job_run, + .clean =3D test_simple_job_clean, + }, +}; + +static int drop_intermediate_poll_update_filename(BdrvChild *child, + BlockDriverState *new_ba= se, + const char *filename, + Error **errp) +{ + /* + * We are free to poll here, which may change the block graph, if + * it is not drained. + */ + + /* If the job is not drained: Complete it, schedule job_exit() */ + aio_poll(qemu_get_current_aio_context(), false); + /* If the job is not drained: Run job_exit(), finish the job */ + aio_poll(qemu_get_current_aio_context(), false); + + return 0; +} + +/** + * Test a poll in the midst of bdrv_drop_intermediate(). + * + * bdrv_drop_intermediate() calls BdrvChildRole.update_filename(), + * which can yield or poll. This may lead to graph changes, unless + * the whole subtree in question is drained. + * + * We test this on the following graph: + * + * Job + * + * | + * job-node + * | + * v + * + * job-node + * + * | + * backing + * | + * v + * + * node-2 --chain--> node-1 --chain--> node-0 + * + * We drop node-1 with bdrv_drop_intermediate(top=3Dnode-1, base=3Dnode-0). + * + * This first updates node-2's backing filename by invoking + * drop_intermediate_poll_update_filename(), which polls twice. This + * causes the job to finish, which in turns causes the job-node to be + * deleted. + * + * bdrv_drop_intermediate() uses a QLIST_FOREACH_SAFE() loop, so it + * already has a pointer to the BdrvChild edge between job-node and + * node-1. When it tries to handle that edge, we probably get a + * segmentation fault because the object no longer exists. + * + * + * The solution is for bdrv_drop_intermediate() to drain top's + * subtree. This prevents graph changes from happening just because + * BdrvChildRole.update_filename() yields or polls. Thus, the block + * job is paused during that drained section and must finish before or + * after. + * + * (In addition, bdrv_replace_child() must keep the job paused.) + */ +static void test_drop_intermediate_poll(void) +{ + static BdrvChildRole chain_child_role; + BlockDriverState *chain[3]; + TestSimpleBlockJob *job; + BlockDriverState *job_node; + bool job_has_completed =3D false; + int i; + int ret; + + chain_child_role =3D child_backing; + chain_child_role.update_filename =3D drop_intermediate_poll_update_fil= ename; + + for (i =3D 0; i < 3; i++) { + char name[32]; + snprintf(name, 32, "node-%i", i); + + chain[i] =3D bdrv_new_open_driver(&bdrv_test, name, 0, &error_abor= t); + } + + job_node =3D bdrv_new_open_driver(&bdrv_test, "job-node", BDRV_O_RDWR, + &error_abort); + bdrv_set_backing_hd(job_node, chain[1], &error_abort); + + /* + * Establish the chain last, so the chain links are the first + * elements in the BDS.parents lists + */ + for (i =3D 0; i < 3; i++) { + if (i) { + /* Takes the reference to chain[i - 1] */ + chain[i]->backing =3D bdrv_attach_child(chain[i], chain[i - 1], + "chain", &chain_child_ro= le, + &error_abort); + } + } + + job =3D block_job_create("job", &test_simple_job_driver, NULL, job_nod= e, + 0, BLK_PERM_ALL, 0, 0, NULL, NULL, &error_abort= ); + + /* The job has a reference now */ + bdrv_unref(job_node); + + job->did_complete =3D &job_has_completed; + + job_start(&job->common.job); + job->should_complete =3D true; + + g_assert(!job_has_completed); + ret =3D bdrv_drop_intermediate(chain[1], chain[0], NULL); + g_assert(ret =3D=3D 0); + g_assert(job_has_completed); + + bdrv_unref(chain[2]); +} + int main(int argc, char **argv) { int ret; @@ -1757,6 +1921,9 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/blockjob/commit_by_drained_end", test_blockjob_commit_by_drained_end); =20 + g_test_add_func("/bdrv-drain/bdrv_drop_intermediate/poll", + test_drop_intermediate_poll); + ret =3D g_test_run(); qemu_event_destroy(&done_event); return ret; --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948503; cv=none; d=zoho.com; s=zohoarc; b=ZhLEWNTGHfnsdIbD27YDg5rQUnzAPdj0vhGJLrJyClM4DzE1bIWgFDVrWQF5t4/35pK+F7Zzw3BFGD1F63TRAboVrCH1VuIfiyYwQGCjEsfTJTLfY0MO6vBmMVwkQeXSAgeesKItm6EyJeRZ/XOebaB1D4tbtOt/+P51HZFKA/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948503; 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=tTQ6I+zb0gRUeIbUg1aXUBeToGQ1BLOVHq6E0ZkAnzs=; b=gaaJ826IxggBzmxnmk7mFPykbmfGb2MswQjJR0Nkr0PTWYjx3dqMPWEuM+kaRovZ5idiis8lY214lkVoSFBOF2qizGVkojVkrtbaA1kPotU70lGBPqwLMnA4qLAf2QVvm/CAps5zJOFgxzT6fkaLr21c5fGjItxIQnxQPnh8hhY= 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 1565948503489843.876699178616; Fri, 16 Aug 2019 02:41:43 -0700 (PDT) Received: from localhost ([::1]:52522 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYju-0006Sq-9O for importer@patchew.org; Fri, 16 Aug 2019 05:41:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59573) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdQ-0008Ug-PL for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdP-0003iR-1x for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56292) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdL-0003c7-5c; Fri, 16 Aug 2019 05:34:55 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 79961306046D; Fri, 16 Aug 2019 09:34:54 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3BAC5C205; Fri, 16 Aug 2019 09:34:53 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:33 +0200 Message-Id: <20190816093439.14262-11-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 16 Aug 2019 09:34:54 +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] [PULL 10/16] tests: Test mid-drain bdrv_replace_child_noperm() 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Max Reitz Add a test for what happens when you call bdrv_replace_child_noperm() for various drain situations ({old,new} child {drained,not drained}). Most importantly, if both the old and the new child are drained, the parent must not be undrained at any point. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- tests/test-bdrv-drain.c | 308 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 1600d41e9a..9dffd86c47 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -1835,6 +1835,311 @@ static void test_drop_intermediate_poll(void) bdrv_unref(chain[2]); } =20 + +typedef struct BDRVReplaceTestState { + bool was_drained; + bool was_undrained; + bool has_read; + + int drain_count; + + bool yield_before_read; + Coroutine *io_co; + Coroutine *drain_co; +} BDRVReplaceTestState; + +static void bdrv_replace_test_close(BlockDriverState *bs) +{ +} + +/** + * If @bs has a backing file: + * Yield if .yield_before_read is true (and wait for drain_begin to + * wake us up). + * Forward the read to bs->backing. Set .has_read to true. + * If drain_begin has woken us, wake it in turn. + * + * Otherwise: + * Set .has_read to true and return success. + */ +static int coroutine_fn bdrv_replace_test_co_preadv(BlockDriverState *bs, + uint64_t offset, + uint64_t bytes, + QEMUIOVector *qiov, + int flags) +{ + BDRVReplaceTestState *s =3D bs->opaque; + + if (bs->backing) { + int ret; + + g_assert(!s->drain_count); + + s->io_co =3D qemu_coroutine_self(); + if (s->yield_before_read) { + s->yield_before_read =3D false; + qemu_coroutine_yield(); + } + s->io_co =3D NULL; + + ret =3D bdrv_preadv(bs->backing, offset, qiov); + s->has_read =3D true; + + /* Wake up drain_co if it runs */ + if (s->drain_co) { + aio_co_wake(s->drain_co); + } + + return ret; + } + + s->has_read =3D true; + return 0; +} + +/** + * If .drain_count is 0, wake up .io_co if there is one; and set + * .was_drained. + * Increment .drain_count. + */ +static void coroutine_fn bdrv_replace_test_co_drain_begin(BlockDriverState= *bs) +{ + BDRVReplaceTestState *s =3D bs->opaque; + + if (!s->drain_count) { + /* Keep waking io_co up until it is done */ + s->drain_co =3D qemu_coroutine_self(); + while (s->io_co) { + aio_co_wake(s->io_co); + s->io_co =3D NULL; + qemu_coroutine_yield(); + } + s->drain_co =3D NULL; + + s->was_drained =3D true; + } + s->drain_count++; +} + +/** + * Reduce .drain_count, set .was_undrained once it reaches 0. + * If .drain_count reaches 0 and the node has a backing file, issue a + * read request. + */ +static void coroutine_fn bdrv_replace_test_co_drain_end(BlockDriverState *= bs) +{ + BDRVReplaceTestState *s =3D bs->opaque; + + g_assert(s->drain_count > 0); + if (!--s->drain_count) { + int ret; + + s->was_undrained =3D true; + + if (bs->backing) { + char data; + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, &data, 1); + + /* Queue a read request post-drain */ + ret =3D bdrv_replace_test_co_preadv(bs, 0, 1, &qiov, 0); + g_assert(ret >=3D 0); + } + } +} + +static BlockDriver bdrv_replace_test =3D { + .format_name =3D "replace_test", + .instance_size =3D sizeof(BDRVReplaceTestState), + + .bdrv_close =3D bdrv_replace_test_close, + .bdrv_co_preadv =3D bdrv_replace_test_co_preadv, + + .bdrv_co_drain_begin =3D bdrv_replace_test_co_drain_begin, + .bdrv_co_drain_end =3D bdrv_replace_test_co_drain_end, + + .bdrv_child_perm =3D bdrv_format_default_perms, +}; + +static void coroutine_fn test_replace_child_mid_drain_read_co(void *opaque) +{ + int ret; + char data; + + ret =3D blk_co_pread(opaque, 0, 1, &data, 0); + g_assert(ret >=3D 0); +} + +/** + * We test two things: + * (1) bdrv_replace_child_noperm() must not undrain the parent if both + * children are drained. + * (2) bdrv_replace_child_noperm() must never flush I/O requests to a + * drained child. If the old child is drained, it must flush I/O + * requests after the new one has been attached. If the new child + * is drained, it must flush I/O requests before the old one is + * detached. + * + * To do so, we create one parent node and two child nodes; then + * attach one of the children (old_child_bs) to the parent, then + * drain both old_child_bs and new_child_bs according to + * old_drain_count and new_drain_count, respectively, and finally + * we invoke bdrv_replace_node() to replace old_child_bs by + * new_child_bs. + * + * The test block driver we use here (bdrv_replace_test) has a read + * function that: + * - For the parent node, can optionally yield, and then forwards the + * read to bdrv_preadv(), + * - For the child node, just returns immediately. + * + * If the read yields, the drain_begin function will wake it up. + * + * The drain_end function issues a read on the parent once it is fully + * undrained (which simulates requests starting to come in again). + */ +static void do_test_replace_child_mid_drain(int old_drain_count, + int new_drain_count) +{ + BlockBackend *parent_blk; + BlockDriverState *parent_bs; + BlockDriverState *old_child_bs, *new_child_bs; + BDRVReplaceTestState *parent_s; + BDRVReplaceTestState *old_child_s, *new_child_s; + Coroutine *io_co; + int i; + + parent_bs =3D bdrv_new_open_driver(&bdrv_replace_test, "parent", 0, + &error_abort); + parent_s =3D parent_bs->opaque; + + parent_blk =3D blk_new(qemu_get_aio_context(), + BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL); + blk_insert_bs(parent_blk, parent_bs, &error_abort); + + old_child_bs =3D bdrv_new_open_driver(&bdrv_replace_test, "old-child",= 0, + &error_abort); + new_child_bs =3D bdrv_new_open_driver(&bdrv_replace_test, "new-child",= 0, + &error_abort); + old_child_s =3D old_child_bs->opaque; + new_child_s =3D new_child_bs->opaque; + + /* So that we can read something */ + parent_bs->total_sectors =3D 1; + old_child_bs->total_sectors =3D 1; + new_child_bs->total_sectors =3D 1; + + bdrv_ref(old_child_bs); + parent_bs->backing =3D bdrv_attach_child(parent_bs, old_child_bs, "chi= ld", + &child_backing, &error_abort); + + for (i =3D 0; i < old_drain_count; i++) { + bdrv_drained_begin(old_child_bs); + } + for (i =3D 0; i < new_drain_count; i++) { + bdrv_drained_begin(new_child_bs); + } + + if (!old_drain_count) { + /* + * Start a read operation that will yield, so it will not + * complete before the node is drained. + */ + parent_s->yield_before_read =3D true; + io_co =3D qemu_coroutine_create(test_replace_child_mid_drain_read_= co, + parent_blk); + qemu_coroutine_enter(io_co); + } + + /* If we have started a read operation, it should have yielded */ + g_assert(!parent_s->has_read); + + /* Reset drained status so we can see what bdrv_replace_node() does */ + parent_s->was_drained =3D false; + parent_s->was_undrained =3D false; + + g_assert(parent_bs->quiesce_counter =3D=3D old_drain_count); + bdrv_replace_node(old_child_bs, new_child_bs, &error_abort); + g_assert(parent_bs->quiesce_counter =3D=3D new_drain_count); + + if (!old_drain_count && !new_drain_count) { + /* + * From undrained to undrained drains and undrains the parent, + * because bdrv_replace_node() contains a drained section for + * @old_child_bs. + */ + g_assert(parent_s->was_drained && parent_s->was_undrained); + } else if (!old_drain_count && new_drain_count) { + /* + * From undrained to drained should drain the parent and keep + * it that way. + */ + g_assert(parent_s->was_drained && !parent_s->was_undrained); + } else if (old_drain_count && !new_drain_count) { + /* + * From drained to undrained should undrain the parent and + * keep it that way. + */ + g_assert(!parent_s->was_drained && parent_s->was_undrained); + } else /* if (old_drain_count && new_drain_count) */ { + /* + * From drained to drained must not undrain the parent at any + * point + */ + g_assert(!parent_s->was_drained && !parent_s->was_undrained); + } + + if (!old_drain_count || !new_drain_count) { + /* + * If !old_drain_count, we have started a read request before + * bdrv_replace_node(). If !new_drain_count, the parent must + * have been undrained at some point, and + * bdrv_replace_test_co_drain_end() starts a read request + * then. + */ + g_assert(parent_s->has_read); + } else { + /* + * If the parent was never undrained, there is no way to start + * a read request. + */ + g_assert(!parent_s->has_read); + } + + /* A drained child must have not received any request */ + g_assert(!(old_drain_count && old_child_s->has_read)); + g_assert(!(new_drain_count && new_child_s->has_read)); + + for (i =3D 0; i < new_drain_count; i++) { + bdrv_drained_end(new_child_bs); + } + for (i =3D 0; i < old_drain_count; i++) { + bdrv_drained_end(old_child_bs); + } + + /* + * By now, bdrv_replace_test_co_drain_end() must have been called + * at some point while the new child was attached to the parent. + */ + g_assert(parent_s->has_read); + g_assert(new_child_s->has_read); + + blk_unref(parent_blk); + bdrv_unref(parent_bs); + bdrv_unref(old_child_bs); + bdrv_unref(new_child_bs); +} + +static void test_replace_child_mid_drain(void) +{ + int old_drain_count, new_drain_count; + + for (old_drain_count =3D 0; old_drain_count < 2; old_drain_count++) { + for (new_drain_count =3D 0; new_drain_count < 2; new_drain_count++= ) { + do_test_replace_child_mid_drain(old_drain_count, new_drain_cou= nt); + } + } +} + int main(int argc, char **argv) { int ret; @@ -1924,6 +2229,9 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/bdrv_drop_intermediate/poll", test_drop_intermediate_poll); =20 + g_test_add_func("/bdrv-drain/replace_child/mid-drain", + test_replace_child_mid_drain); + ret =3D g_test_run(); qemu_event_destroy(&done_event); return ret; --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948650; cv=none; d=zoho.com; s=zohoarc; b=K0zNNHYqVnaNOSvSfijt/b692tCkljwgxVa9yy6IuwrzQNevYOSO5hvWbxJs6pDXRJcauK3FceKFhBCtsd88B2lAuK2m5su8luygk7X10qrTsQByHT4CrKSIteVD77C6h/RXWeHa7BNcKZirqxhhPasFc6b+bqS5JEmuKBmQudQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948650; 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=wfGf4Rg2S+DzGmuRd8sLggpYZZNLKtu0z/xfsN2Zu0c=; b=N4WUohIFClUqRK/rgCwJMtg9Cp/eukw9iPp+gUvwuG7Wv6VrtXAOigkLYeqw6N9Fja6t21YWkxdPYZiYFVuyVScT2h9A+7XcLlUptC/9PaaOMlOrQFBQZvTJILXAJSJ52HBhD+L7lh44GSAdf9rV05AUIpEdRrLzPeegQvXCthw= 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 1565948650631681.7984557920386; Fri, 16 Aug 2019 02:44:10 -0700 (PDT) Received: from localhost ([::1]:52558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYmH-0001Ve-AV for importer@patchew.org; Fri, 16 Aug 2019 05:44:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59627) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdU-00008b-Aa for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdS-0003pf-EB for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55872) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdO-0003gH-7T; Fri, 16 Aug 2019 05:34:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 916BBC049E36; Fri, 16 Aug 2019 09:34:57 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC0925C1B2; Fri, 16 Aug 2019 09:34:54 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:34 +0200 Message-Id: <20190816093439.14262-12-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 16 Aug 2019 09:34:57 +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] [PULL 11/16] iotests: Add test for concurrent stream/commit 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Max Reitz We already have 030 for that in general, but this tests very specific cases of both jobs finishing concurrently. Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- tests/qemu-iotests/258 | 163 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/258.out | 33 ++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 197 insertions(+) create mode 100755 tests/qemu-iotests/258 create mode 100644 tests/qemu-iotests/258.out diff --git a/tests/qemu-iotests/258 b/tests/qemu-iotests/258 new file mode 100755 index 0000000000..b84cf02254 --- /dev/null +++ b/tests/qemu-iotests/258 @@ -0,0 +1,163 @@ +#!/usr/bin/env python +# +# Very specific tests for adjacent commit/stream block jobs +# +# Copyright (C) 2019 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Creator/Owner: Max Reitz + +import iotests +from iotests import log, qemu_img, qemu_io_silent, \ + filter_qmp_testfiles, filter_qmp_imgfmt + +# Need backing file and change-backing-file support +iotests.verify_image_format(supported_fmts=3D['qcow2', 'qed']) +iotests.verify_platform(['linux']) + + +# Returns a node for blockdev-add +def node(node_name, path, backing=3DNone, fmt=3DNone, throttle=3DNone): + if fmt is None: + fmt =3D iotests.imgfmt + + res =3D { + 'node-name': node_name, + 'driver': fmt, + 'file': { + 'driver': 'file', + 'filename': path + } + } + + if backing is not None: + res['backing'] =3D backing + + if throttle: + res['file'] =3D { + 'driver': 'throttle', + 'throttle-group': throttle, + 'file': res['file'] + } + + return res + +# Finds a node in the debug block graph +def find_graph_node(graph, node_id): + return next(node for node in graph['nodes'] if node['id'] =3D=3D node_= id) + + +def test_concurrent_finish(write_to_stream_node): + log('') + log('=3D=3D=3D Commit and stream finish concurrently (letting %s write= ) =3D=3D=3D' % \ + ('stream' if write_to_stream_node else 'commit')) + log('') + + # All chosen in such a way that when the commit job wants to + # finish, it polls and thus makes stream finish concurrently -- + # and the other way around, depending on whether the commit job + # is finalized before stream completes or not. + + with iotests.FilePath('node4.img') as node4_path, \ + iotests.FilePath('node3.img') as node3_path, \ + iotests.FilePath('node2.img') as node2_path, \ + iotests.FilePath('node1.img') as node1_path, \ + iotests.FilePath('node0.img') as node0_path, \ + iotests.VM() as vm: + + # It is important to use raw for the base layer (so that + # permissions are just handed through to the protocol layer) + assert qemu_img('create', '-f', 'raw', node0_path, '64M') =3D=3D 0 + + stream_throttle=3DNone + commit_throttle=3DNone + + for path in [node1_path, node2_path, node3_path, node4_path]: + assert qemu_img('create', '-f', iotests.imgfmt, path, '64M') = =3D=3D 0 + + if write_to_stream_node: + # This is what (most of the time) makes commit finish + # earlier and then pull in stream + assert qemu_io_silent(node2_path, + '-c', 'write %iK 64K' % (65536 - 192), + '-c', 'write %iK 64K' % (65536 - 64)) = =3D=3D 0 + + stream_throttle=3D'tg' + else: + # And this makes stream finish earlier + assert qemu_io_silent(node1_path, + '-c', 'write %iK 64K' % (65536 - 64)) = =3D=3D 0 + + commit_throttle=3D'tg' + + vm.launch() + + vm.qmp_log('object-add', + qom_type=3D'throttle-group', + id=3D'tg', + props=3D{ + 'x-iops-write': 1, + 'x-iops-write-max': 1 + }) + + vm.qmp_log('blockdev-add', + filters=3D[filter_qmp_testfiles, filter_qmp_imgfmt], + **node('node4', node4_path, throttle=3Dstream_throttle, + backing=3Dnode('node3', node3_path, + backing=3Dnode('node2', node2_path, + backing=3Dnode('node1', node1_path, + backing=3Dnode('node0', node0_path, throttle=3Dcommit= _throttle, + fmt=3D'raw')))))) + + vm.qmp_log('block-commit', + job_id=3D'commit', + device=3D'node4', + filter_node_name=3D'commit-filter', + top_node=3D'node1', + base_node=3D'node0', + auto_finalize=3DFalse) + + vm.qmp_log('block-stream', + job_id=3D'stream', + device=3D'node3', + base_node=3D'commit-filter') + + if write_to_stream_node: + vm.run_job('commit', auto_finalize=3DFalse, auto_dismiss=3DTru= e) + vm.run_job('stream', auto_finalize=3DTrue, auto_dismiss=3DTrue) + else: + # No, the jobs do not really finish concurrently here, + # the stream job does complete strictly before commit. + # But still, this is close enough for what we want to + # test. + vm.run_job('stream', auto_finalize=3DTrue, auto_dismiss=3DTrue) + vm.run_job('commit', auto_finalize=3DFalse, auto_dismiss=3DTru= e) + + # Assert that the backing node of node3 is node 0 now + graph =3D vm.qmp('x-debug-query-block-graph')['return'] + for edge in graph['edges']: + if edge['name'] =3D=3D 'backing' and \ + find_graph_node(graph, edge['parent'])['name'] =3D=3D 'node= 3': + assert find_graph_node(graph, edge['child'])['name'] =3D= =3D 'node0' + break + + +def main(): + log('Running tests:') + test_concurrent_finish(True) + test_concurrent_finish(False) + +if __name__ =3D=3D '__main__': + main() diff --git a/tests/qemu-iotests/258.out b/tests/qemu-iotests/258.out new file mode 100644 index 0000000000..ce6e9ba3e5 --- /dev/null +++ b/tests/qemu-iotests/258.out @@ -0,0 +1,33 @@ +Running tests: + +=3D=3D=3D Commit and stream finish concurrently (letting stream write) =3D= =3D=3D + +{"execute": "object-add", "arguments": {"id": "tg", "props": {"x-iops-writ= e": 1, "x-iops-write-max": 1}, "qom-type": "throttle-group"}} +{"return": {}} +{"execute": "blockdev-add", "arguments": {"backing": {"backing": {"backing= ": {"backing": {"driver": "raw", "file": {"driver": "file", "filename": "TE= ST_DIR/PID-node0.img"}, "node-name": "node0"}, "driver": "IMGFMT", "file": = {"driver": "file", "filename": "TEST_DIR/PID-node1.img"}, "node-name": "nod= e1"}, "driver": "IMGFMT", "file": {"driver": "file", "filename": "TEST_DIR/= PID-node2.img"}, "node-name": "node2"}, "driver": "IMGFMT", "file": {"drive= r": "file", "filename": "TEST_DIR/PID-node3.img"}, "node-name": "node3"}, "= driver": "IMGFMT", "file": {"driver": "throttle", "file": {"driver": "file"= , "filename": "TEST_DIR/PID-node4.img"}, "throttle-group": "tg"}, "node-nam= e": "node4"}} +{"return": {}} +{"execute": "block-commit", "arguments": {"auto-finalize": false, "base-no= de": "node0", "device": "node4", "filter-node-name": "commit-filter", "job-= id": "commit", "top-node": "node1"}} +{"return": {}} +{"execute": "block-stream", "arguments": {"base-node": "commit-filter", "d= evice": "node3", "job-id": "stream"}} +{"return": {}} +{"execute": "job-finalize", "arguments": {"id": "commit"}} +{"return": {}} +{"data": {"id": "commit", "type": "commit"}, "event": "BLOCK_JOB_PENDING",= "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"device": "commit", "len": 67108864, "offset": 67108864, "speed"= : 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"micr= oseconds": "USECS", "seconds": "SECS"}} +{"data": {"device": "stream", "len": 67108864, "offset": 67108864, "speed"= : 0, "type": "stream"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"micr= oseconds": "USECS", "seconds": "SECS"}} + +=3D=3D=3D Commit and stream finish concurrently (letting commit write) =3D= =3D=3D + +{"execute": "object-add", "arguments": {"id": "tg", "props": {"x-iops-writ= e": 1, "x-iops-write-max": 1}, "qom-type": "throttle-group"}} +{"return": {}} +{"execute": "blockdev-add", "arguments": {"backing": {"backing": {"backing= ": {"backing": {"driver": "raw", "file": {"driver": "throttle", "file": {"d= river": "file", "filename": "TEST_DIR/PID-node0.img"}, "throttle-group": "t= g"}, "node-name": "node0"}, "driver": "IMGFMT", "file": {"driver": "file", = "filename": "TEST_DIR/PID-node1.img"}, "node-name": "node1"}, "driver": "IM= GFMT", "file": {"driver": "file", "filename": "TEST_DIR/PID-node2.img"}, "n= ode-name": "node2"}, "driver": "IMGFMT", "file": {"driver": "file", "filena= me": "TEST_DIR/PID-node3.img"}, "node-name": "node3"}, "driver": "IMGFMT", = "file": {"driver": "file", "filename": "TEST_DIR/PID-node4.img"}, "node-nam= e": "node4"}} +{"return": {}} +{"execute": "block-commit", "arguments": {"auto-finalize": false, "base-no= de": "node0", "device": "node4", "filter-node-name": "commit-filter", "job-= id": "commit", "top-node": "node1"}} +{"return": {}} +{"execute": "block-stream", "arguments": {"base-node": "commit-filter", "d= evice": "node3", "job-id": "stream"}} +{"return": {}} +{"data": {"device": "stream", "len": 67108864, "offset": 67108864, "speed"= : 0, "type": "stream"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"micr= oseconds": "USECS", "seconds": "SECS"}} +{"execute": "job-finalize", "arguments": {"id": "commit"}} +{"return": {}} +{"data": {"id": "commit", "type": "commit"}, "event": "BLOCK_JOB_PENDING",= "timestamp": {"microseconds": "USECS", "seconds": "SECS"}} +{"data": {"device": "commit", "len": 67108864, "offset": 67108864, "speed"= : 0, "type": "commit"}, "event": "BLOCK_JOB_COMPLETED", "timestamp": {"micr= oseconds": "USECS", "seconds": "SECS"}} diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 71ba3c05dc..5a37839e35 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -271,4 +271,5 @@ 254 rw backing quick 255 rw quick 256 rw quick +258 rw quick 262 rw quick migration --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948904; cv=none; d=zoho.com; s=zohoarc; b=SXyQ1eXoc8O8LufefXK5yg1YLOfb+vRuIcxXp4nudBjO15zYlehm+QCjAr8XLZuyVvFhyAPLBkhiJc/avl0vIpXkjVC/R8ze0Pxd89bQkTDmBk6EKzu3lAE4B5awb8Sar7oG+172VhxVmlbzc3LdyH2wuLH0N8LPN7DSBGfhitg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948904; 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=Y5R/0RHIMCA2GDlt2bqYBRfg47J6rV5dgrDdAyrzbK0=; b=OGLBaPtRtuTza6ZvACiSsx+I+Ho6dPGiyLmbtGVBxmpv0I3v60DinGjQoxp+x7Kh3BZzbOo4RAI/EzMCwBkBBud7AMmsIV/yIWlobYX6nsS+MVK4DRpibhLSki+v/bXYEVVuxmw+OCkttMGABA4TTxpHr32U4Drf7R/FxOizuYY= 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 1565948904654266.62892407620154; Fri, 16 Aug 2019 02:48:24 -0700 (PDT) Received: from localhost ([::1]:52628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYqN-0006Kz-EJ for importer@patchew.org; Fri, 16 Aug 2019 05:48:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59612) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdT-000079-BL for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdS-0003p1-0w for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46806) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdP-0003iF-95; Fri, 16 Aug 2019 05:34:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 98D7A302C061; Fri, 16 Aug 2019 09:34:58 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id D57D55C1B2; Fri, 16 Aug 2019 09:34:57 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:35 +0200 Message-Id: <20190816093439.14262-13-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 16 Aug 2019 09:34:58 +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] [PULL 12/16] block: Remove blk_pread_unthrottled() 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The functionality offered by blk_pread_unthrottled() goes back to commit 498e386c584. Then, we couldn't perform I/O throttling with synchronous requests because timers wouldn't be executed in polling loops. So the commit automatically disabled I/O throttling as soon as a synchronous request was issued. However, for geometry detection during disk initialisation, we always used (and still use) synchronous requests even if guest requests use AIO later. Geometry detection was not wanted to disable I/O throttling, so bdrv_pread_unthrottled() was introduced which disabled throttling only temporarily. All of this isn't necessary any more because we do run timers in polling loop and even synchronous requests are now using coroutine infrastructure internally. For this reason, commit 90c78624f already removed the automatic disabling of I/O throttling. It's time to get rid of the workaround for the removed code, and its abuse of blk_root_drained_begin()/end(), as well. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/sysemu/block-backend.h | 2 -- block/block-backend.c | 16 ---------------- hw/block/hd-geometry.c | 7 +------ 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 733c4957eb..7320b58467 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -117,8 +117,6 @@ char *blk_get_attached_dev_id(BlockBackend *blk); BlockBackend *blk_by_dev(void *dev); BlockBackend *blk_by_qdev_id(const char *id, Error **errp); void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaq= ue); -int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, - int bytes); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); diff --git a/block/block-backend.c b/block/block-backend.c index 0056b526b8..fdd6b01ecf 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1237,22 +1237,6 @@ static int blk_prw(BlockBackend *blk, int64_t offset= , uint8_t *buf, return rwco.ret; } =20 -int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, - int count) -{ - int ret; - - ret =3D blk_check_byte_request(blk, offset, count); - if (ret < 0) { - return ret; - } - - blk_root_drained_begin(blk->root); - ret =3D blk_pread(blk, offset, buf, count); - blk_root_drained_end(blk->root, NULL); - return ret; -} - int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int bytes, BdrvRequestFlags flags) { diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c index 79384a2b0a..dcbccee294 100644 --- a/hw/block/hd-geometry.c +++ b/hw/block/hd-geometry.c @@ -63,12 +63,7 @@ static int guess_disk_lchs(BlockBackend *blk, =20 blk_get_geometry(blk, &nb_sectors); =20 - /** - * The function will be invoked during startup not only in sync I/O mo= de, - * but also in async I/O mode. So the I/O throttling function has to - * be disabled temporarily here, not permanently. - */ - if (blk_pread_unthrottled(blk, 0, buf, BDRV_SECTOR_SIZE) < 0) { + if (blk_pread(blk, 0, buf, BDRV_SECTOR_SIZE) < 0) { return -1; } /* test msdos magic */ --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948661; cv=none; d=zoho.com; s=zohoarc; b=Ry0H0oFsP6mDIbC2/4XaZxucAasc2KSVWqUpB2wumLEoVPMNh9WHRHm3WCCuZK4gnQojRnY72t907yeGJwyPl0gGO/daBqS7aksU9vmzuMLYFit2jUzIi9RySKSA4eXPkJ5/1Jn6Sho/kboUlnA+7o09qVmMvW+roO4W5FE0cWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948661; 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=Ev8dPSCWRMJ30CVYQ97uYDTegAym/OwwbwlwGRyitZk=; b=PSPmyCfmy5KlFOrrqKKIZGPvF6GjZJesWngpiGmprNeNOoCFID5vCl8Pj1R1hd+vu3YE4xwQl5SH/CYBp3oAaRrijDeKv62SEBvaihrFRY+8POG0Nyi7mxE2qwUZwBWrEVsiTp0d+6KJ4L75E0L9SLNLlFkbpxpa9pEIN87SKNY= 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 1565948661328921.3118611805412; Fri, 16 Aug 2019 02:44:21 -0700 (PDT) Received: from localhost ([::1]:52562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYmR-0001u1-Ps for importer@patchew.org; Fri, 16 Aug 2019 05:44:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59643) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdV-0000BK-TU for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdU-0003rn-MN for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56350) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdS-0003og-DK; Fri, 16 Aug 2019 05:35:02 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFCA2306046D; Fri, 16 Aug 2019 09:35:01 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC63B5C1D6; Fri, 16 Aug 2019 09:34:58 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:36 +0200 Message-Id: <20190816093439.14262-14-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 16 Aug 2019 09:35:01 +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] [PULL 13/16] mirror: Keep mirror_top_bs drained after dropping permissions 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" mirror_top_bs is currently implicitly drained through its connection to the source or the target node. However, the drain section for target_bs ends early after moving mirror_top_bs from src to target_bs, so that requests can already be restarted while mirror_top_bs is still present in the chain, but has dropped all permissions and therefore runs into an assertion failure like this: qemu-system-x86_64: block/io.c:1634: bdrv_co_write_req_prepare: Assertion `child->perm & BLK_PERM_WRITE' failed. Keep mirror_top_bs drained until all graph changes have completed. Cc: qemu-stable@nongnu.org Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/mirror.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index 9f5c59ece1..642d6570cc 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -656,7 +656,10 @@ static int mirror_exit_common(Job *job) s->target =3D NULL; =20 /* We don't access the source any more. Dropping any WRITE/RESIZE is - * required before it could become a backing file of target_bs. */ + * required before it could become a backing file of target_bs. Not ha= ving + * these permissions any more means that we can't allow any new reques= ts on + * mirror_top_bs from now on, so keep it drained. */ + bdrv_drained_begin(mirror_top_bs); bs_opaque->stop =3D true; bdrv_child_refresh_perms(mirror_top_bs, mirror_top_bs->backing, &error_abort); @@ -724,6 +727,7 @@ static int mirror_exit_common(Job *job) bs_opaque->job =3D NULL; =20 bdrv_drained_end(src); + bdrv_drained_end(mirror_top_bs); s->in_drain =3D false; bdrv_unref(mirror_top_bs); bdrv_unref(src); --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565949067; cv=none; d=zoho.com; s=zohoarc; b=REAYMO9jkw9ScNyPIGtCs82uFIBp2clja+3bB7j0d1EipXlU25cxrFYcgdDHvVC89Kx589N94cx0YV7snwLuSDoUznLbhN8KxorOAikJcciEa7SIdOR5ZZzPkhV13SmpluvUXebv+tKdPyvTEoQQ50tbnbc12s8IAHqG+qr1dWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565949067; 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=b6JQmSNyq45N4UmYrV70fw5zSGh/a8j3PkQ7vUfVEwo=; b=GXaclR2T9+TM1z1srRb+xOz7Zqz2Fht5nfB6HFBJmN0DN5YO3E2Fom9eRaWCda7SDeHGf4w0LN0atJcVojmHntRgPcVMxsJvpBj3avD76VR1m9SV0rxnCj+hoNk93psEFpFbj3Wam5Vi3sqUR/p0VtuCJgANXVDH3AvkGI3gBt4= 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 1565949067291123.83358213673364; Fri, 16 Aug 2019 02:51:07 -0700 (PDT) Received: from localhost ([::1]:52640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYsy-0008KM-20 for importer@patchew.org; Fri, 16 Aug 2019 05:51:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59711) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYdb-0000Ki-8j for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdZ-0003x4-E3 for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60842) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdV-0003rx-G8; Fri, 16 Aug 2019 05:35:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFABD308212D; Fri, 16 Aug 2019 09:35:04 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0D465C1B2; Fri, 16 Aug 2019 09:35:01 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:37 +0200 Message-Id: <20190816093439.14262-15-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 16 Aug 2019 09:35:04 +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] [PULL 14/16] block-backend: Queue requests while drained 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This fixes devices like IDE that can still start new requests from I/O handlers in the CPU thread while the block backend is drained. The basic assumption is that in a drain section, no new requests should be allowed through a BlockBackend (blk_drained_begin/end don't exist, we get drain sections only on the node level). However, there are two special cases where requests should not be queued: 1. Block jobs: We already make sure that block jobs are paused in a drain section, so they won't start new requests. However, if the drain_begin is called on the job's BlockBackend first, it can happen that we deadlock because the job stays busy until it reaches a pause point - which it can't if its requests aren't processed any more. The proper solution here would be to make all requests through the job's filter node instead of using a BlockBackend. For now, just disabling request queuing on the job BlockBackend is simpler. 2. In test cases where making requests through bdrv_* would be cumbersome because we'd need a BdrvChild. As we already got the functionality to disable request queuing from 1., use it in tests, too, for convenience. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- include/sysemu/block-backend.h | 1 + block/backup.c | 1 + block/block-backend.c | 53 ++++++++++++++++++++++++++++++++-- block/commit.c | 2 ++ block/mirror.c | 1 + blockjob.c | 3 ++ tests/test-bdrv-drain.c | 1 + 7 files changed, 59 insertions(+), 3 deletions(-) diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 7320b58467..368d53af77 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -104,6 +104,7 @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, ui= nt64_t *shared_perm); =20 void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow); void blk_set_allow_aio_context_change(BlockBackend *blk, bool allow); +void blk_set_disable_request_queuing(BlockBackend *blk, bool disable); void blk_iostatus_enable(BlockBackend *blk); bool blk_iostatus_is_enabled(const BlockBackend *blk); BlockDeviceIoStatus blk_iostatus(const BlockBackend *blk); diff --git a/block/backup.c b/block/backup.c index b26c22c4b8..4743c8f0bc 100644 --- a/block/backup.c +++ b/block/backup.c @@ -644,6 +644,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDr= iverState *bs, if (ret < 0) { goto error; } + blk_set_disable_request_queuing(job->target, true); =20 job->on_source_error =3D on_source_error; job->on_target_error =3D on_target_error; diff --git a/block/block-backend.c b/block/block-backend.c index fdd6b01ecf..c13c5c83b0 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -79,6 +79,9 @@ struct BlockBackend { QLIST_HEAD(, BlockBackendAioNotifier) aio_notifiers; =20 int quiesce_counter; + CoQueue queued_requests; + bool disable_request_queuing; + VMChangeStateEntry *vmsh; bool force_allow_inactivate; =20 @@ -339,6 +342,7 @@ BlockBackend *blk_new(AioContext *ctx, uint64_t perm, u= int64_t shared_perm) =20 block_acct_init(&blk->stats); =20 + qemu_co_queue_init(&blk->queued_requests); notifier_list_init(&blk->remove_bs_notifiers); notifier_list_init(&blk->insert_bs_notifiers); QLIST_INIT(&blk->aio_notifiers); @@ -1096,6 +1100,11 @@ void blk_set_allow_aio_context_change(BlockBackend *= blk, bool allow) blk->allow_aio_context_change =3D allow; } =20 +void blk_set_disable_request_queuing(BlockBackend *blk, bool disable) +{ + blk->disable_request_queuing =3D disable; +} + static int blk_check_byte_request(BlockBackend *blk, int64_t offset, size_t size) { @@ -1127,13 +1136,24 @@ static int blk_check_byte_request(BlockBackend *blk= , int64_t offset, return 0; } =20 +static void coroutine_fn blk_wait_while_drained(BlockBackend *blk) +{ + if (blk->quiesce_counter && !blk->disable_request_queuing) { + qemu_co_queue_wait(&blk->queued_requests, NULL); + } +} + int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { int ret; - BlockDriverState *bs =3D blk_bs(blk); + BlockDriverState *bs; =20 + blk_wait_while_drained(blk); + + /* Call blk_bs() only after waiting, the graph may have changed */ + bs =3D blk_bs(blk); trace_blk_co_preadv(blk, bs, offset, bytes, flags); =20 ret =3D blk_check_byte_request(blk, offset, bytes); @@ -1159,8 +1179,12 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, i= nt64_t offset, BdrvRequestFlags flags) { int ret; - BlockDriverState *bs =3D blk_bs(blk); + BlockDriverState *bs; =20 + blk_wait_while_drained(blk); + + /* Call blk_bs() only after waiting, the graph may have changed */ + bs =3D blk_bs(blk); trace_blk_co_pwritev(blk, bs, offset, bytes, flags); =20 ret =3D blk_check_byte_request(blk, offset, bytes); @@ -1349,6 +1373,12 @@ static void blk_aio_read_entry(void *opaque) BlkRwCo *rwco =3D &acb->rwco; QEMUIOVector *qiov =3D rwco->iobuf; =20 + if (rwco->blk->quiesce_counter) { + blk_dec_in_flight(rwco->blk); + blk_wait_while_drained(rwco->blk); + blk_inc_in_flight(rwco->blk); + } + assert(qiov->size =3D=3D acb->bytes); rwco->ret =3D blk_co_preadv(rwco->blk, rwco->offset, acb->bytes, qiov, rwco->flags); @@ -1361,6 +1391,12 @@ static void blk_aio_write_entry(void *opaque) BlkRwCo *rwco =3D &acb->rwco; QEMUIOVector *qiov =3D rwco->iobuf; =20 + if (rwco->blk->quiesce_counter) { + blk_dec_in_flight(rwco->blk); + blk_wait_while_drained(rwco->blk); + blk_inc_in_flight(rwco->blk); + } + assert(!qiov || qiov->size =3D=3D acb->bytes); rwco->ret =3D blk_co_pwritev(rwco->blk, rwco->offset, acb->bytes, qiov, rwco->flags); @@ -1482,6 +1518,8 @@ void blk_aio_cancel_async(BlockAIOCB *acb) =20 int blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf) { + blk_wait_while_drained(blk); + if (!blk_is_available(blk)) { return -ENOMEDIUM; } @@ -1522,7 +1560,11 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigne= d long int req, void *buf, =20 int blk_co_pdiscard(BlockBackend *blk, int64_t offset, int bytes) { - int ret =3D blk_check_byte_request(blk, offset, bytes); + int ret; + + blk_wait_while_drained(blk); + + ret =3D blk_check_byte_request(blk, offset, bytes); if (ret < 0) { return ret; } @@ -1532,6 +1574,8 @@ int blk_co_pdiscard(BlockBackend *blk, int64_t offset= , int bytes) =20 int blk_co_flush(BlockBackend *blk) { + blk_wait_while_drained(blk); + if (!blk_is_available(blk)) { return -ENOMEDIUM; } @@ -2232,6 +2276,9 @@ static void blk_root_drained_end(BdrvChild *child, in= t *drained_end_counter) if (blk->dev_ops && blk->dev_ops->drained_end) { blk->dev_ops->drained_end(blk->dev_opaque); } + while (qemu_co_enter_next(&blk->queued_requests, NULL)) { + /* Resume all queued requests */ + } } } =20 diff --git a/block/commit.c b/block/commit.c index 2c5a6d4ebc..408ae15389 100644 --- a/block/commit.c +++ b/block/commit.c @@ -350,6 +350,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, if (ret < 0) { goto fail; } + blk_set_disable_request_queuing(s->base, true); s->base_bs =3D base; =20 /* Required permissions are already taken with block_job_add_bdrv() */ @@ -358,6 +359,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, if (ret < 0) { goto fail; } + blk_set_disable_request_queuing(s->top, true); =20 s->backing_file_str =3D g_strdup(backing_file_str); s->on_error =3D on_error; diff --git a/block/mirror.c b/block/mirror.c index 642d6570cc..9b36391bb9 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1636,6 +1636,7 @@ static BlockJob *mirror_start_job( blk_set_force_allow_inactivate(s->target); } blk_set_allow_aio_context_change(s->target, true); + blk_set_disable_request_queuing(s->target, true); =20 s->replaces =3D g_strdup(replaces); s->on_source_error =3D on_source_error; diff --git a/blockjob.c b/blockjob.c index 20b7f557da..73d9f1ba2b 100644 --- a/blockjob.c +++ b/blockjob.c @@ -445,6 +445,9 @@ void *block_job_create(const char *job_id, const BlockJ= obDriver *driver, =20 bdrv_op_unblock(bs, BLOCK_OP_TYPE_DATAPLANE, job->blocker); =20 + /* Disable request queuing in the BlockBackend to avoid deadlocks on d= rain: + * The job reports that it's busy until it reaches a pause point. */ + blk_set_disable_request_queuing(blk, true); blk_set_allow_aio_context_change(blk, true); =20 /* Only set speed when necessary to avoid NotSupported error */ diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 9dffd86c47..468bbcc9a1 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -686,6 +686,7 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) &error_abort); s =3D bs->opaque; blk_insert_bs(blk, bs, &error_abort); + blk_set_disable_request_queuing(blk, true); =20 blk_set_aio_context(blk, ctx_a, &error_abort); aio_context_acquire(ctx_a); --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948976; cv=none; d=zoho.com; s=zohoarc; b=YhPgtel4DUpS8t/eAe+URxpXVdebKd6xHOfT1loRZDLEsmalTHnJ1SfdxRx69mSYKdCvyzMJwZ7ThU3pQPX7TzwtlZaS4wscFhsvi4tv4wlvdFVp95XBWVDAb1DT99uFyNolVoFuMnd3JeDp6OV75ggQX4dgQN5n1jWvbvVBM1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948976; 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=7FzVB2/JPfy0DKwmhUckKS8hd5rGoZVat14sPZJQCPg=; b=hSYTuL+M8Ri3tg6CbdSnLgPQ1SQ1IDYsoFtVFF3wMA0peobcjJL6Jj+oeaobB7ys2JlqWt8u29QyhTqK0Ner5l+P0ejR71np2flQUNyGy6agKTwtfHXb8tbdAXALMTsVrDQtKCEEXVzWToL0bPJTDzKpOutLrQEflV6m4dQa9nw= 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 1565948976795193.92065455926524; Fri, 16 Aug 2019 02:49:36 -0700 (PDT) Received: from localhost ([::1]:52634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYrX-0007EZ-J8 for importer@patchew.org; Fri, 16 Aug 2019 05:49:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59688) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYda-0000Ix-5D for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdY-0003vB-Tt for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18513) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdW-0003sl-HN; Fri, 16 Aug 2019 05:35:06 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6692308A958; Fri, 16 Aug 2019 09:35:05 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D2FD7DA4B; Fri, 16 Aug 2019 09:35:04 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:38 +0200 Message-Id: <20190816093439.14262-16-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 16 Aug 2019 09:35:05 +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] [PULL 15/16] qemu-img convert: Deprecate using -n and -o together 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" bdrv_create options specified with -o have no effect when skipping image creation with -n, so this doesn't make sense. Warn against the misuse and deprecate the combination so we can make it a hard error later. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Eric Blake --- qemu-img.c | 5 +++++ qemu-deprecated.texi | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 79983772de..d9321f6418 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2231,6 +2231,11 @@ static int img_convert(int argc, char **argv) goto fail_getopt; } =20 + if (skip_create && options) { + warn_report("-o has no effect when skipping image creation"); + warn_report("This will become an error in future QEMU versions."); + } + s.src_num =3D argc - optind - 1; out_filename =3D s.src_num >=3D 1 ? argv[argc - 1] : NULL; =20 diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index fff07bb2a3..f7680c08e1 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -305,6 +305,13 @@ to just export the entire image and then mount only /d= ev/nbd0p1 than it is to reinvoke @command{qemu-nbd -c /dev/nbd0} limited to just a subset of the image. =20 +@subsection qemu-img convert -n -o (since 4.2.0) + +All options specified in @option{-o} are image creation options, so +they have no effect when used with @option{-n} to skip image creation. +Silently ignored options can be confusing, so this combination of +options will be made an error in future versions. + @section Build system =20 @subsection Python 2 support (since 4.1.0) --=20 2.20.1 From nobody Mon May 6 21:54:06 2024 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=1565948758; cv=none; d=zoho.com; s=zohoarc; b=J+fAHxIS8e51dK+unP6q4AfEFhqtLFucNfWnQwfZP9MoMoyqEJ0brXOCzTBDbZe3DkCMhg5kfGOLYD371NjsL53YyO971usYr5MlFAGKxIOaxPIsBmS4pyp5nO6knMKSuOjPkW9B6andaM4pB3Nt08hWY4YGQgoVS+MzM6c2ZQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565948758; 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=H8rRuPZ6Qt7VsSU4H8No71CckHkEIw2Cp9AIioF7Ow0=; b=FiE2yNJ2s6hhfjJ95zXzJ6DvqF67Fi1BykN3vXEVO73MQG8V0P/XS3GDdbkjHHt/9hSIxDcf+QNZt85Fp+f2od0iTR8xt/HNVCCztopXYHSx2lHBIabH7YXkpUnN8E1QKsso4SZhQ2M8gtNYWi08noJRnA50p4oS8F4sPFguaZE= 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 1565948758686295.24367753166086; Fri, 16 Aug 2019 02:45:58 -0700 (PDT) Received: from localhost ([::1]:52606 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYo1-0004EX-E7 for importer@patchew.org; Fri, 16 Aug 2019 05:45:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59742) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hyYde-0000PE-6r for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hyYdc-00042n-L7 for qemu-devel@nongnu.org; Fri, 16 Aug 2019 05:35:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25870) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hyYdZ-0003uS-08; Fri, 16 Aug 2019 05:35:09 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 587FC308A9BE; Fri, 16 Aug 2019 09:35:08 +0000 (UTC) Received: from localhost.localdomain.com (dhcp-200-226.str.redhat.com [10.33.200.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24ED55C1D6; Fri, 16 Aug 2019 09:35:06 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 16 Aug 2019 11:34:39 +0200 Message-Id: <20190816093439.14262-17-kwolf@redhat.com> In-Reply-To: <20190816093439.14262-1-kwolf@redhat.com> References: <20190816093439.14262-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 16 Aug 2019 09:35:08 +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] [PULL 16/16] file-posix: Handle undetectable alignment 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Nir Soffer In some cases buf_align or request_alignment cannot be detected: 1. With Gluster, buf_align cannot be detected since the actual I/O is done on Gluster server, and qemu buffer alignment does not matter. Since we don't have alignment requirement, buf_align=3D1 is the best value. 2. With local XFS filesystem, buf_align cannot be detected if reading from unallocated area. In this we must align the buffer, but we don't know what is the correct size. Using the wrong alignment results in I/O error. 3. With Gluster backed by XFS, request_alignment cannot be detected if reading from unallocated area. In this case we need to use the correct alignment, and failing to do so results in I/O errors. 4. With NFS, the server does not use direct I/O, so both buf_align cannot be detected. In this case we don't need any alignment so we can use buf_align=3D1 and request_alignment=3D1. These cases seems to work when storage sector size is 512 bytes, because the current code starts checking align=3D512. If the check succeeds because alignment cannot be detected we use 512. But this does not work for storage with 4k sector size. To determine if we can detect the alignment, we probe first with align=3D1. If probing succeeds, maybe there are no alignment requirement (cases 1, 4) or we are probing unallocated area (cases 2, 3). Since we don't have any way to tell, we treat this as undetectable alignment. If probing with align=3D1 fails with EINVAL, but probing with one of the expected alignments succeeds, we know that we found a working alignment. Practically the alignment requirements are the same for buffer alignment, buffer length, and offset in file. So in case we cannot detect buf_align, we can use request alignment. If we cannot detect request alignment, we can fallback to a safe value. To use this logic, we probe first request alignment instead of buf_align. Here is a table showing the behaviour with current code (the value in parenthesis is the optimal value). Case Sector buf_align (opt) request_alignment (opt) result =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 512 512 (1) 512 (512) OK 1 4096 512 (1) 4096 (4096) FAIL ---------------------------------------------------------------------- 2 512 512 (512) 512 (512) OK 2 4096 512 (4096) 4096 (4096) FAIL ---------------------------------------------------------------------- 3 512 512 (1) 512 (512) OK 3 4096 512 (1) 512 (4096) FAIL ---------------------------------------------------------------------- 4 512 512 (1) 512 (1) OK 4 4096 512 (1) 512 (1) OK Same cases with this change: Case Sector buf_align (opt) request_alignment (opt) result =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 1 512 512 (1) 512 (512) OK 1 4096 4096 (1) 4096 (4096) OK ---------------------------------------------------------------------- 2 512 512 (512) 512 (512) OK 2 4096 4096 (4096) 4096 (4096) OK ---------------------------------------------------------------------- 3 512 4096 (1) 4096 (512) OK 3 4096 4096 (1) 4096 (4096) OK ---------------------------------------------------------------------- 4 512 4096 (1) 4096 (1) OK 4 4096 4096 (1) 4096 (1) OK I tested that provisioning VMs and copying disks on local XFS and Gluster with 4k bytes sector size work now, resolving bugs [1],[2]. I tested also on XFS, NFS, Gluster with 512 bytes sector size. [1] https://bugzilla.redhat.com/1737256 [2] https://bugzilla.redhat.com/1738657 Signed-off-by: Nir Soffer Signed-off-by: Kevin Wolf --- block/file-posix.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 4479cc7ab4..b8b4dad553 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -323,6 +323,7 @@ static void raw_probe_alignment(BlockDriverState *bs, i= nt fd, Error **errp) BDRVRawState *s =3D bs->opaque; char *buf; size_t max_align =3D MAX(MAX_BLOCKSIZE, getpagesize()); + size_t alignments[] =3D {1, 512, 1024, 2048, 4096}; =20 /* For SCSI generic devices the alignment is not really used. With buffered I/O, we don't have any restrictions. */ @@ -349,25 +350,38 @@ static void raw_probe_alignment(BlockDriverState *bs,= int fd, Error **errp) } #endif =20 - /* If we could not get the sizes so far, we can only guess them */ - if (!s->buf_align) { + /* + * If we could not get the sizes so far, we can only guess them. First= try + * to detect request alignment, since it is more likely to succeed. Th= en + * try to detect buf_align, which cannot be detected in some cases (e.= g. + * Gluster). If buf_align cannot be detected, we fallback to the value= of + * request_alignment. + */ + + if (!bs->bl.request_alignment) { + int i; size_t align; - buf =3D qemu_memalign(max_align, 2 * max_align); - for (align =3D 512; align <=3D max_align; align <<=3D 1) { - if (raw_is_io_aligned(fd, buf + align, max_align)) { - s->buf_align =3D align; + buf =3D qemu_memalign(max_align, max_align); + for (i =3D 0; i < ARRAY_SIZE(alignments); i++) { + align =3D alignments[i]; + if (raw_is_io_aligned(fd, buf, align)) { + /* Fallback to safe value. */ + bs->bl.request_alignment =3D (align !=3D 1) ? align : max_= align; break; } } qemu_vfree(buf); } =20 - if (!bs->bl.request_alignment) { + if (!s->buf_align) { + int i; size_t align; - buf =3D qemu_memalign(s->buf_align, max_align); - for (align =3D 512; align <=3D max_align; align <<=3D 1) { - if (raw_is_io_aligned(fd, buf, align)) { - bs->bl.request_alignment =3D align; + buf =3D qemu_memalign(max_align, 2 * max_align); + for (i =3D 0; i < ARRAY_SIZE(alignments); i++) { + align =3D alignments[i]; + if (raw_is_io_aligned(fd, buf + align, max_align)) { + /* Fallback to request_aligment. */ + s->buf_align =3D (align !=3D 1) ? align : bs->bl.request_a= lignment; break; } } --=20 2.20.1