4 # Copy-on-read tests using a COR filter with a bottom node
6 # Copyright (C) 2018 Red Hat, Inc.
7 # Copyright (c) 2020 Virtuozzo International GmbH
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.
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.
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/>.
24 from iotests import log, qemu_img, qemu_io
26 # Need backing file support
27 iotests.script_initialize(supported_fmts=['qcow2'],
28 supported_platforms=['linux'])
31 log('=== Copy-on-read across nodes ===')
34 # This test is similar to the 216 one by Hanna Reitz <hreitz@redhat.com>
35 # The difference is that this test case involves a bottom node to the
38 with iotests.FilePath('base.img') as base_img_path, \
39 iotests.FilePath('mid.img') as mid_img_path, \
40 iotests.FilePath('top.img') as top_img_path, \
43 log('--- Setting up images ---')
46 qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M')
47 qemu_io(base_img_path, '-c', 'write -P 1 0M 1M')
48 qemu_io(base_img_path, '-c', 'write -P 1 3M 1M')
49 qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
50 '-F', iotests.imgfmt, mid_img_path)
51 qemu_io(mid_img_path, '-c', 'write -P 3 2M 1M')
52 qemu_io(mid_img_path, '-c', 'write -P 3 4M 1M')
53 qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path,
54 '-F', iotests.imgfmt, top_img_path)
55 qemu_io(top_img_path, '-c', 'write -P 2 1M 1M')
65 log('--- Doing COR ---')
70 log(vm.qmp('blockdev-add',
72 driver='copy-on-read',
75 'driver': iotests.imgfmt,
78 'filename': top_img_path
82 'driver': iotests.imgfmt,
85 'filename': mid_img_path
88 'driver': iotests.imgfmt,
91 'filename': base_img_path
98 log(vm.qmp('human-monitor-command',
99 command_line='qemu-io node0 "read 0 5M"'))
104 log('--- Checking COR result ---')
107 # Detach backing to check that we can read the data from the top level now
108 qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, top_img_path)
110 qemu_io(top_img_path, '-c', 'read -P 0 0 1M')
111 qemu_io(top_img_path, '-c', 'read -P 2 1M 1M')
112 qemu_io(top_img_path, '-c', 'read -P 3 2M 1M')
113 qemu_io(top_img_path, '-c', 'read -P 0 3M 1M')
114 qemu_io(top_img_path, '-c', 'read -P 3 4M 1M')