blob: 4a4818bafbf918ddfb520d0a312ee5c92b2d0309 [file] [log] [blame]
Philippe Mathieu-Daudé7c477522020-01-30 17:32:30 +01001#!/usr/bin/env python3
Kevin Wolfac6fb432019-05-21 20:35:52 +02002#
3# Test commit job graph modifications while requests are active
4#
5# Copyright (C) 2019 Red Hat, Inc.
6#
7# Creator/Owner: Kevin Wolf <kwolf@redhat.com>
8#
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.
13#
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.
18#
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/>.
21#
22
23import iotests
24from iotests import imgfmt
25
26iotests.verify_image_format(supported_fmts=['qcow2'])
27
Max Reitz74f27ea2019-05-22 16:40:37 +020028iotests.log('Finishing a commit job with background reads')
29iotests.log('============================================')
30iotests.log('')
31
Kevin Wolfac6fb432019-05-21 20:35:52 +020032with iotests.FilePath('t.qcow2') as disk_path, \
33 iotests.FilePath('t.qcow2.mid') as mid_path, \
34 iotests.FilePath('t.qcow2.base') as base_path, \
35 iotests.VM() as vm:
36
37 iotests.log("=== Create backing chain and start VM ===")
38 iotests.log("")
39
40 size = 128 * 1024 * 1024
41 size_str = str(size)
42
43 iotests.create_image(base_path, size)
44 iotests.qemu_img_log('create', '-f', iotests.imgfmt, mid_path, size_str)
45 iotests.qemu_img_log('create', '-f', iotests.imgfmt, disk_path, size_str)
46
47 # Create a backing chain like this:
48 # base <- [throttled: bps-read=4096] <- mid <- overlay
49
50 vm.add_object('throttle-group,x-bps-read=4096,id=throttle0')
51 vm.add_blockdev('file,filename=%s,node-name=base' % (base_path))
52 vm.add_blockdev('throttle,throttle-group=throttle0,file=base,node-name=throttled')
53 vm.add_blockdev('file,filename=%s,node-name=mid-file' % (mid_path))
54 vm.add_blockdev('qcow2,file=mid-file,node-name=mid,backing=throttled')
55 vm.add_drive_raw('if=none,id=overlay,driver=qcow2,file=%s,backing=mid' % (disk_path))
56
57 vm.launch()
58
59 iotests.log("=== Start background read requests ===")
60 iotests.log("")
61
62 def start_requests():
63 vm.hmp_qemu_io('overlay', 'aio_read 0 4k')
64 vm.hmp_qemu_io('overlay', 'aio_read 0 4k')
65
66 start_requests()
67
68 iotests.log("=== Run a commit job ===")
69 iotests.log("")
70
71 result = vm.qmp_log('block-commit', job_id='job0', auto_finalize=False,
72 device='overlay', top_node='mid')
73
74 vm.run_job('job0', auto_finalize=False, pre_finalize=start_requests,
75 auto_dismiss=True)
76
77 vm.shutdown()
Max Reitz74f27ea2019-05-22 16:40:37 +020078
79iotests.log('')
80iotests.log('Closing the VM while a job is being cancelled')
81iotests.log('=============================================')
82iotests.log('')
83
84with iotests.FilePath('src.qcow2') as src_path, \
85 iotests.FilePath('dst.qcow2') as dst_path, \
86 iotests.VM() as vm:
87
88 iotests.log('=== Create images and start VM ===')
89 iotests.log('')
90
91 size = 128 * 1024 * 1024
92 size_str = str(size)
93
94 iotests.qemu_img_log('create', '-f', iotests.imgfmt, src_path, size_str)
95 iotests.qemu_img_log('create', '-f', iotests.imgfmt, dst_path, size_str)
96
97 iotests.log(iotests.qemu_io('-f', iotests.imgfmt, '-c', 'write 0 1M',
98 src_path),
99 filters=[iotests.filter_test_dir, iotests.filter_qemu_io])
100
101 vm.add_object('throttle-group,x-bps-read=4096,id=throttle0')
102
103 vm.add_blockdev('file,node-name=src-file,filename=%s' % (src_path))
104 vm.add_blockdev('%s,node-name=src,file=src-file' % (iotests.imgfmt))
105
106 vm.add_blockdev('file,node-name=dst-file,filename=%s' % (dst_path))
107 vm.add_blockdev('%s,node-name=dst,file=dst-file' % (iotests.imgfmt))
108
109 vm.add_blockdev('throttle,node-name=src-throttled,' +
110 'throttle-group=throttle0,file=src')
111
112 vm.add_device('virtio-blk,drive=src-throttled')
113
114 vm.launch()
115
116 iotests.log('=== Start a mirror job ===')
117 iotests.log('')
118
119 vm.qmp_log('blockdev-mirror', job_id='job0', device='src-throttled',
120 target='dst', sync='full')
121
122 vm.qmp_log('block-job-cancel', device='job0')
123 vm.qmp_log('quit')
124
Max Reitz46871332019-07-19 11:26:17 +0200125 vm.shutdown(has_quit=True)