xref: /openbmc/qemu/tests/qemu-iotests/255 (revision 7d8140595f1e131935ba1c98a55af7d066660707)
17c477526SPhilippe Mathieu-Daudé#!/usr/bin/env python3
2ac6fb43eSKevin Wolf#
3ac6fb43eSKevin Wolf# Test commit job graph modifications while requests are active
4ac6fb43eSKevin Wolf#
5ac6fb43eSKevin Wolf# Copyright (C) 2019 Red Hat, Inc.
6ac6fb43eSKevin Wolf#
7ac6fb43eSKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
8ac6fb43eSKevin Wolf#
9ac6fb43eSKevin Wolf# This program is free software; you can redistribute it and/or modify
10ac6fb43eSKevin Wolf# it under the terms of the GNU General Public License as published by
11ac6fb43eSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
12ac6fb43eSKevin Wolf# (at your option) any later version.
13ac6fb43eSKevin Wolf#
14ac6fb43eSKevin Wolf# This program is distributed in the hope that it will be useful,
15ac6fb43eSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
16ac6fb43eSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17ac6fb43eSKevin Wolf# GNU General Public License for more details.
18ac6fb43eSKevin Wolf#
19ac6fb43eSKevin Wolf# You should have received a copy of the GNU General Public License
20ac6fb43eSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21ac6fb43eSKevin Wolf#
22ac6fb43eSKevin Wolf
23ac6fb43eSKevin Wolfimport iotests
24ac6fb43eSKevin Wolffrom iotests import imgfmt
25ac6fb43eSKevin Wolf
26*7d814059SJohn Snowiotests.script_initialize(supported_fmts=['qcow2'])
27ac6fb43eSKevin Wolf
2874f27eadSMax Reitziotests.log('Finishing a commit job with background reads')
2974f27eadSMax Reitziotests.log('============================================')
3074f27eadSMax Reitziotests.log('')
3174f27eadSMax Reitz
32ac6fb43eSKevin Wolfwith iotests.FilePath('t.qcow2') as disk_path, \
33ac6fb43eSKevin Wolf     iotests.FilePath('t.qcow2.mid') as mid_path, \
34ac6fb43eSKevin Wolf     iotests.FilePath('t.qcow2.base') as base_path, \
35ac6fb43eSKevin Wolf     iotests.VM() as vm:
36ac6fb43eSKevin Wolf
37ac6fb43eSKevin Wolf    iotests.log("=== Create backing chain and start VM ===")
38ac6fb43eSKevin Wolf    iotests.log("")
39ac6fb43eSKevin Wolf
40ac6fb43eSKevin Wolf    size = 128 * 1024 * 1024
41ac6fb43eSKevin Wolf    size_str = str(size)
42ac6fb43eSKevin Wolf
43ac6fb43eSKevin Wolf    iotests.create_image(base_path, size)
44ac6fb43eSKevin Wolf    iotests.qemu_img_log('create', '-f', iotests.imgfmt, mid_path, size_str)
45ac6fb43eSKevin Wolf    iotests.qemu_img_log('create', '-f', iotests.imgfmt, disk_path, size_str)
46ac6fb43eSKevin Wolf
47ac6fb43eSKevin Wolf    # Create a backing chain like this:
48ac6fb43eSKevin Wolf    # base <- [throttled: bps-read=4096] <- mid <- overlay
49ac6fb43eSKevin Wolf
50ac6fb43eSKevin Wolf    vm.add_object('throttle-group,x-bps-read=4096,id=throttle0')
51ac6fb43eSKevin Wolf    vm.add_blockdev('file,filename=%s,node-name=base' % (base_path))
52ac6fb43eSKevin Wolf    vm.add_blockdev('throttle,throttle-group=throttle0,file=base,node-name=throttled')
53ac6fb43eSKevin Wolf    vm.add_blockdev('file,filename=%s,node-name=mid-file' % (mid_path))
54ac6fb43eSKevin Wolf    vm.add_blockdev('qcow2,file=mid-file,node-name=mid,backing=throttled')
55ac6fb43eSKevin Wolf    vm.add_drive_raw('if=none,id=overlay,driver=qcow2,file=%s,backing=mid' % (disk_path))
56ac6fb43eSKevin Wolf
57ac6fb43eSKevin Wolf    vm.launch()
58ac6fb43eSKevin Wolf
59ac6fb43eSKevin Wolf    iotests.log("=== Start background read requests ===")
60ac6fb43eSKevin Wolf    iotests.log("")
61ac6fb43eSKevin Wolf
62ac6fb43eSKevin Wolf    def start_requests():
63ac6fb43eSKevin Wolf        vm.hmp_qemu_io('overlay', 'aio_read 0 4k')
64ac6fb43eSKevin Wolf        vm.hmp_qemu_io('overlay', 'aio_read 0 4k')
65ac6fb43eSKevin Wolf
66ac6fb43eSKevin Wolf    start_requests()
67ac6fb43eSKevin Wolf
68ac6fb43eSKevin Wolf    iotests.log("=== Run a commit job ===")
69ac6fb43eSKevin Wolf    iotests.log("")
70ac6fb43eSKevin Wolf
71ac6fb43eSKevin Wolf    result = vm.qmp_log('block-commit', job_id='job0', auto_finalize=False,
72ac6fb43eSKevin Wolf                        device='overlay', top_node='mid')
73ac6fb43eSKevin Wolf
74ac6fb43eSKevin Wolf    vm.run_job('job0', auto_finalize=False, pre_finalize=start_requests,
75ac6fb43eSKevin Wolf                auto_dismiss=True)
76ac6fb43eSKevin Wolf
77ac6fb43eSKevin Wolf    vm.shutdown()
7874f27eadSMax Reitz
7974f27eadSMax Reitziotests.log('')
8074f27eadSMax Reitziotests.log('Closing the VM while a job is being cancelled')
8174f27eadSMax Reitziotests.log('=============================================')
8274f27eadSMax Reitziotests.log('')
8374f27eadSMax Reitz
8474f27eadSMax Reitzwith iotests.FilePath('src.qcow2') as src_path, \
8574f27eadSMax Reitz     iotests.FilePath('dst.qcow2') as dst_path, \
8674f27eadSMax Reitz     iotests.VM() as vm:
8774f27eadSMax Reitz
8874f27eadSMax Reitz    iotests.log('=== Create images and start VM ===')
8974f27eadSMax Reitz    iotests.log('')
9074f27eadSMax Reitz
9174f27eadSMax Reitz    size = 128 * 1024 * 1024
9274f27eadSMax Reitz    size_str = str(size)
9374f27eadSMax Reitz
9474f27eadSMax Reitz    iotests.qemu_img_log('create', '-f', iotests.imgfmt, src_path, size_str)
9574f27eadSMax Reitz    iotests.qemu_img_log('create', '-f', iotests.imgfmt, dst_path, size_str)
9674f27eadSMax Reitz
9774f27eadSMax Reitz    iotests.log(iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write 0 1M',
9874f27eadSMax Reitz                                src_path),
9974f27eadSMax Reitz                filters=[iotests.filter_test_dir, iotests.filter_qemu_io])
10074f27eadSMax Reitz
10174f27eadSMax Reitz    vm.add_object('throttle-group,x-bps-read=4096,id=throttle0')
10274f27eadSMax Reitz
10374f27eadSMax Reitz    vm.add_blockdev('file,node-name=src-file,filename=%s' % (src_path))
10474f27eadSMax Reitz    vm.add_blockdev('%s,node-name=src,file=src-file' % (iotests.imgfmt))
10574f27eadSMax Reitz
10674f27eadSMax Reitz    vm.add_blockdev('file,node-name=dst-file,filename=%s' % (dst_path))
10774f27eadSMax Reitz    vm.add_blockdev('%s,node-name=dst,file=dst-file' % (iotests.imgfmt))
10874f27eadSMax Reitz
10974f27eadSMax Reitz    vm.add_blockdev('throttle,node-name=src-throttled,' +
11074f27eadSMax Reitz                    'throttle-group=throttle0,file=src')
11174f27eadSMax Reitz
11274f27eadSMax Reitz    vm.add_device('virtio-blk,drive=src-throttled')
11374f27eadSMax Reitz
11474f27eadSMax Reitz    vm.launch()
11574f27eadSMax Reitz
11674f27eadSMax Reitz    iotests.log('=== Start a mirror job ===')
11774f27eadSMax Reitz    iotests.log('')
11874f27eadSMax Reitz
11974f27eadSMax Reitz    vm.qmp_log('blockdev-mirror', job_id='job0', device='src-throttled',
12074f27eadSMax Reitz                                  target='dst', sync='full')
12174f27eadSMax Reitz
12274f27eadSMax Reitz    vm.qmp_log('block-job-cancel', device='job0')
12374f27eadSMax Reitz    vm.qmp_log('quit')
12474f27eadSMax Reitz
1254687133bSMax Reitz    vm.shutdown(has_quit=True)
126