1b6e0985aSAndrey Shinkevich#!/usr/bin/env python3 2b6e0985aSAndrey Shinkevich# group: rw quick 3b6e0985aSAndrey Shinkevich# 4b6e0985aSAndrey Shinkevich# Copy-on-read tests using a COR filter with a bottom node 5b6e0985aSAndrey Shinkevich# 6b6e0985aSAndrey Shinkevich# Copyright (C) 2018 Red Hat, Inc. 7b6e0985aSAndrey Shinkevich# Copyright (c) 2020 Virtuozzo International GmbH 8b6e0985aSAndrey Shinkevich# 9b6e0985aSAndrey Shinkevich# This program is free software; you can redistribute it and/or modify 10b6e0985aSAndrey Shinkevich# it under the terms of the GNU General Public License as published by 11b6e0985aSAndrey Shinkevich# the Free Software Foundation; either version 2 of the License, or 12b6e0985aSAndrey Shinkevich# (at your option) any later version. 13b6e0985aSAndrey Shinkevich# 14b6e0985aSAndrey Shinkevich# This program is distributed in the hope that it will be useful, 15b6e0985aSAndrey Shinkevich# but WITHOUT ANY WARRANTY; without even the implied warranty of 16b6e0985aSAndrey Shinkevich# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17b6e0985aSAndrey Shinkevich# GNU General Public License for more details. 18b6e0985aSAndrey Shinkevich# 19b6e0985aSAndrey Shinkevich# You should have received a copy of the GNU General Public License 20b6e0985aSAndrey Shinkevich# along with this program. If not, see <http://www.gnu.org/licenses/>. 21b6e0985aSAndrey Shinkevich# 22b6e0985aSAndrey Shinkevich 23b6e0985aSAndrey Shinkevichimport iotests 24*72cfb937SJohn Snowfrom iotests import log, qemu_img, qemu_io 25b6e0985aSAndrey Shinkevich 26b6e0985aSAndrey Shinkevich# Need backing file support 27b6e0985aSAndrey Shinkevichiotests.script_initialize(supported_fmts=['qcow2'], 28b6e0985aSAndrey Shinkevich supported_platforms=['linux']) 29b6e0985aSAndrey Shinkevich 30b6e0985aSAndrey Shinkevichlog('') 31b6e0985aSAndrey Shinkevichlog('=== Copy-on-read across nodes ===') 32b6e0985aSAndrey Shinkevichlog('') 33b6e0985aSAndrey Shinkevich 3442a5009dSJohn Snow# This test is similar to the 216 one by Hanna Reitz <hreitz@redhat.com> 35b6e0985aSAndrey Shinkevich# The difference is that this test case involves a bottom node to the 36b6e0985aSAndrey Shinkevich# COR filter driver. 37b6e0985aSAndrey Shinkevich 38b6e0985aSAndrey Shinkevichwith iotests.FilePath('base.img') as base_img_path, \ 39b6e0985aSAndrey Shinkevich iotests.FilePath('mid.img') as mid_img_path, \ 40b6e0985aSAndrey Shinkevich iotests.FilePath('top.img') as top_img_path, \ 41b6e0985aSAndrey Shinkevich iotests.VM() as vm: 42b6e0985aSAndrey Shinkevich 43b6e0985aSAndrey Shinkevich log('--- Setting up images ---') 44b6e0985aSAndrey Shinkevich log('') 45b6e0985aSAndrey Shinkevich 46fc272d3cSJohn Snow qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') 47*72cfb937SJohn Snow qemu_io(base_img_path, '-c', 'write -P 1 0M 1M') 48*72cfb937SJohn Snow qemu_io(base_img_path, '-c', 'write -P 1 3M 1M') 49fc272d3cSJohn Snow qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, 50fc272d3cSJohn Snow '-F', iotests.imgfmt, mid_img_path) 51*72cfb937SJohn Snow qemu_io(mid_img_path, '-c', 'write -P 3 2M 1M') 52*72cfb937SJohn Snow qemu_io(mid_img_path, '-c', 'write -P 3 4M 1M') 53fc272d3cSJohn Snow qemu_img('create', '-f', iotests.imgfmt, '-b', mid_img_path, 54fc272d3cSJohn Snow '-F', iotests.imgfmt, top_img_path) 55*72cfb937SJohn Snow qemu_io(top_img_path, '-c', 'write -P 2 1M 1M') 56b6e0985aSAndrey Shinkevich 57b6e0985aSAndrey Shinkevich# 0 1 2 3 4 58b6e0985aSAndrey Shinkevich# top 2 59b6e0985aSAndrey Shinkevich# mid 3 3 60b6e0985aSAndrey Shinkevich# base 1 1 61b6e0985aSAndrey Shinkevich 62b6e0985aSAndrey Shinkevich log('Done') 63b6e0985aSAndrey Shinkevich 64b6e0985aSAndrey Shinkevich log('') 65b6e0985aSAndrey Shinkevich log('--- Doing COR ---') 66b6e0985aSAndrey Shinkevich log('') 67b6e0985aSAndrey Shinkevich 68b6e0985aSAndrey Shinkevich vm.launch() 69b6e0985aSAndrey Shinkevich 70b6e0985aSAndrey Shinkevich log(vm.qmp('blockdev-add', 71b6e0985aSAndrey Shinkevich node_name='node0', 72b6e0985aSAndrey Shinkevich driver='copy-on-read', 73b6e0985aSAndrey Shinkevich bottom='node2', 74b6e0985aSAndrey Shinkevich file={ 75b6e0985aSAndrey Shinkevich 'driver': iotests.imgfmt, 76b6e0985aSAndrey Shinkevich 'file': { 77b6e0985aSAndrey Shinkevich 'driver': 'file', 78b6e0985aSAndrey Shinkevich 'filename': top_img_path 79b6e0985aSAndrey Shinkevich }, 80b6e0985aSAndrey Shinkevich 'backing': { 81b6e0985aSAndrey Shinkevich 'node-name': 'node2', 82b6e0985aSAndrey Shinkevich 'driver': iotests.imgfmt, 83b6e0985aSAndrey Shinkevich 'file': { 84b6e0985aSAndrey Shinkevich 'driver': 'file', 85b6e0985aSAndrey Shinkevich 'filename': mid_img_path 86b6e0985aSAndrey Shinkevich }, 87b6e0985aSAndrey Shinkevich 'backing': { 88b6e0985aSAndrey Shinkevich 'driver': iotests.imgfmt, 89b6e0985aSAndrey Shinkevich 'file': { 90b6e0985aSAndrey Shinkevich 'driver': 'file', 91b6e0985aSAndrey Shinkevich 'filename': base_img_path 92b6e0985aSAndrey Shinkevich } 93b6e0985aSAndrey Shinkevich }, 94b6e0985aSAndrey Shinkevich } 95b6e0985aSAndrey Shinkevich })) 96b6e0985aSAndrey Shinkevich 97b6e0985aSAndrey Shinkevich # Trigger COR 98b6e0985aSAndrey Shinkevich log(vm.qmp('human-monitor-command', 99b6e0985aSAndrey Shinkevich command_line='qemu-io node0 "read 0 5M"')) 100b6e0985aSAndrey Shinkevich 101b6e0985aSAndrey Shinkevich vm.shutdown() 102b6e0985aSAndrey Shinkevich 103b6e0985aSAndrey Shinkevich log('') 104b6e0985aSAndrey Shinkevich log('--- Checking COR result ---') 105b6e0985aSAndrey Shinkevich log('') 106b6e0985aSAndrey Shinkevich 107b6e0985aSAndrey Shinkevich # Detach backing to check that we can read the data from the top level now 108fc272d3cSJohn Snow qemu_img('rebase', '-u', '-b', '', '-f', iotests.imgfmt, top_img_path) 109b6e0985aSAndrey Shinkevich 110*72cfb937SJohn Snow qemu_io(top_img_path, '-c', 'read -P 0 0 1M') 111*72cfb937SJohn Snow qemu_io(top_img_path, '-c', 'read -P 2 1M 1M') 112*72cfb937SJohn Snow qemu_io(top_img_path, '-c', 'read -P 3 2M 1M') 113*72cfb937SJohn Snow qemu_io(top_img_path, '-c', 'read -P 0 3M 1M') 114*72cfb937SJohn Snow qemu_io(top_img_path, '-c', 'read -P 3 4M 1M') 115b6e0985aSAndrey Shinkevich 116b6e0985aSAndrey Shinkevich log('Done') 117