From nobody Thu Dec 18 13:36:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152061497581078.00267086865995; Fri, 9 Mar 2018 09:02:55 -0800 (PST) Received: from localhost ([::1]:46555 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euLPy-0004VE-UZ for importer@patchew.org; Fri, 09 Mar 2018 12:02:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1euKlS-0001hW-8t for qemu-devel@nongnu.org; Fri, 09 Mar 2018 11:21:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1euKlP-0007a8-4w for qemu-devel@nongnu.org; Fri, 09 Mar 2018 11:21:02 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44726 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1euKlL-0007Tl-8s; Fri, 09 Mar 2018 11:20:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5FA28182D0A; Fri, 9 Mar 2018 16:20:54 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-234.ams2.redhat.com [10.36.117.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31AB1215CDAA; Fri, 9 Mar 2018 16:20:54 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 9 Mar 2018 17:19:32 +0100 Message-Id: <20180309161933.8168-56-kwolf@redhat.com> In-Reply-To: <20180309161933.8168-1-kwolf@redhat.com> References: <20180309161933.8168-1-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Mar 2018 16:20:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 09 Mar 2018 16:20:54 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kwolf@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 55/56] iotests: Tweak 030 in order to trigger a race condition with parallel jobs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Alberto Garcia This patch tweaks TestParallelOps in iotest 030 so it allocates data in smaller regions (256KB/512KB instead of 512KB/1MB) and the block-stream job in test_stream_commit() only needs to copy data that is at the very end of the image. This way when the block-stream job is awakened it will finish right away without any chance of being stopped by block_job_sleep_ns(). This triggers the bug that was fixed by 3d5d319e1221082974711af1d09d82f and 1a63a907507fbbcfaee3f622907ec24 and is therefore a more useful test case for parallel block jobs. After this patch the aforementiond bug can also be reproduced with the test_stream_parallel() test case. Since with this change the stream job in test_stream_commit() finishes early, this patch introduces a similar test case where both jobs are slowed down so they can actually run in parallel. Signed-off-by: Alberto Garcia Cc: John Snow Message-id: 20180306130121.30243-1-berto@igalia.com Signed-off-by: Max Reitz --- tests/qemu-iotests/030 | 52 ++++++++++++++++++++++++++++++++++++++----= ---- tests/qemu-iotests/030.out | 4 ++-- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 index 457984b8e9..b5f88959aa 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -156,7 +156,7 @@ class TestSingleDrive(iotests.QMPTestCase): class TestParallelOps(iotests.QMPTestCase): num_ops =3D 4 # Number of parallel block-stream operations num_imgs =3D num_ops * 2 + 1 - image_len =3D num_ops * 1024 * 1024 + image_len =3D num_ops * 512 * 1024 imgs =3D [] =20 def setUp(self): @@ -176,14 +176,14 @@ class TestParallelOps(iotests.QMPTestCase): '-o', 'backing_file=3D%s' % self.imgs[i-1], self.imgs= [i]) =20 # Put data into the images we are copying data from - for i in range(self.num_imgs / 2): - img_index =3D i * 2 + 1 - # Alternate between 512k and 1M. + odd_img_indexes =3D [x for x in reversed(range(self.num_imgs)) if = x % 2 =3D=3D 1] + for i in range(len(odd_img_indexes)): + # Alternate between 256KB and 512KB. # This way jobs will not finish in the same order they were cr= eated - num_kb =3D 512 + 512 * (i % 2) + num_kb =3D 256 + 256 * (i % 2) qemu_io('-f', iotests.imgfmt, - '-c', 'write -P %d %d %d' % (i, i*1024*1024, num_kb * = 1024), - self.imgs[img_index]) + '-c', 'write -P 0xFF %dk %dk' % (i * 512, num_kb), + self.imgs[odd_img_indexes[i]]) =20 # Attach the drive to the VM self.vm =3D iotests.VM() @@ -318,12 +318,14 @@ class TestParallelOps(iotests.QMPTestCase): self.wait_until_completed(drive=3D'commit-drive0') =20 # Test a block-stream and a block-commit job in parallel - def test_stream_commit(self): + # Here the stream job is supposed to finish quickly in order to reprod= uce + # the scenario that triggers the bug fixed in 3d5d319e1221 and 1a63a90= 7507 + def test_stream_commit_1(self): self.assertLessEqual(8, self.num_imgs) self.assert_no_active_block_jobs() =20 # Stream from node0 into node2 - result =3D self.vm.qmp('block-stream', device=3D'node2', job_id=3D= 'node2') + result =3D self.vm.qmp('block-stream', device=3D'node2', base_node= =3D'node0', job_id=3D'node2') self.assert_qmp(result, 'return', {}) =20 # Commit from the active layer into node3 @@ -348,6 +350,38 @@ class TestParallelOps(iotests.QMPTestCase): =20 self.assert_no_active_block_jobs() =20 + # This is similar to test_stream_commit_1 but both jobs are slowed + # down so they can run in parallel for a little while. + def test_stream_commit_2(self): + self.assertLessEqual(8, self.num_imgs) + self.assert_no_active_block_jobs() + + # Stream from node0 into node4 + result =3D self.vm.qmp('block-stream', device=3D'node4', base_node= =3D'node0', job_id=3D'node4', speed=3D1024*1024) + self.assert_qmp(result, 'return', {}) + + # Commit from the active layer into node5 + result =3D self.vm.qmp('block-commit', device=3D'drive0', base=3Ds= elf.imgs[5], speed=3D1024*1024) + self.assert_qmp(result, 'return', {}) + + # Wait for all jobs to be finished. + pending_jobs =3D ['node4', 'drive0'] + while len(pending_jobs) > 0: + for event in self.vm.get_qmp_events(wait=3DTrue): + if event['event'] =3D=3D 'BLOCK_JOB_COMPLETED': + node_name =3D self.dictpath(event, 'data/device') + self.assertTrue(node_name in pending_jobs) + self.assert_qmp_absent(event, 'data/error') + pending_jobs.remove(node_name) + if event['event'] =3D=3D 'BLOCK_JOB_READY': + self.assert_qmp(event, 'data/device', 'drive0') + self.assert_qmp(event, 'data/type', 'commit') + self.assert_qmp_absent(event, 'data/error') + self.assertTrue('drive0' in pending_jobs) + self.vm.qmp('block-job-complete', device=3D'drive0') + + self.assert_no_active_block_jobs() + # Test the base_node parameter def test_stream_base_node_name(self): self.assert_no_active_block_jobs() diff --git a/tests/qemu-iotests/030.out b/tests/qemu-iotests/030.out index 391c8573ca..42314e9c00 100644 --- a/tests/qemu-iotests/030.out +++ b/tests/qemu-iotests/030.out @@ -1,5 +1,5 @@ -....................... +........................ ---------------------------------------------------------------------- -Ran 23 tests +Ran 24 tests =20 OK --=20 2.13.6