From nobody Fri Dec 19 18:53:02 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.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=1608305973; cv=none; d=zohomail.com; s=zohoarc; b=SA2HwIMm1gszv02DV3Z3efe3emueQcjfIRMKZzhCXbxjY4C8URROmQG+CnMMbN3JFPfroHE73Jk/iME5DPGfydYTAK1L32D2KBAGafdZy2kbNpAsj9U3GOy6YTGzRvCENbAyQBC9px+DO93heKjC6JVq90wEUIb6wHyhaGnmJnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608305973; h=Content-Type: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; bh=6ErUEnaNKG6/qSd1Y8m/jb6ba8DX2JHoW//aeqtNNhg=; b=f9sSoay+5Ox/hAikfJLkVqD0/SO/7G9cyycRgPIFntHp+GTNiEVYG+Ka6ectw3b47TNmi7tEX9JeedmzSe0ttvvrHcUhyj17xSIrnFVn1FhE3NRbzbPHDbNsoIuR7++WorQVfzV5xm4qYkHtYn+JSUT/opOaB4TE1GVWFq2ZLxg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.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 1608305973289984.1412303442025; Fri, 18 Dec 2020 07:39:33 -0800 (PST) Received: from localhost ([::1]:60702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kqHZh-00035B-UL for importer@patchew.org; Fri, 18 Dec 2020 10:21:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kqHRs-0002eC-Um for qemu-devel@nongnu.org; Fri, 18 Dec 2020 10:13:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48055) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kqHRm-0005RN-Hb for qemu-devel@nongnu.org; Fri, 18 Dec 2020 10:13:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-182-IOmWYGXmO8OeNuXdUo5yAw-1; Fri, 18 Dec 2020 10:13:29 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 918CA1005D4E; Fri, 18 Dec 2020 15:13:28 +0000 (UTC) Received: from localhost (ovpn-114-84.ams2.redhat.com [10.36.114.84]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0666C2998C; Fri, 18 Dec 2020 15:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608304413; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ErUEnaNKG6/qSd1Y8m/jb6ba8DX2JHoW//aeqtNNhg=; b=CYvsghTa9JO7k80Y8wNLiSob5sBsArkFBOwrUm6NR9IODGwHedOIHiZn0Dulr0d8nPwCmi Fob7DrTyHqUdzfxTdpjy2oewrohQeR9ds4JSIo2d0NmAOINfqGmluAGwKHtaErjH5iDqON XvJFQ+CEvxbf/PDU/9ePKf/fUsGkvrQ= X-MC-Unique: IOmWYGXmO8OeNuXdUo5yAw-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PULL 16/30] iotests: add 298 to test new preallocate filter driver Date: Fri, 18 Dec 2020 16:12:35 +0100 Message-Id: <20201218151249.715731-17-mreitz@redhat.com> In-Reply-To: <20201218151249.715731-1-mreitz@redhat.com> References: <20201218151249.715731-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=63.128.21.124; envelope-from=mreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Peter Maydell , qemu-devel@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) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20201021145859.11201-13-vsementsov@virtuozzo.com> Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- tests/qemu-iotests/298 | 186 +++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/298.out | 5 + tests/qemu-iotests/group | 1 + 3 files changed, 192 insertions(+) create mode 100644 tests/qemu-iotests/298 create mode 100644 tests/qemu-iotests/298.out diff --git a/tests/qemu-iotests/298 b/tests/qemu-iotests/298 new file mode 100644 index 0000000000..d535946b5f --- /dev/null +++ b/tests/qemu-iotests/298 @@ -0,0 +1,186 @@ +#!/usr/bin/env python3 +# +# Test for preallocate filter +# +# Copyright (c) 2020 Virtuozzo International GmbH. +# +# 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 . +# + +import os +import iotests + +MiB =3D 1024 * 1024 +disk =3D os.path.join(iotests.test_dir, 'disk') +overlay =3D os.path.join(iotests.test_dir, 'overlay') +refdisk =3D os.path.join(iotests.test_dir, 'refdisk') +drive_opts =3D f'node-name=3Ddisk,driver=3D{iotests.imgfmt},' \ + f'file.node-name=3Dfilter,file.driver=3Dpreallocate,' \ + f'file.file.node-name=3Dfile,file.file.filename=3D{disk}' + + +class TestPreallocateBase(iotests.QMPTestCase): + def setUp(self): + iotests.qemu_img_create('-f', iotests.imgfmt, disk, str(10 * MiB)) + + def tearDown(self): + try: + self.check_small() + check =3D iotests.qemu_img_check(disk) + self.assertFalse('leaks' in check) + self.assertFalse('corruptions' in check) + self.assertEqual(check['check-errors'], 0) + finally: + os.remove(disk) + + def check_big(self): + self.assertTrue(os.path.getsize(disk) > 100 * MiB) + + def check_small(self): + self.assertTrue(os.path.getsize(disk) < 10 * MiB) + + +class TestQemuImg(TestPreallocateBase): + def test_qemu_img(self): + p =3D iotests.QemuIoInteractive('--image-opts', drive_opts) + + p.cmd('write 0 1M') + p.cmd('flush') + + self.check_big() + + p.close() + + +class TestPreallocateFilter(TestPreallocateBase): + def setUp(self): + super().setUp() + self.vm =3D iotests.VM().add_drive(path=3DNone, opts=3Ddrive_opts) + self.vm.launch() + + def tearDown(self): + self.vm.shutdown() + super().tearDown() + + def test_prealloc(self): + self.vm.hmp_qemu_io('drive0', 'write 0 1M') + self.check_big() + + def test_external_snapshot(self): + self.test_prealloc() + + result =3D self.vm.qmp('blockdev-snapshot-sync', node_name=3D'disk= ', + snapshot_file=3Doverlay, + snapshot_node_name=3D'overlay') + self.assert_qmp(result, 'return', {}) + + # on reopen to r-o base preallocation should be dropped + self.check_small() + + self.vm.hmp_qemu_io('drive0', 'write 1M 1M') + + result =3D self.vm.qmp('block-commit', device=3D'overlay') + self.assert_qmp(result, 'return', {}) + self.complete_and_wait() + + # commit of new megabyte should trigger preallocation + self.check_big() + + def test_reopen_opts(self): + result =3D self.vm.qmp('x-blockdev-reopen', **{ + 'node-name': 'disk', + 'driver': iotests.imgfmt, + 'file': { + 'node-name': 'filter', + 'driver': 'preallocate', + 'prealloc-size': 20 * MiB, + 'prealloc-align': 5 * MiB, + 'file': { + 'node-name': 'file', + 'driver': 'file', + 'filename': disk + } + } + }) + self.assert_qmp(result, 'return', {}) + + self.vm.hmp_qemu_io('drive0', 'write 0 1M') + self.assertTrue(os.path.getsize(disk) =3D=3D 25 * MiB) + + +class TestTruncate(iotests.QMPTestCase): + def setUp(self): + iotests.qemu_img_create('-f', iotests.imgfmt, disk, str(10 * MiB)) + iotests.qemu_img_create('-f', iotests.imgfmt, refdisk, str(10 * Mi= B)) + + def tearDown(self): + os.remove(disk) + os.remove(refdisk) + + def do_test(self, prealloc_mode, new_size): + ret =3D iotests.qemu_io_silent('--image-opts', '-c', 'write 0 10M'= , '-c', + f'truncate -m {prealloc_mode} {new_si= ze}', + drive_opts) + self.assertEqual(ret, 0) + + ret =3D iotests.qemu_io_silent('-f', iotests.imgfmt, '-c', 'write = 0 10M', + '-c', + f'truncate -m {prealloc_mode} {new_si= ze}', + refdisk) + self.assertEqual(ret, 0) + + stat =3D os.stat(disk) + refstat =3D os.stat(refdisk) + + # Probably we'll want preallocate filter to keep align to cluster = when + # shrink preallocation, so, ignore small differece + self.assertLess(abs(stat.st_size - refstat.st_size), 64 * 1024) + + # Preallocate filter may leak some internal clusters (for example,= if + # guest write far over EOF, skipping some clusters - they will rem= ain + # fallocated, preallocate filter don't care about such leaks, it d= rops + # only trailing preallocation. + self.assertLess(abs(stat.st_blocks - refstat.st_blocks) * 512, + 1024 * 1024) + + def test_real_shrink(self): + self.do_test('off', '5M') + + def test_truncate_inside_preallocated_area__falloc(self): + self.do_test('falloc', '50M') + + def test_truncate_inside_preallocated_area__metadata(self): + self.do_test('metadata', '50M') + + def test_truncate_inside_preallocated_area__full(self): + self.do_test('full', '50M') + + def test_truncate_inside_preallocated_area__off(self): + self.do_test('off', '50M') + + def test_truncate_over_preallocated_area__falloc(self): + self.do_test('falloc', '150M') + + def test_truncate_over_preallocated_area__metadata(self): + self.do_test('metadata', '150M') + + def test_truncate_over_preallocated_area__full(self): + self.do_test('full', '150M') + + def test_truncate_over_preallocated_area__off(self): + self.do_test('off', '150M') + + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D['qcow2'], required_fmts=3D['preallocate= ']) diff --git a/tests/qemu-iotests/298.out b/tests/qemu-iotests/298.out new file mode 100644 index 0000000000..fa16b5ccef --- /dev/null +++ b/tests/qemu-iotests/298.out @@ -0,0 +1,5 @@ +............. +---------------------------------------------------------------------- +Ran 13 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 9a8394b4cd..614d58369e 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -307,6 +307,7 @@ 295 rw 296 rw 297 meta +298 299 auto quick 300 migration 301 backing quick --=20 2.29.2