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