4 # Test streaming with throttle nodes on top
6 # Copyright (C) 2022 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 from typing import List
26 from iotests import qemu_img_create, qemu_io
29 image_size = 256 * 1024 * 1024
30 base_img = os.path.join(iotests.test_dir, 'base.img')
31 top_img = os.path.join(iotests.test_dir, 'top.img')
34 class TcgVM(iotests.VM):
36 Variant of iotests.VM that uses -accel tcg. Simply using
37 iotests.VM.add_args('-accel', 'tcg') is not sufficient, because that will
38 put -accel qtest before -accel tcg, and -accel arguments are prioritized in
39 the order they appear.
42 def _base_args(self) -> List[str]:
43 # Put -accel tcg first so it takes precedence
44 return ['-accel', 'tcg'] + super()._base_args
47 class TestStreamWithThrottle(iotests.QMPTestCase):
48 def setUp(self) -> None:
50 Create a simple backing chain between two images, write something to
51 the base image. Attach them to the VM underneath two throttle nodes,
52 one of which has actually no limits set, but the other does. Then put
53 a virtio-blk device on top.
54 This test configuration has been taken from
55 https://gitlab.com/qemu-project/qemu/-/issues/1215
57 qemu_img_create('-f', iotests.imgfmt, base_img, str(image_size))
58 qemu_img_create('-f', iotests.imgfmt, '-b', base_img, '-F',
59 iotests.imgfmt, top_img, str(image_size))
61 # Write something to stream
62 qemu_io(base_img, '-c', f'write 0 {image_size}')
66 'node-name': 'throttled-node',
67 'throttle-group': 'thrgr-limited',
70 'throttle-group': 'thrgr-unlimited',
72 'driver': iotests.imgfmt,
73 'node-name': 'unthrottled-node',
82 # Issue 1215 is not reproducible in qtest mode, which is why we need to
83 # create an -accel tcg VM
85 self.vm.add_object('iothread,id=iothr0')
86 self.vm.add_object('throttle-group,id=thrgr-unlimited')
87 self.vm.add_object('throttle-group,id=thrgr-limited,'
88 'x-iops-total=10000,x-bps-total=104857600')
89 self.vm.add_blockdev(self.vm.qmp_to_opts(blockdev))
90 self.vm.add_device('virtio-blk,iothread=iothr0,drive=throttled-node')
91 if iotests.qemu_default_machine == 's390-ccw-virtio':
92 self.vm.add_args('-no-shutdown')
95 def tearDown(self) -> None:
100 def test_stream(self) -> None:
102 Do a simple stream beneath the two throttle nodes. Should complete
105 self.vm.cmd('block-stream',
107 device='unthrottled-node')
109 # Should succeed and not time out
111 self.vm.run_job('stream')
112 except asyncio.TimeoutError:
113 # VM may be stuck, kill it before tearDown()
118 if __name__ == '__main__':
119 # Must support backing images
120 iotests.main(supported_fmts=['qcow', 'qcow2', 'qed'],
121 supported_protocols=['file'],
122 required_fmts=['throttle'])