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/>.
22 owner
=benoit@irqsave.net
25 echo "QA output created by $seq"
27 status
=1 # failure is the default!
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
44 _require_drivers quorum
45 _require_devices virtio-scsi
50 $QEMU -nographic -qmp stdio
-serial none
"$@"
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"
70 echo "== creating quorum files =="
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
79 echo "== writing images =="
81 $QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io
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
91 echo "== corrupting image =="
93 $QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
96 echo "== checking quorum correction =="
98 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
101 echo "== checking mixed reference/option specification =="
104 { "execute": "qmp_capabilities" }
105 { "execute": "blockdev-add",
107 "node-name": "drive2",
111 "filename": "$TEST_DIR/2.raw"
115 { "execute": "blockdev-add",
118 "node-name": "drive0-quorum",
125 "filename": "$TEST_DIR/1.raw"
133 "filename": "$TEST_DIR/3.raw"
139 { "execute": "human-monitor-command",
141 "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"'
144 { "execute": "quit" }
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
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
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)
183 echo '-- running quorum --'
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" \
190 "node-name": "quorum",
193 "rewrite-corrupted": true,
194 "children": [ "file1", "file2", "file3" ]
196 -device virtio-scsi
,id
=scsi \
197 -device scsi-hd
,id
=quorum-drive
,bus
=scsi
.0,drive
=quorum \
199 { "execute": "qmp_capabilities" }
201 "execute": "human-monitor-command",
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
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
219 echo "== checking that quorum is broken =="
221 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
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
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
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
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
254 echo "== dynamically adding a child to a quorum =="
256 for verify
in false true
; do
258 { "execute": "qmp_capabilities" }
259 { "execute": "blockdev-add",
262 "node-name": "drive0-quorum",
264 "blkverify": ${verify},
270 "filename": "$TEST_DIR/1.raw"
277 "filename": "$TEST_DIR/2.raw"
283 { "execute": "blockdev-add",
285 "node-name": "drive3",
289 "filename": "$TEST_DIR/2.raw"
293 { "execute": "x-blockdev-change",
294 "arguments": { "parent": "drive0-quorum",
296 { "execute": "quit" }
301 echo "== dynamically removing a child from a quorum =="
303 for verify
in false true
; do
304 for vote_threshold
in 1 2; do
306 { "execute": "qmp_capabilities" }
307 { "execute": "blockdev-add",
310 "node-name": "drive0-quorum",
311 "vote-threshold": ${vote_threshold},
312 "blkverify": ${verify},
318 "filename": "$TEST_DIR/1.raw"
325 "filename": "$TEST_DIR/2.raw"
331 { "execute": "x-blockdev-change",
332 "arguments": { "parent": "drive0-quorum",
333 "child": "children.1" } }
334 { "execute": "quit" }