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