xref: /openbmc/qemu/tests/qemu-iotests/312 (revision ef9bba1484bb8fb5fda53a7bf90bf5e1a8e6a9f6)
1*ef9bba14SAlberto Garcia#!/usr/bin/env bash
2*ef9bba14SAlberto Garcia#
3*ef9bba14SAlberto Garcia# Test drive-mirror with quorum
4*ef9bba14SAlberto Garcia#
5*ef9bba14SAlberto Garcia# The goal of this test is to check how the quorum driver reports
6*ef9bba14SAlberto Garcia# regions that are known to read as zeroes (BDRV_BLOCK_ZERO). The idea
7*ef9bba14SAlberto Garcia# is that drive-mirror will try the efficient representation of zeroes
8*ef9bba14SAlberto Garcia# in the destination image instead of writing actual zeroes.
9*ef9bba14SAlberto Garcia#
10*ef9bba14SAlberto Garcia# Copyright (C) 2020 Igalia, S.L.
11*ef9bba14SAlberto Garcia# Author: Alberto Garcia <berto@igalia.com>
12*ef9bba14SAlberto Garcia#
13*ef9bba14SAlberto Garcia# This program is free software; you can redistribute it and/or modify
14*ef9bba14SAlberto Garcia# it under the terms of the GNU General Public License as published by
15*ef9bba14SAlberto Garcia# the Free Software Foundation; either version 2 of the License, or
16*ef9bba14SAlberto Garcia# (at your option) any later version.
17*ef9bba14SAlberto Garcia#
18*ef9bba14SAlberto Garcia# This program is distributed in the hope that it will be useful,
19*ef9bba14SAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of
20*ef9bba14SAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21*ef9bba14SAlberto Garcia# GNU General Public License for more details.
22*ef9bba14SAlberto Garcia#
23*ef9bba14SAlberto Garcia# You should have received a copy of the GNU General Public License
24*ef9bba14SAlberto Garcia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
25*ef9bba14SAlberto Garcia#
26*ef9bba14SAlberto Garcia
27*ef9bba14SAlberto Garcia# creator
28*ef9bba14SAlberto Garciaowner=berto@igalia.com
29*ef9bba14SAlberto Garcia
30*ef9bba14SAlberto Garciaseq=`basename $0`
31*ef9bba14SAlberto Garciaecho "QA output created by $seq"
32*ef9bba14SAlberto Garcia
33*ef9bba14SAlberto Garciastatus=1	# failure is the default!
34*ef9bba14SAlberto Garcia
35*ef9bba14SAlberto Garcia_cleanup()
36*ef9bba14SAlberto Garcia{
37*ef9bba14SAlberto Garcia    _rm_test_img "$TEST_IMG.0"
38*ef9bba14SAlberto Garcia    _rm_test_img "$TEST_IMG.1"
39*ef9bba14SAlberto Garcia    _rm_test_img "$TEST_IMG.2"
40*ef9bba14SAlberto Garcia    _rm_test_img "$TEST_IMG.3"
41*ef9bba14SAlberto Garcia    _cleanup_qemu
42*ef9bba14SAlberto Garcia}
43*ef9bba14SAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15
44*ef9bba14SAlberto Garcia
45*ef9bba14SAlberto Garcia# get standard environment, filters and checks
46*ef9bba14SAlberto Garcia. ./common.rc
47*ef9bba14SAlberto Garcia. ./common.filter
48*ef9bba14SAlberto Garcia. ./common.qemu
49*ef9bba14SAlberto Garcia
50*ef9bba14SAlberto Garcia_supported_fmt qcow2
51*ef9bba14SAlberto Garcia_supported_proto file
52*ef9bba14SAlberto Garcia_supported_os Linux
53*ef9bba14SAlberto Garcia_unsupported_imgopts cluster_size data_file
54*ef9bba14SAlberto Garcia
55*ef9bba14SAlberto Garciaecho
56*ef9bba14SAlberto Garciaecho '### Create all images' # three source (quorum), one destination
57*ef9bba14SAlberto Garciaecho
58*ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.0" _make_test_img -o cluster_size=64k 10M
59*ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.1" _make_test_img -o cluster_size=64k 10M
60*ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.2" _make_test_img -o cluster_size=64k 10M
61*ef9bba14SAlberto GarciaTEST_IMG="$TEST_IMG.3" _make_test_img -o cluster_size=64k 10M
62*ef9bba14SAlberto Garcia
63*ef9bba14SAlberto Garciaquorum="driver=raw,file.driver=quorum,file.vote-threshold=2"
64*ef9bba14SAlberto Garciaquorum="$quorum,file.children.0.file.filename=$TEST_IMG.0"
65*ef9bba14SAlberto Garciaquorum="$quorum,file.children.1.file.filename=$TEST_IMG.1"
66*ef9bba14SAlberto Garciaquorum="$quorum,file.children.2.file.filename=$TEST_IMG.2"
67*ef9bba14SAlberto Garciaquorum="$quorum,file.children.0.driver=$IMGFMT"
68*ef9bba14SAlberto Garciaquorum="$quorum,file.children.1.driver=$IMGFMT"
69*ef9bba14SAlberto Garciaquorum="$quorum,file.children.2.driver=$IMGFMT"
70*ef9bba14SAlberto Garcia
71*ef9bba14SAlberto Garciaecho
72*ef9bba14SAlberto Garciaecho '### Output of qemu-img map (empty quorum)'
73*ef9bba14SAlberto Garciaecho
74*ef9bba14SAlberto Garcia$QEMU_IMG map --image-opts $quorum | _filter_qemu_img_map
75*ef9bba14SAlberto Garcia
76*ef9bba14SAlberto Garcia# Now we write data to the quorum. All three images will read as
77*ef9bba14SAlberto Garcia# zeroes in all cases, but with different ways to represent them
78*ef9bba14SAlberto Garcia# (unallocated clusters, zero clusters, data clusters with zeroes)
79*ef9bba14SAlberto Garcia# that will have an effect on how the data will be mirrored and the
80*ef9bba14SAlberto Garcia# output of qemu-img map on the resulting image.
81*ef9bba14SAlberto Garciaecho
82*ef9bba14SAlberto Garciaecho '### Write data to the quorum'
83*ef9bba14SAlberto Garciaecho
84*ef9bba14SAlberto Garcia# Test 1: data regions surrounded by unallocated clusters.
85*ef9bba14SAlberto Garcia# Three data regions, the largest one (0x30000) will be picked, end result:
86*ef9bba14SAlberto Garcia# offset 0x10000, length 0x30000 -> data
87*ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x10000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io
88*ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x10000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io
89*ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x10000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io
90*ef9bba14SAlberto Garcia
91*ef9bba14SAlberto Garcia# Test 2: zero regions surrounded by data clusters.
92*ef9bba14SAlberto Garcia# First we allocate the data clusters.
93*ef9bba14SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "write -P 0 $((0x100000)) $((0x40000))" | _filter_qemu_io
94*ef9bba14SAlberto Garcia
95*ef9bba14SAlberto Garcia# Three zero regions, the smallest one (0x10000) will be picked, end result:
96*ef9bba14SAlberto Garcia# offset 0x100000, length 0x10000 -> data
97*ef9bba14SAlberto Garcia# offset 0x110000, length 0x10000 -> zeroes
98*ef9bba14SAlberto Garcia# offset 0x120000, length 0x20000 -> data
99*ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x110000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io
100*ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x110000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io
101*ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x110000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io
102*ef9bba14SAlberto Garcia
103*ef9bba14SAlberto Garcia# Test 3: zero clusters surrounded by unallocated clusters.
104*ef9bba14SAlberto Garcia# Everything reads as zeroes, no effect on the end result.
105*ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x150000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io
106*ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x150000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io
107*ef9bba14SAlberto Garcia$QEMU_IO -c "write -z $((0x150000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io
108*ef9bba14SAlberto Garcia
109*ef9bba14SAlberto Garcia# Test 4: mix of data and zero clusters.
110*ef9bba14SAlberto Garcia# The zero region will be ignored in favor of the largest data region
111*ef9bba14SAlberto Garcia# (0x20000), end result:
112*ef9bba14SAlberto Garcia# offset 0x200000, length 0x20000 -> data
113*ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x200000)) $((0x10000))" "$TEST_IMG.0" | _filter_qemu_io
114*ef9bba14SAlberto Garcia$QEMU_IO -c "write -z   $((0x200000)) $((0x30000))" "$TEST_IMG.1" | _filter_qemu_io
115*ef9bba14SAlberto Garcia$QEMU_IO -c "write -P 0 $((0x200000)) $((0x20000))" "$TEST_IMG.2" | _filter_qemu_io
116*ef9bba14SAlberto Garcia
117*ef9bba14SAlberto Garciaecho
118*ef9bba14SAlberto Garciaecho '### Launch the drive-mirror job'
119*ef9bba14SAlberto Garciaecho
120*ef9bba14SAlberto Garciaqemu_comm_method="qmp" _launch_qemu -drive if=virtio,"$quorum"
121*ef9bba14SAlberto Garciah=$QEMU_HANDLE
122*ef9bba14SAlberto Garcia_send_qemu_cmd $h "{ 'execute': 'qmp_capabilities' }" 'return'
123*ef9bba14SAlberto Garcia
124*ef9bba14SAlberto Garcia_send_qemu_cmd $h \
125*ef9bba14SAlberto Garcia    "{'execute': 'drive-mirror',
126*ef9bba14SAlberto Garcia                 'arguments': {'device': 'virtio0',
127*ef9bba14SAlberto Garcia                               'format': '$IMGFMT',
128*ef9bba14SAlberto Garcia                               'target': '$TEST_IMG.3',
129*ef9bba14SAlberto Garcia                               'sync':   'full',
130*ef9bba14SAlberto Garcia                               'mode':   'existing' }}"    \
131*ef9bba14SAlberto Garcia     "BLOCK_JOB_READY.*virtio0"
132*ef9bba14SAlberto Garcia
133*ef9bba14SAlberto Garcia_send_qemu_cmd $h \
134*ef9bba14SAlberto Garcia    "{ 'execute': 'block-job-complete',
135*ef9bba14SAlberto Garcia       'arguments': { 'device': 'virtio0' } }" \
136*ef9bba14SAlberto Garcia    'BLOCK_JOB_COMPLETED'
137*ef9bba14SAlberto Garcia
138*ef9bba14SAlberto Garcia_send_qemu_cmd $h "{ 'execute': 'quit' }" ''
139*ef9bba14SAlberto Garcia
140*ef9bba14SAlberto Garciaecho
141*ef9bba14SAlberto Garciaecho '### Output of qemu-img map (destination image)'
142*ef9bba14SAlberto Garciaecho
143*ef9bba14SAlberto Garcia$QEMU_IMG map "$TEST_IMG.3" | _filter_qemu_img_map
144*ef9bba14SAlberto Garcia
145*ef9bba14SAlberto Garcia# success, all done
146*ef9bba14SAlberto Garciaecho "*** done"
147*ef9bba14SAlberto Garciarm -f $seq.full
148*ef9bba14SAlberto Garciastatus=0
149