| 1 | #!/usr/bin/env python3 |
| 2 | # group: rw quick |
| 3 | # |
| 4 | # Copy-on-read tests using a COR filter with a bottom node |
| 5 | # |
| 6 | # Copyright (C) 2018 Red Hat, Inc. |
| 7 | # Copyright (c) 2020 Virtuozzo International GmbH |
| 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 | |
| 23 | import iotests |
| 24 | from iotests import log, qemu_img, qemu_io |
| 25 | |
| 26 | # Need backing file support |
| 27 | iotests.script_initialize(supported_fmts=['qcow2'], |
| 28 | supported_platforms=['linux'], |
| 29 | require_hmp=True) |
| 30 | |
| 31 | log('') |
| 32 | log('=== Copy-on-read across nodes ===') |
| 33 | log('') |
| 34 | |
| 35 | # This test is similar to the 216 one by Hanna Reitz <hreitz@redhat.com> |
| 36 | # The difference is that this test case involves a bottom node to the |
| 37 | # COR filter driver. |
| 38 | |
| 39 | with iotests.FilePath('base.img') as base_img_path, \ |
| 40 | iotests.FilePath('mid.img') as mid_img_path, \ |
| 41 | iotests.FilePath('top.img') as top_img_path, \ |
| 42 | iotests.VM() as vm: |
| 43 | |
| 44 | log('--- Setting up images ---') |
| 45 | log('') |
| 46 | |
| 47 | qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') |
| 48 | qemu_io(base_img_path, '-c', 'write -P 1 0M 1M') |
| 49 | qemu_io(base_img_path, '-c', 'write -P 1 3M 1M') |
| 50 | qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, |
| 51 | '-F', iotests.imgfmt, mid_img_path) |
| 52 | qemu_io(mid_img_path, '-c', 'write -P 3 2M 1M') |
| 53 | qemu_io(mid_img_path, '-c', 'write -P 3 4M 1M') |
| 54 | qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, |
| 55 | '-F', iotests.imgfmt, top_img_path) |
| 56 | qemu_io(top_img_path, '-c', 'write -P 2 1M 1M') |
| 57 | |
| 58 | # 0 1 2 3 4 |
| 59 | # top 2 |
| 60 | # mid 3 3 |
| 61 | # base 1 1 |
| 62 | |
| 63 | log('Done') |
| 64 | |
| 65 | log('') |
| 66 | log('--- Doing COR ---') |
| 67 | log('') |
| 68 | |
| 69 | vm.launch() |
| 70 | |
| 71 | log(vm.qmp('blockdev-add', |
| 72 | node_name='node0', |
| 73 | driver='copy-on-read', |
| 74 | bottom='node2', |
| 75 | file={ |
| 76 | 'driver': iotests.imgfmt, |
| 77 | 'file': { |
| 78 | 'driver': 'file', |
| 79 | 'filename': top_img_path |
| 80 | }, |
| 81 | 'backing': { |
| 82 | 'node-name': 'node2', |
| 83 | 'driver': iotests.imgfmt, |
| 84 | 'file': { |
| 85 | 'driver': 'file', |
| 86 | 'filename': mid_img_path |
| 87 | }, |
| 88 | 'backing': { |
| 89 | 'driver': iotests.imgfmt, |
| 90 | 'file': { |
| 91 | 'driver': 'file', |
| 92 | 'filename': base_img_path |
| 93 | } |
| 94 | }, |
| 95 | } |
| 96 | })) |
| 97 | |
| 98 | # Trigger COR |
| 99 | log(vm.qmp('human-monitor-command', |
| 100 | command_line='qemu-io node0 "read 0 5M"')) |
| 101 | |
| 102 | vm.shutdown() |
| 103 | |
| 104 | log('') |
| 105 | log('--- Checking COR result ---') |
| 106 | log('') |
| 107 | |
| 108 | # Detach backing to check that we can read the data from the top level now |
| 109 | qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, top_img_path) |
| 110 | |
| 111 | qemu_io(top_img_path, '-c', 'read -P 0 0 1M') |
| 112 | qemu_io(top_img_path, '-c', 'read -P 2 1M 1M') |
| 113 | qemu_io(top_img_path, '-c', 'read -P 3 2M 1M') |
| 114 | qemu_io(top_img_path, '-c', 'read -P 0 3M 1M') |
| 115 | qemu_io(top_img_path, '-c', 'read -P 3 4M 1M') |
| 116 | |
| 117 | log('Done') |