4 # Test what happens when a stream job does an unaligned prefetch read
5 # which requires padding while having a NULL qiov.
7 # Copyright (C) Proxmox Server Solutions GmbH
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from iotests import imgfmt, qemu_img_create, qemu_io, QMPTestCase
27 image_size = 1 * 1024 * 1024
28 cluster_size = 64 * 1024
29 base = os.path.join(iotests.test_dir, 'base.img')
30 top = os.path.join(iotests.test_dir, 'top.img')
32 class TestStreamUnalignedPrefetch(QMPTestCase):
33 def setUp(self) -> None:
36 - base image {base} with {cluster_size // 2} bytes allocated
37 - top image {top} without any data allocated and coarser
40 Attach a compress filter for the top image, because that
41 requires that the request alignment is the top image's cluster
44 qemu_img_create('-f', imgfmt,
45 '-o', 'cluster_size={}'.format(cluster_size // 2),
46 base, str(image_size))
47 qemu_io('-c', f'write 0 {cluster_size // 2}', base)
48 qemu_img_create('-f', imgfmt,
49 '-o', 'cluster_size={}'.format(cluster_size),
52 self.vm = iotests.VM()
53 self.vm.add_blockdev(self.vm.qmp_to_opts({
61 self.vm.add_blockdev(self.vm.qmp_to_opts({
63 'node-name': 'compress-top',
76 def tearDown(self) -> None:
81 def test_stream_unaligned_prefetch(self) -> None:
82 self.vm.cmd('block-stream', job_id='stream', device='compress-top')
85 if __name__ == '__main__':
86 iotests.main(supported_fmts=['qcow2'], supported_protocols=['file'])