From nobody Sat May 18 18:12:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520341450345700.1505619123878; Tue, 6 Mar 2018 05:04:10 -0800 (PST) Received: from localhost ([::1]:55480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etCGH-0006Hl-Jw for importer@patchew.org; Tue, 06 Mar 2018 08:04:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etCEh-0005Um-R8 for qemu-devel@nongnu.org; Tue, 06 Mar 2018 08:02:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etCEe-0002Yp-OJ for qemu-devel@nongnu.org; Tue, 06 Mar 2018 08:02:31 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:52915) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1etCEe-0001em-BC; Tue, 06 Mar 2018 08:02:28 -0500 Received: from [194.100.51.2] (helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1etCE2-0000ph-1f; Tue, 06 Mar 2018 14:01:50 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1etCDi-0007sU-G3; Tue, 06 Mar 2018 15:01:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Message-Id:Date:Subject:Cc:To:From; bh=I49gFsh3Qz/qN6gzbAMTyl67T1gs2Hc75VJ04bKq4i0=; b=nSFP6vPaBonKO/fbqf76Cc5ADKBFLoRNDzYr+Kg6oIh7/jQx6e8wOm4tSX4jKb84QOR9gJ+RcCf7Ed86eeIBikzBSmFuAjdNjryD85s8r5pLjkU29ce1GqJEfPDjB2EzFyqUusbqDU6OE3VDJQYhFSXhzAlJy9Ss9h58+5Rw1+ntW2V8Togekeb6NM1f1PAHgnOlRJWY3Hy/7lFjobJetBVoogl5Kgtr7WPlMScWeJqoJtO/HGE+eXacIZhKVnw7rwpBNxAoEaQqoUTCZUOB29whVXKVQJIGijfI0c6VBUV85sZSqUPrh5yWWNmJF+DL95lUNWf0Q3OWQQ2+9Iymbw==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 15:01:21 +0200 Message-Id: <20180306130121.30243-1-berto@igalia.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v4] 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: Kevin Wolf , John Snow , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This 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 --- v4: Mention that commit 1a63a907507fbbcfaee3f622907ec24 also contributes to solve the original bug (both commits need to reverted in order to reproduce this bug reliably). Rewrite the loop that writes data into the images to make it more readable. --- 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.11.0