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