3 # Copy-on-read tests using a COR filter node
5 # Copyright (C) 2018 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Creator/Owner: Max Reitz <mreitz@redhat.com>
23 from iotests import log, qemu_img, qemu_io_silent
25 # Need backing file support
26 iotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'],
27 supported_platforms=['linux'])
30 log('=== Copy-on-read across nodes ===')
33 # The old copy-on-read mechanism without a filter node cannot request
34 # WRITE_UNCHANGED permissions for its child. Therefore it just tries
35 # to sneak its write by the usual permission system and holds its
36 # fingers crossed. However, that sneaking does not work so well when
37 # there is a filter node in the way: That will receive the write
38 # request and re-issue a new one to its child, which this time is a
39 # proper write request that will make the permission system cough --
40 # unless there is someone at the top (like a guest device) that has
41 # requested write permissions.
43 # A COR filter node, however, can request the proper permissions for
44 # its child and therefore is not hit by this issue.
46 with iotests.FilePath('base.img') as base_img_path, \
47 iotests.FilePath('top.img') as top_img_path, \
50 log('--- Setting up images ---')
53 assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') == 0
54 assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') == 0
55 assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path,
56 '-F', iotests.imgfmt, top_img_path) == 0
57 assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') == 0
62 log('--- Doing COR ---')
65 # Compare with e.g. the following:
66 # vm.add_drive_raw('if=none,node-name=node0,copy-on-read=on,driver=raw,' \
67 # 'file.driver=%s,file.file.filename=%s' %
68 # (iotests.imgfmt, top_img_path))
69 # (Remove the blockdev-add instead.)
70 # ((Not tested here because it hits an assertion in the permission
75 log(vm.qmp('blockdev-add',
77 driver='copy-on-read',
81 'driver': 'copy-on-read',
85 'driver': iotests.imgfmt,
88 'filename': top_img_path
91 'driver': iotests.imgfmt,
94 'filename': base_img_path
103 log(vm.qmp('human-monitor-command',
104 command_line='qemu-io node0 "read 0 64M"'))
109 log('--- Checking COR result ---')
112 assert qemu_io_silent(base_img_path, '-c', 'discard 0 64M') == 0
113 assert qemu_io_silent(top_img_path, '-c', 'read -P 1 0M 1M') == 0
114 assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') == 0