iotests/081: Test rewrite-corrupted without WRITE
[qemu.git] / tests / qemu-iotests / 081
blob4e199729317135b492cbe185cd07bd158f42e020
1 #!/usr/bin/env bash
3 # Test Quorum block driver
5 # Copyright (C) 2013 Nodalink, SARL.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=benoit@irqsave.net
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 _cleanup()
31 _rm_test_img "$TEST_DIR/1.raw"
32 _rm_test_img "$TEST_DIR/2.raw"
33 _rm_test_img "$TEST_DIR/3.raw"
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 _supported_fmt raw
42 _supported_proto file
43 _supported_os Linux
44 _require_drivers quorum
45 _require_devices virtio-scsi
47 do_run_qemu()
49 echo Testing: "$@"
50 $QEMU -nographic -qmp stdio -serial none "$@"
51 echo
54 run_qemu()
56 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \
57 | _filter_qmp | _filter_qemu_io \
58 | _filter_generated_node_ids
61 quorum="driver=raw,file.driver=quorum,file.vote-threshold=2"
62 quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
63 quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
64 quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
65 quorum="$quorum,file.children.0.driver=raw"
66 quorum="$quorum,file.children.1.driver=raw"
67 quorum="$quorum,file.children.2.driver=raw"
69 echo
70 echo "== creating quorum files =="
72 size=10M
74 TEST_IMG="$TEST_DIR/1.raw" _make_test_img $size
75 TEST_IMG="$TEST_DIR/2.raw" _make_test_img $size
76 TEST_IMG="$TEST_DIR/3.raw" _make_test_img $size
78 echo
79 echo "== writing images =="
81 $QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io
83 echo
84 echo "== checking quorum write =="
86 $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
87 $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
88 $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io
90 echo
91 echo "== corrupting image =="
93 $QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
95 echo
96 echo "== checking quorum correction =="
98 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
100 echo
101 echo "== checking mixed reference/option specification =="
103 run_qemu <<EOF
104 { "execute": "qmp_capabilities" }
105 { "execute": "blockdev-add",
106 "arguments": {
107 "node-name": "drive2",
108 "driver": "$IMGFMT",
109 "file": {
110 "driver": "file",
111 "filename": "$TEST_DIR/2.raw"
115 { "execute": "blockdev-add",
116 "arguments": {
117 "driver": "quorum",
118 "node-name": "drive0-quorum",
119 "vote-threshold": 2,
120 "children": [
122 "driver": "$IMGFMT",
123 "file": {
124 "driver": "file",
125 "filename": "$TEST_DIR/1.raw"
128 "drive2",
130 "driver": "$IMGFMT",
131 "file": {
132 "driver": "file",
133 "filename": "$TEST_DIR/3.raw"
139 { "execute": "human-monitor-command",
140 "arguments": {
141 "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"'
144 { "execute": "quit" }
147 echo
148 echo "== using quorum rewrite corrupted mode =="
150 quorum="$quorum,file.rewrite-corrupted=on"
152 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
154 echo
155 echo "== checking that quorum has corrected the corrupted file =="
157 $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
159 echo
160 echo "== using quorum rewrite corrupted mode without WRITE permission =="
162 # The same as above, but this time, do it on a quorum node whose only
163 # parent will not take the WRITE permission
165 echo '-- corrupting --'
166 # Only corrupt a portion: The guest device (scsi-hd on virtio-scsi)
167 # will read some data (looking for a partition table to guess the
168 # disk's geometry), which would trigger a quorum mismatch if the
169 # beginning of the image was corrupted. The subsequent
170 # QUORUM_REPORT_BAD event would be suppressed (because at that point,
171 # there cannot have been a qmp_capabilities on the monitor). Because
172 # that event is rate-limited, the next QUORUM_REPORT_BAD that happens
173 # thanks to our qemu-io read (which should trigger a mismatch) would
174 # then be delayed past the VM quit and not appear in the output.
175 # So we keep the first 1M intact to see a QUORUM_REPORT_BAD resulting
176 # from the qemu-io invocation.
177 $QEMU_IO -c "write -P 0x42 1M 1M" "$TEST_DIR/2.raw" | _filter_qemu_io
179 # Fix the corruption (on a read-only quorum node, i.e. without taking
180 # the WRITE permission on it -- its child nodes need to be R/W OTOH,
181 # so that rewrite-corrupted works)
182 echo
183 echo '-- running quorum --'
184 run_qemu \
185 -blockdev file,node-name=file1,filename="$TEST_DIR/1.raw" \
186 -blockdev file,node-name=file2,filename="$TEST_DIR/2.raw" \
187 -blockdev file,node-name=file3,filename="$TEST_DIR/3.raw" \
188 -blockdev '{
189 "driver": "quorum",
190 "node-name": "quorum",
191 "read-only": true,
192 "vote-threshold": 2,
193 "rewrite-corrupted": true,
194 "children": [ "file1", "file2", "file3" ]
195 }' \
196 -device virtio-scsi,id=scsi \
197 -device scsi-hd,id=quorum-drive,bus=scsi.0,drive=quorum \
198 <<EOF
199 { "execute": "qmp_capabilities" }
201 "execute": "human-monitor-command",
202 "arguments": {
203 "command-line": 'qemu-io -d quorum-drive "read -P 0x32 0 $size"'
206 { "execute": "quit" }
209 echo '-- checking that the image has been corrected --'
210 $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
212 echo
213 echo "== breaking quorum =="
215 $QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
216 $QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
218 echo
219 echo "== checking that quorum is broken =="
221 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
223 echo
224 echo "== checking the blkverify mode with broken content =="
226 quorum="driver=raw,file.driver=quorum,file.vote-threshold=2,file.blkverify=on"
227 quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
228 quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
229 quorum="$quorum,file.children.0.driver=raw"
230 quorum="$quorum,file.children.1.driver=raw"
232 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
234 echo
235 echo "== writing the same data to both files =="
237 $QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
238 $QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
240 echo
241 echo "== checking the blkverify mode with valid content =="
243 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
245 echo
246 echo "== checking the blkverify mode with invalid settings =="
248 quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
249 quorum="$quorum,file.children.2.driver=raw"
251 $QEMU_IO -c "open -o $quorum" | _filter_qemu_io
253 echo
254 echo "== dynamically adding a child to a quorum =="
256 for verify in false true; do
257 run_qemu <<EOF
258 { "execute": "qmp_capabilities" }
259 { "execute": "blockdev-add",
260 "arguments": {
261 "driver": "quorum",
262 "node-name": "drive0-quorum",
263 "vote-threshold": 2,
264 "blkverify": ${verify},
265 "children": [
267 "driver": "$IMGFMT",
268 "file": {
269 "driver": "file",
270 "filename": "$TEST_DIR/1.raw"
274 "driver": "$IMGFMT",
275 "file": {
276 "driver": "file",
277 "filename": "$TEST_DIR/2.raw"
283 { "execute": "blockdev-add",
284 "arguments": {
285 "node-name": "drive3",
286 "driver": "$IMGFMT",
287 "file": {
288 "driver": "file",
289 "filename": "$TEST_DIR/2.raw"
293 { "execute": "x-blockdev-change",
294 "arguments": { "parent": "drive0-quorum",
295 "node": "drive3" } }
296 { "execute": "quit" }
298 done
300 echo
301 echo "== dynamically removing a child from a quorum =="
303 for verify in false true; do
304 for vote_threshold in 1 2; do
305 run_qemu <<EOF
306 { "execute": "qmp_capabilities" }
307 { "execute": "blockdev-add",
308 "arguments": {
309 "driver": "quorum",
310 "node-name": "drive0-quorum",
311 "vote-threshold": ${vote_threshold},
312 "blkverify": ${verify},
313 "children": [
315 "driver": "$IMGFMT",
316 "file": {
317 "driver": "file",
318 "filename": "$TEST_DIR/1.raw"
322 "driver": "$IMGFMT",
323 "file": {
324 "driver": "file",
325 "filename": "$TEST_DIR/2.raw"
331 { "execute": "x-blockdev-change",
332 "arguments": { "parent": "drive0-quorum",
333 "child": "children.1" } }
334 { "execute": "quit" }
336 done
337 done
339 # success, all done
340 echo "*** done"
341 rm -f $seq.full
342 status=0