111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2c7fc5bc2SBenoît Canet# 3c7fc5bc2SBenoît Canet# Test Quorum block driver 4c7fc5bc2SBenoît Canet# 5c7fc5bc2SBenoît Canet# Copyright (C) 2013 Nodalink, SARL. 6c7fc5bc2SBenoît Canet# 7c7fc5bc2SBenoît Canet# This program is free software; you can redistribute it and/or modify 8c7fc5bc2SBenoît Canet# it under the terms of the GNU General Public License as published by 9c7fc5bc2SBenoît Canet# the Free Software Foundation; either version 2 of the License, or 10c7fc5bc2SBenoît Canet# (at your option) any later version. 11c7fc5bc2SBenoît Canet# 12c7fc5bc2SBenoît Canet# This program is distributed in the hope that it will be useful, 13c7fc5bc2SBenoît Canet# but WITHOUT ANY WARRANTY; without even the implied warranty of 14c7fc5bc2SBenoît Canet# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15c7fc5bc2SBenoît Canet# GNU General Public License for more details. 16c7fc5bc2SBenoît Canet# 17c7fc5bc2SBenoît Canet# You should have received a copy of the GNU General Public License 18c7fc5bc2SBenoît Canet# along with this program. If not, see <http://www.gnu.org/licenses/>. 19c7fc5bc2SBenoît Canet# 20c7fc5bc2SBenoît Canet 21c7fc5bc2SBenoît Canet# creator 22c7fc5bc2SBenoît Canetowner=benoit@irqsave.net 23c7fc5bc2SBenoît Canet 24c7fc5bc2SBenoît Canetseq=`basename $0` 25c7fc5bc2SBenoît Canetecho "QA output created by $seq" 26c7fc5bc2SBenoît Canet 27c7fc5bc2SBenoît Canetstatus=1 # failure is the default! 28c7fc5bc2SBenoît Canet 29c7fc5bc2SBenoît Canet_cleanup() 30c7fc5bc2SBenoît Canet{ 31f91ecbd7SMax Reitz _rm_test_img "$TEST_DIR/1.raw" 32f91ecbd7SMax Reitz _rm_test_img "$TEST_DIR/2.raw" 33f91ecbd7SMax Reitz _rm_test_img "$TEST_DIR/3.raw" 34c7fc5bc2SBenoît Canet} 35c7fc5bc2SBenoît Canettrap "_cleanup; exit \$status" 0 1 2 3 15 36c7fc5bc2SBenoît Canet 37c7fc5bc2SBenoît Canet# get standard environment, filters and checks 38c7fc5bc2SBenoît Canet. ./common.rc 39c7fc5bc2SBenoît Canet. ./common.filter 40c7fc5bc2SBenoît Canet 41c7fc5bc2SBenoît Canet_supported_fmt raw 42c5f7c0afSPeter Lieven_supported_proto file 43c7fc5bc2SBenoît Canet_supported_os Linux 4421b43d00SThomas Huth_require_drivers quorum 45*c61c644fSMax Reitz_require_devices virtio-scsi 46c7fc5bc2SBenoît Canet 478cedcffdSEric Blakedo_run_qemu() 486141f3bdSMax Reitz{ 4955f2c014SMax Reitz echo Testing: "$@" 506141f3bdSMax Reitz $QEMU -nographic -qmp stdio -serial none "$@" 516141f3bdSMax Reitz echo 526141f3bdSMax Reitz} 536141f3bdSMax Reitz 548cedcffdSEric Blakerun_qemu() 556141f3bdSMax Reitz{ 5655f2c014SMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \ 5755f2c014SMax Reitz | _filter_qmp | _filter_qemu_io \ 5855f2c014SMax Reitz | _filter_generated_node_ids 596141f3bdSMax Reitz} 606141f3bdSMax Reitz 618f9e835fSKevin Wolfquorum="driver=raw,file.driver=quorum,file.vote-threshold=2" 628f9e835fSKevin Wolfquorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" 63c7fc5bc2SBenoît Canetquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" 648f9e835fSKevin Wolfquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw" 658f9e835fSKevin Wolfquorum="$quorum,file.children.0.driver=raw" 668f9e835fSKevin Wolfquorum="$quorum,file.children.1.driver=raw" 678f9e835fSKevin Wolfquorum="$quorum,file.children.2.driver=raw" 68c7fc5bc2SBenoît Canet 69c7fc5bc2SBenoît Canetecho 70c7fc5bc2SBenoît Canetecho "== creating quorum files ==" 71c7fc5bc2SBenoît Canet 72c7fc5bc2SBenoît Canetsize=10M 73c7fc5bc2SBenoît Canet 74c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/1.raw" _make_test_img $size 75c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/2.raw" _make_test_img $size 76c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/3.raw" _make_test_img $size 77c7fc5bc2SBenoît Canet 78c7fc5bc2SBenoît Canetecho 79c7fc5bc2SBenoît Canetecho "== writing images ==" 80c7fc5bc2SBenoît Canet 81c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io 82c7fc5bc2SBenoît Canet 83c7fc5bc2SBenoît Canetecho 84c7fc5bc2SBenoît Canetecho "== checking quorum write ==" 85c7fc5bc2SBenoît Canet 86c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 87c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 88c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io 89c7fc5bc2SBenoît Canet 90c7fc5bc2SBenoît Canetecho 91c7fc5bc2SBenoît Canetecho "== corrupting image ==" 92c7fc5bc2SBenoît Canet 93c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 94c7fc5bc2SBenoît Canet 95c7fc5bc2SBenoît Canetecho 96c7fc5bc2SBenoît Canetecho "== checking quorum correction ==" 97c7fc5bc2SBenoît Canet 98c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 99c7fc5bc2SBenoît Canet 100c7fc5bc2SBenoît Canetecho 1016141f3bdSMax Reitzecho "== checking mixed reference/option specification ==" 1026141f3bdSMax Reitz 1038e9e6530SMax Reitzrun_qemu <<EOF 1046141f3bdSMax Reitz{ "execute": "qmp_capabilities" } 1056141f3bdSMax Reitz{ "execute": "blockdev-add", 1066141f3bdSMax Reitz "arguments": { 1078e9e6530SMax Reitz "node-name": "drive2", 1088e9e6530SMax Reitz "driver": "$IMGFMT", 1098e9e6530SMax Reitz "file": { 1108e9e6530SMax Reitz "driver": "file", 1118e9e6530SMax Reitz "filename": "$TEST_DIR/2.raw" 1128e9e6530SMax Reitz } 1138e9e6530SMax Reitz } 1148e9e6530SMax Reitz} 1158e9e6530SMax Reitz{ "execute": "blockdev-add", 1168e9e6530SMax Reitz "arguments": { 1176141f3bdSMax Reitz "driver": "quorum", 11826d5fa10SKevin Wolf "node-name": "drive0-quorum", 1196141f3bdSMax Reitz "vote-threshold": 2, 1206141f3bdSMax Reitz "children": [ 1216141f3bdSMax Reitz { 1228e9e6530SMax Reitz "driver": "$IMGFMT", 1236141f3bdSMax Reitz "file": { 1246141f3bdSMax Reitz "driver": "file", 1256141f3bdSMax Reitz "filename": "$TEST_DIR/1.raw" 1266141f3bdSMax Reitz } 1276141f3bdSMax Reitz }, 1286141f3bdSMax Reitz "drive2", 1296141f3bdSMax Reitz { 1308e9e6530SMax Reitz "driver": "$IMGFMT", 1316141f3bdSMax Reitz "file": { 1326141f3bdSMax Reitz "driver": "file", 1336141f3bdSMax Reitz "filename": "$TEST_DIR/3.raw" 1346141f3bdSMax Reitz } 1356141f3bdSMax Reitz } 1366141f3bdSMax Reitz ] 1376141f3bdSMax Reitz } 1386141f3bdSMax Reitz} 1396141f3bdSMax Reitz{ "execute": "human-monitor-command", 1406141f3bdSMax Reitz "arguments": { 1416141f3bdSMax Reitz "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"' 1426141f3bdSMax Reitz } 1436141f3bdSMax Reitz} 1446141f3bdSMax Reitz{ "execute": "quit" } 1456141f3bdSMax ReitzEOF 1466141f3bdSMax Reitz 1476141f3bdSMax Reitzecho 148cf29a570SBenoît Canetecho "== using quorum rewrite corrupted mode ==" 149cf29a570SBenoît Canet 150cf29a570SBenoît Canetquorum="$quorum,file.rewrite-corrupted=on" 151cf29a570SBenoît Canet 152cf29a570SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 153cf29a570SBenoît Canet 154cf29a570SBenoît Canetecho 155cf29a570SBenoît Canetecho "== checking that quorum has corrected the corrupted file ==" 156cf29a570SBenoît Canet 157cf29a570SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 158cf29a570SBenoît Canet 159cf29a570SBenoît Canetecho 160*c61c644fSMax Reitzecho "== using quorum rewrite corrupted mode without WRITE permission ==" 161*c61c644fSMax Reitz 162*c61c644fSMax Reitz# The same as above, but this time, do it on a quorum node whose only 163*c61c644fSMax Reitz# parent will not take the WRITE permission 164*c61c644fSMax Reitz 165*c61c644fSMax Reitzecho '-- corrupting --' 166*c61c644fSMax Reitz# Only corrupt a portion: The guest device (scsi-hd on virtio-scsi) 167*c61c644fSMax Reitz# will read some data (looking for a partition table to guess the 168*c61c644fSMax Reitz# disk's geometry), which would trigger a quorum mismatch if the 169*c61c644fSMax Reitz# beginning of the image was corrupted. The subsequent 170*c61c644fSMax Reitz# QUORUM_REPORT_BAD event would be suppressed (because at that point, 171*c61c644fSMax Reitz# there cannot have been a qmp_capabilities on the monitor). Because 172*c61c644fSMax Reitz# that event is rate-limited, the next QUORUM_REPORT_BAD that happens 173*c61c644fSMax Reitz# thanks to our qemu-io read (which should trigger a mismatch) would 174*c61c644fSMax Reitz# then be delayed past the VM quit and not appear in the output. 175*c61c644fSMax Reitz# So we keep the first 1M intact to see a QUORUM_REPORT_BAD resulting 176*c61c644fSMax Reitz# from the qemu-io invocation. 177*c61c644fSMax Reitz$QEMU_IO -c "write -P 0x42 1M 1M" "$TEST_DIR/2.raw" | _filter_qemu_io 178*c61c644fSMax Reitz 179*c61c644fSMax Reitz# Fix the corruption (on a read-only quorum node, i.e. without taking 180*c61c644fSMax Reitz# the WRITE permission on it -- its child nodes need to be R/W OTOH, 181*c61c644fSMax Reitz# so that rewrite-corrupted works) 182*c61c644fSMax Reitzecho 183*c61c644fSMax Reitzecho '-- running quorum --' 184*c61c644fSMax Reitzrun_qemu \ 185*c61c644fSMax Reitz -blockdev file,node-name=file1,filename="$TEST_DIR/1.raw" \ 186*c61c644fSMax Reitz -blockdev file,node-name=file2,filename="$TEST_DIR/2.raw" \ 187*c61c644fSMax Reitz -blockdev file,node-name=file3,filename="$TEST_DIR/3.raw" \ 188*c61c644fSMax Reitz -blockdev '{ 189*c61c644fSMax Reitz "driver": "quorum", 190*c61c644fSMax Reitz "node-name": "quorum", 191*c61c644fSMax Reitz "read-only": true, 192*c61c644fSMax Reitz "vote-threshold": 2, 193*c61c644fSMax Reitz "rewrite-corrupted": true, 194*c61c644fSMax Reitz "children": [ "file1", "file2", "file3" ] 195*c61c644fSMax Reitz }' \ 196*c61c644fSMax Reitz -device virtio-scsi,id=scsi \ 197*c61c644fSMax Reitz -device scsi-hd,id=quorum-drive,bus=scsi.0,drive=quorum \ 198*c61c644fSMax Reitz <<EOF 199*c61c644fSMax Reitz{ "execute": "qmp_capabilities" } 200*c61c644fSMax Reitz{ 201*c61c644fSMax Reitz "execute": "human-monitor-command", 202*c61c644fSMax Reitz "arguments": { 203*c61c644fSMax Reitz "command-line": 'qemu-io -d quorum-drive "read -P 0x32 0 $size"' 204*c61c644fSMax Reitz } 205*c61c644fSMax Reitz} 206*c61c644fSMax Reitz{ "execute": "quit" } 207*c61c644fSMax ReitzEOF 208*c61c644fSMax Reitz 209*c61c644fSMax Reitzecho '-- checking that the image has been corrected --' 210*c61c644fSMax Reitz$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 211*c61c644fSMax Reitz 212*c61c644fSMax Reitzecho 213c7fc5bc2SBenoît Canetecho "== breaking quorum ==" 214c7fc5bc2SBenoît Canet 215c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 216cf29a570SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 217cf29a570SBenoît Canet 218c7fc5bc2SBenoît Canetecho 219c7fc5bc2SBenoît Canetecho "== checking that quorum is broken ==" 220c7fc5bc2SBenoît Canet 221c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 222c7fc5bc2SBenoît Canet 22382c4c859SAlberto Garciaecho 22482c4c859SAlberto Garciaecho "== checking the blkverify mode with broken content ==" 22582c4c859SAlberto Garcia 22682c4c859SAlberto Garciaquorum="driver=raw,file.driver=quorum,file.vote-threshold=2,file.blkverify=on" 22782c4c859SAlberto Garciaquorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" 22882c4c859SAlberto Garciaquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" 22982c4c859SAlberto Garciaquorum="$quorum,file.children.0.driver=raw" 23082c4c859SAlberto Garciaquorum="$quorum,file.children.1.driver=raw" 23182c4c859SAlberto Garcia 23282c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 23382c4c859SAlberto Garcia 23482c4c859SAlberto Garciaecho 23582c4c859SAlberto Garciaecho "== writing the same data to both files ==" 23682c4c859SAlberto Garcia 23782c4c859SAlberto Garcia$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 23882c4c859SAlberto Garcia$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 23982c4c859SAlberto Garcia 24082c4c859SAlberto Garciaecho 24182c4c859SAlberto Garciaecho "== checking the blkverify mode with valid content ==" 24282c4c859SAlberto Garcia 24382c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 24482c4c859SAlberto Garcia 24582c4c859SAlberto Garciaecho 24682c4c859SAlberto Garciaecho "== checking the blkverify mode with invalid settings ==" 24782c4c859SAlberto Garcia 24882c4c859SAlberto Garciaquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw" 24982c4c859SAlberto Garciaquorum="$quorum,file.children.2.driver=raw" 25082c4c859SAlberto Garcia 25182c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" | _filter_qemu_io 25282c4c859SAlberto Garcia 25304f600efSAlberto Garciaecho 25404f600efSAlberto Garciaecho "== dynamically adding a child to a quorum ==" 25504f600efSAlberto Garcia 25604f600efSAlberto Garciafor verify in false true; do 25704f600efSAlberto Garcia run_qemu <<EOF 25804f600efSAlberto Garcia { "execute": "qmp_capabilities" } 25904f600efSAlberto Garcia { "execute": "blockdev-add", 26004f600efSAlberto Garcia "arguments": { 26104f600efSAlberto Garcia "driver": "quorum", 26204f600efSAlberto Garcia "node-name": "drive0-quorum", 26304f600efSAlberto Garcia "vote-threshold": 2, 26404f600efSAlberto Garcia "blkverify": ${verify}, 26504f600efSAlberto Garcia "children": [ 26604f600efSAlberto Garcia { 26704f600efSAlberto Garcia "driver": "$IMGFMT", 26804f600efSAlberto Garcia "file": { 26904f600efSAlberto Garcia "driver": "file", 27004f600efSAlberto Garcia "filename": "$TEST_DIR/1.raw" 27104f600efSAlberto Garcia } 27204f600efSAlberto Garcia }, 27304f600efSAlberto Garcia { 27404f600efSAlberto Garcia "driver": "$IMGFMT", 27504f600efSAlberto Garcia "file": { 27604f600efSAlberto Garcia "driver": "file", 27704f600efSAlberto Garcia "filename": "$TEST_DIR/2.raw" 27804f600efSAlberto Garcia } 27904f600efSAlberto Garcia } 28004f600efSAlberto Garcia ] 28104f600efSAlberto Garcia } 28204f600efSAlberto Garcia } 28304f600efSAlberto Garcia { "execute": "blockdev-add", 28404f600efSAlberto Garcia "arguments": { 28504f600efSAlberto Garcia "node-name": "drive3", 28604f600efSAlberto Garcia "driver": "$IMGFMT", 28704f600efSAlberto Garcia "file": { 28804f600efSAlberto Garcia "driver": "file", 28904f600efSAlberto Garcia "filename": "$TEST_DIR/2.raw" 29004f600efSAlberto Garcia } 29104f600efSAlberto Garcia } 29204f600efSAlberto Garcia } 29304f600efSAlberto Garcia { "execute": "x-blockdev-change", 29404f600efSAlberto Garcia "arguments": { "parent": "drive0-quorum", 29504f600efSAlberto Garcia "node": "drive3" } } 29604f600efSAlberto Garcia { "execute": "quit" } 29704f600efSAlberto GarciaEOF 29804f600efSAlberto Garciadone 29904f600efSAlberto Garcia 30004f600efSAlberto Garciaecho 30104f600efSAlberto Garciaecho "== dynamically removing a child from a quorum ==" 30204f600efSAlberto Garcia 30304f600efSAlberto Garciafor verify in false true; do 30404f600efSAlberto Garcia for vote_threshold in 1 2; do 30504f600efSAlberto Garcia run_qemu <<EOF 30604f600efSAlberto Garcia { "execute": "qmp_capabilities" } 30704f600efSAlberto Garcia { "execute": "blockdev-add", 30804f600efSAlberto Garcia "arguments": { 30904f600efSAlberto Garcia "driver": "quorum", 31004f600efSAlberto Garcia "node-name": "drive0-quorum", 31104f600efSAlberto Garcia "vote-threshold": ${vote_threshold}, 31204f600efSAlberto Garcia "blkverify": ${verify}, 31304f600efSAlberto Garcia "children": [ 31404f600efSAlberto Garcia { 31504f600efSAlberto Garcia "driver": "$IMGFMT", 31604f600efSAlberto Garcia "file": { 31704f600efSAlberto Garcia "driver": "file", 31804f600efSAlberto Garcia "filename": "$TEST_DIR/1.raw" 31904f600efSAlberto Garcia } 32004f600efSAlberto Garcia }, 32104f600efSAlberto Garcia { 32204f600efSAlberto Garcia "driver": "$IMGFMT", 32304f600efSAlberto Garcia "file": { 32404f600efSAlberto Garcia "driver": "file", 32504f600efSAlberto Garcia "filename": "$TEST_DIR/2.raw" 32604f600efSAlberto Garcia } 32704f600efSAlberto Garcia } 32804f600efSAlberto Garcia ] 32904f600efSAlberto Garcia } 33004f600efSAlberto Garcia } 33104f600efSAlberto Garcia { "execute": "x-blockdev-change", 33204f600efSAlberto Garcia "arguments": { "parent": "drive0-quorum", 33304f600efSAlberto Garcia "child": "children.1" } } 33404f600efSAlberto Garcia { "execute": "quit" } 33504f600efSAlberto GarciaEOF 33604f600efSAlberto Garcia done 33704f600efSAlberto Garciadone 33804f600efSAlberto Garcia 339c7fc5bc2SBenoît Canet# success, all done 340c7fc5bc2SBenoît Canetecho "*** done" 341c7fc5bc2SBenoît Canetrm -f $seq.full 342c7fc5bc2SBenoît Canetstatus=0 343