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