Philippe Mathieu-Daudé | 7c47752 | 2020-01-30 17:32:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Vladimir Sementsov-Ogievskiy | 9dd003a | 2021-01-16 16:44:19 +0300 | [diff] [blame] | 2 | # group: rw quick |
Max Reitz | 3e7a95f | 2018-04-21 15:29:29 +0200 | [diff] [blame] | 3 | # |
| 4 | # Copy-on-read tests using a COR filter node |
| 5 | # |
| 6 | # Copyright (C) 2018 Red Hat, Inc. |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | # This program is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | # GNU General Public License for more details. |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License |
| 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | # |
John Snow | 42a5009 | 2022-03-22 13:42:12 -0400 | [diff] [blame] | 21 | # Creator/Owner: Hanna Reitz <hreitz@redhat.com> |
Max Reitz | 3e7a95f | 2018-04-21 15:29:29 +0200 | [diff] [blame] | 22 | |
| 23 | import iotests |
John Snow | 72cfb93 | 2022-04-18 17:15:03 -0400 | [diff] [blame] | 24 | from iotests import log, qemu_img, qemu_io |
Max Reitz | 3e7a95f | 2018-04-21 15:29:29 +0200 | [diff] [blame] | 25 | |
| 26 | # Need backing file support |
John Snow | 7d81405 | 2020-03-30 20:00:11 -0400 | [diff] [blame] | 27 | iotests.script_initialize(supported_fmts=['qcow2', 'qcow', 'qed', 'vmdk'], |
| 28 | supported_platforms=['linux']) |
Max Reitz | 3e7a95f | 2018-04-21 15:29:29 +0200 | [diff] [blame] | 29 | |
| 30 | log('') |
| 31 | log('=== Copy-on-read across nodes ===') |
| 32 | log('') |
| 33 | |
| 34 | # The old copy-on-read mechanism without a filter node cannot request |
| 35 | # WRITE_UNCHANGED permissions for its child. Therefore it just tries |
| 36 | # to sneak its write by the usual permission system and holds its |
| 37 | # fingers crossed. However, that sneaking does not work so well when |
| 38 | # there is a filter node in the way: That will receive the write |
| 39 | # request and re-issue a new one to its child, which this time is a |
| 40 | # proper write request that will make the permission system cough -- |
| 41 | # unless there is someone at the top (like a guest device) that has |
| 42 | # requested write permissions. |
| 43 | # |
| 44 | # A COR filter node, however, can request the proper permissions for |
| 45 | # its child and therefore is not hit by this issue. |
| 46 | |
| 47 | with iotests.FilePath('base.img') as base_img_path, \ |
| 48 | iotests.FilePath('top.img') as top_img_path, \ |
| 49 | iotests.VM() as vm: |
| 50 | |
| 51 | log('--- Setting up images ---') |
| 52 | log('') |
| 53 | |
John Snow | fc272d3 | 2022-03-21 16:16:03 -0400 | [diff] [blame] | 54 | qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') |
John Snow | 72cfb93 | 2022-04-18 17:15:03 -0400 | [diff] [blame] | 55 | qemu_io(base_img_path, '-c', 'write -P 1 0M 1M') |
John Snow | fc272d3 | 2022-03-21 16:16:03 -0400 | [diff] [blame] | 56 | qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, |
| 57 | '-F', iotests.imgfmt, top_img_path) |
John Snow | 72cfb93 | 2022-04-18 17:15:03 -0400 | [diff] [blame] | 58 | qemu_io(top_img_path, '-c', 'write -P 2 1M 1M') |
Max Reitz | 3e7a95f | 2018-04-21 15:29:29 +0200 | [diff] [blame] | 59 | |
Max Reitz | e4ca4e9 | 2018-05-09 21:43:02 +0200 | [diff] [blame] | 60 | log('Done') |
Max Reitz | 3e7a95f | 2018-04-21 15:29:29 +0200 | [diff] [blame] | 61 | |
| 62 | log('') |
| 63 | log('--- Doing COR ---') |
| 64 | log('') |
| 65 | |
| 66 | # Compare with e.g. the following: |
| 67 | # vm.add_drive_raw('if=none,node-name=node0,copy-on-read=on,driver=raw,' \ |
| 68 | # 'file.driver=%s,file.file.filename=%s' % |
| 69 | # (iotests.imgfmt, top_img_path)) |
| 70 | # (Remove the blockdev-add instead.) |
| 71 | # ((Not tested here because it hits an assertion in the permission |
| 72 | # system.)) |
| 73 | |
| 74 | vm.launch() |
| 75 | |
| 76 | log(vm.qmp('blockdev-add', |
| 77 | node_name='node0', |
| 78 | driver='copy-on-read', |
| 79 | file={ |
| 80 | 'driver': 'raw', |
| 81 | 'file': { |
| 82 | 'driver': 'copy-on-read', |
| 83 | 'file': { |
| 84 | 'driver': 'raw', |
| 85 | 'file': { |
| 86 | 'driver': iotests.imgfmt, |
| 87 | 'file': { |
| 88 | 'driver': 'file', |
| 89 | 'filename': top_img_path |
| 90 | }, |
| 91 | 'backing': { |
| 92 | 'driver': iotests.imgfmt, |
| 93 | 'file': { |
| 94 | 'driver': 'file', |
| 95 | 'filename': base_img_path |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | })) |
| 102 | |
| 103 | # Trigger COR |
| 104 | log(vm.qmp('human-monitor-command', |
| 105 | command_line='qemu-io node0 "read 0 64M"')) |
| 106 | |
| 107 | vm.shutdown() |
| 108 | |
| 109 | log('') |
| 110 | log('--- Checking COR result ---') |
| 111 | log('') |
| 112 | |
John Snow | 72cfb93 | 2022-04-18 17:15:03 -0400 | [diff] [blame] | 113 | qemu_io(base_img_path, '-c', 'discard 0 64M') |
| 114 | qemu_io(top_img_path, '-c', 'read -P 1 0M 1M') |
| 115 | qemu_io(top_img_path, '-c', 'read -P 2 1M 1M') |
Max Reitz | e4ca4e9 | 2018-05-09 21:43:02 +0200 | [diff] [blame] | 116 | |
| 117 | log('Done') |