xref: /openbmc/qemu/tests/qemu-iotests/255 (revision ac6fb43eae1f5029b51e0a3d975fe2111cc8b976)
1*ac6fb43eSKevin Wolf#!/usr/bin/env python
2*ac6fb43eSKevin Wolf#
3*ac6fb43eSKevin Wolf# Test commit job graph modifications while requests are active
4*ac6fb43eSKevin Wolf#
5*ac6fb43eSKevin Wolf# Copyright (C) 2019 Red Hat, Inc.
6*ac6fb43eSKevin Wolf#
7*ac6fb43eSKevin Wolf# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
8*ac6fb43eSKevin Wolf#
9*ac6fb43eSKevin Wolf# This program is free software; you can redistribute it and/or modify
10*ac6fb43eSKevin Wolf# it under the terms of the GNU General Public License as published by
11*ac6fb43eSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
12*ac6fb43eSKevin Wolf# (at your option) any later version.
13*ac6fb43eSKevin Wolf#
14*ac6fb43eSKevin Wolf# This program is distributed in the hope that it will be useful,
15*ac6fb43eSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
16*ac6fb43eSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*ac6fb43eSKevin Wolf# GNU General Public License for more details.
18*ac6fb43eSKevin Wolf#
19*ac6fb43eSKevin Wolf# You should have received a copy of the GNU General Public License
20*ac6fb43eSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
21*ac6fb43eSKevin Wolf#
22*ac6fb43eSKevin Wolf
23*ac6fb43eSKevin Wolfimport iotests
24*ac6fb43eSKevin Wolffrom iotests import imgfmt
25*ac6fb43eSKevin Wolf
26*ac6fb43eSKevin Wolfiotests.verify_image_format(supported_fmts=['qcow2'])
27*ac6fb43eSKevin Wolf
28*ac6fb43eSKevin Wolfdef blockdev_create(vm, options):
29*ac6fb43eSKevin Wolf    result = vm.qmp_log('blockdev-create',
30*ac6fb43eSKevin Wolf                        filters=[iotests.filter_qmp_testfiles],
31*ac6fb43eSKevin Wolf                        job_id='job0', options=options)
32*ac6fb43eSKevin Wolf
33*ac6fb43eSKevin Wolf    if 'return' in result:
34*ac6fb43eSKevin Wolf        assert result['return'] == {}
35*ac6fb43eSKevin Wolf        vm.run_job('job0')
36*ac6fb43eSKevin Wolf    iotests.log("")
37*ac6fb43eSKevin Wolf
38*ac6fb43eSKevin Wolfwith iotests.FilePath('t.qcow2') as disk_path, \
39*ac6fb43eSKevin Wolf     iotests.FilePath('t.qcow2.mid') as mid_path, \
40*ac6fb43eSKevin Wolf     iotests.FilePath('t.qcow2.base') as base_path, \
41*ac6fb43eSKevin Wolf     iotests.VM() as vm:
42*ac6fb43eSKevin Wolf
43*ac6fb43eSKevin Wolf    iotests.log("=== Create backing chain and start VM ===")
44*ac6fb43eSKevin Wolf    iotests.log("")
45*ac6fb43eSKevin Wolf
46*ac6fb43eSKevin Wolf    size = 128 * 1024 * 1024
47*ac6fb43eSKevin Wolf    size_str = str(size)
48*ac6fb43eSKevin Wolf
49*ac6fb43eSKevin Wolf    iotests.create_image(base_path, size)
50*ac6fb43eSKevin Wolf    iotests.qemu_img_log('create', '-f', iotests.imgfmt, mid_path, size_str)
51*ac6fb43eSKevin Wolf    iotests.qemu_img_log('create', '-f', iotests.imgfmt, disk_path, size_str)
52*ac6fb43eSKevin Wolf
53*ac6fb43eSKevin Wolf    # Create a backing chain like this:
54*ac6fb43eSKevin Wolf    # base <- [throttled: bps-read=4096] <- mid <- overlay
55*ac6fb43eSKevin Wolf
56*ac6fb43eSKevin Wolf    vm.add_object('throttle-group,x-bps-read=4096,id=throttle0')
57*ac6fb43eSKevin Wolf    vm.add_blockdev('file,filename=%s,node-name=base' % (base_path))
58*ac6fb43eSKevin Wolf    vm.add_blockdev('throttle,throttle-group=throttle0,file=base,node-name=throttled')
59*ac6fb43eSKevin Wolf    vm.add_blockdev('file,filename=%s,node-name=mid-file' % (mid_path))
60*ac6fb43eSKevin Wolf    vm.add_blockdev('qcow2,file=mid-file,node-name=mid,backing=throttled')
61*ac6fb43eSKevin Wolf    vm.add_drive_raw('if=none,id=overlay,driver=qcow2,file=%s,backing=mid' % (disk_path))
62*ac6fb43eSKevin Wolf
63*ac6fb43eSKevin Wolf    vm.launch()
64*ac6fb43eSKevin Wolf
65*ac6fb43eSKevin Wolf    iotests.log("=== Start background read requests ===")
66*ac6fb43eSKevin Wolf    iotests.log("")
67*ac6fb43eSKevin Wolf
68*ac6fb43eSKevin Wolf    def start_requests():
69*ac6fb43eSKevin Wolf        vm.hmp_qemu_io('overlay', 'aio_read 0 4k')
70*ac6fb43eSKevin Wolf        vm.hmp_qemu_io('overlay', 'aio_read 0 4k')
71*ac6fb43eSKevin Wolf
72*ac6fb43eSKevin Wolf    start_requests()
73*ac6fb43eSKevin Wolf
74*ac6fb43eSKevin Wolf    iotests.log("=== Run a commit job ===")
75*ac6fb43eSKevin Wolf    iotests.log("")
76*ac6fb43eSKevin Wolf
77*ac6fb43eSKevin Wolf    result = vm.qmp_log('block-commit', job_id='job0', auto_finalize=False,
78*ac6fb43eSKevin Wolf                        device='overlay', top_node='mid')
79*ac6fb43eSKevin Wolf
80*ac6fb43eSKevin Wolf    vm.run_job('job0', auto_finalize=False, pre_finalize=start_requests,
81*ac6fb43eSKevin Wolf                auto_dismiss=True)
82*ac6fb43eSKevin Wolf
83*ac6fb43eSKevin Wolf    vm.shutdown()
84