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_silent
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 Max Reitz <mreitz@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 assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
47 assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0
48 assert qemu_io_silent(base_img_path, '-c', 'write -P 1 3M 1M') == 0
49 assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
50 '-F', iotests.imgfmt, mid_img_path) == 0
51 assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 2M 1M') == 0
52 assert qemu_io_silent(mid_img_path, '-c', 'write -P 3 4M 1M') == 0
53 assert qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path,
54 '-F', iotests.imgfmt, top_img_path) == 0
55 assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0
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 assert qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt,
111 assert qemu_io_silent(top_img_path, '-c', 'read -P 0 0 1M') == 0
112 assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0
113 assert qemu_io_silent(top_img_path, '-c', 'read -P 3 2M 1M') == 0
114 assert qemu_io_silent(top_img_path, '-c', 'read -P 0 3M 1M') == 0
115 assert qemu_io_silent(top_img_path, '-c', 'read -P 3 4M 1M') == 0