1c7fc5bc2SBenoît Canet#!/bin/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 Canethere=`pwd` 28c7fc5bc2SBenoît Canettmp=/tmp/$$ 29c7fc5bc2SBenoît Canetstatus=1 # failure is the default! 30c7fc5bc2SBenoît Canet 31c7fc5bc2SBenoît Canet_cleanup() 32c7fc5bc2SBenoît Canet{ 33c7fc5bc2SBenoît Canet rm -rf $TEST_DIR/1.raw 34c7fc5bc2SBenoît Canet rm -rf $TEST_DIR/2.raw 35c7fc5bc2SBenoît Canet rm -rf $TEST_DIR/3.raw 36c7fc5bc2SBenoît Canet} 37c7fc5bc2SBenoît Canettrap "_cleanup; exit \$status" 0 1 2 3 15 38c7fc5bc2SBenoît Canet 39c7fc5bc2SBenoît Canet# get standard environment, filters and checks 40c7fc5bc2SBenoît Canet. ./common.rc 41c7fc5bc2SBenoît Canet. ./common.filter 42c7fc5bc2SBenoît Canet 43c7fc5bc2SBenoît Canet_supported_fmt raw 44*c5f7c0afSPeter Lieven_supported_proto file 45c7fc5bc2SBenoît Canet_supported_os Linux 46c7fc5bc2SBenoît Canet 476141f3bdSMax Reitzfunction do_run_qemu() 486141f3bdSMax Reitz{ 496141f3bdSMax Reitz echo Testing: "$@" | _filter_imgfmt 506141f3bdSMax Reitz $QEMU -nographic -qmp stdio -serial none "$@" 516141f3bdSMax Reitz echo 526141f3bdSMax Reitz} 536141f3bdSMax Reitz 546141f3bdSMax Reitzfunction run_qemu() 556141f3bdSMax Reitz{ 566141f3bdSMax Reitz do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu_io 576141f3bdSMax Reitz} 586141f3bdSMax Reitz 594b350f1dSBenoît Canettest_quorum=$($QEMU_IMG --help|grep quorum) 604b350f1dSBenoît Canet[ "$test_quorum" = "" ] && _supported_fmt quorum 614b350f1dSBenoît Canet 62c7fc5bc2SBenoît Canetquorum="file.driver=quorum,file.children.0.file.filename=$TEST_DIR/1.raw" 63c7fc5bc2SBenoît Canetquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" 64c7fc5bc2SBenoît Canetquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw,file.vote-threshold=2" 65c7fc5bc2SBenoît Canet 66c7fc5bc2SBenoît Canetecho 67c7fc5bc2SBenoît Canetecho "== creating quorum files ==" 68c7fc5bc2SBenoît Canet 69c7fc5bc2SBenoît Canetsize=10M 70c7fc5bc2SBenoît Canet 71c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/1.raw" _make_test_img $size 72c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/2.raw" _make_test_img $size 73c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/3.raw" _make_test_img $size 74c7fc5bc2SBenoît Canet 75c7fc5bc2SBenoît Canetecho 76c7fc5bc2SBenoît Canetecho "== writing images ==" 77c7fc5bc2SBenoît Canet 78c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io 79c7fc5bc2SBenoît Canet 80c7fc5bc2SBenoît Canetecho 81c7fc5bc2SBenoît Canetecho "== checking quorum write ==" 82c7fc5bc2SBenoît Canet 83c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 84c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 85c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io 86c7fc5bc2SBenoît Canet 87c7fc5bc2SBenoît Canetecho 88c7fc5bc2SBenoît Canetecho "== corrupting image ==" 89c7fc5bc2SBenoît Canet 90c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 91c7fc5bc2SBenoît Canet 92c7fc5bc2SBenoît Canetecho 93c7fc5bc2SBenoît Canetecho "== checking quorum correction ==" 94c7fc5bc2SBenoît Canet 95c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 96c7fc5bc2SBenoît Canet 97c7fc5bc2SBenoît Canetecho 986141f3bdSMax Reitzecho "== checking mixed reference/option specification ==" 996141f3bdSMax Reitz 1006141f3bdSMax Reitzrun_qemu -drive "file=$TEST_DIR/2.raw,format=$IMGFMT,if=none,id=drive2" <<EOF 1016141f3bdSMax Reitz{ "execute": "qmp_capabilities" } 1026141f3bdSMax Reitz{ "execute": "blockdev-add", 1036141f3bdSMax Reitz "arguments": { 1046141f3bdSMax Reitz "options": { 1056141f3bdSMax Reitz "driver": "quorum", 1066141f3bdSMax Reitz "id": "drive0-quorum", 1076141f3bdSMax Reitz "vote-threshold": 2, 1086141f3bdSMax Reitz "children": [ 1096141f3bdSMax Reitz { 1106141f3bdSMax Reitz "driver": "raw", 1116141f3bdSMax Reitz "file": { 1126141f3bdSMax Reitz "driver": "file", 1136141f3bdSMax Reitz "filename": "$TEST_DIR/1.raw" 1146141f3bdSMax Reitz } 1156141f3bdSMax Reitz }, 1166141f3bdSMax Reitz "drive2", 1176141f3bdSMax Reitz { 1186141f3bdSMax Reitz "driver": "raw", 1196141f3bdSMax Reitz "file": { 1206141f3bdSMax Reitz "driver": "file", 1216141f3bdSMax Reitz "filename": "$TEST_DIR/3.raw" 1226141f3bdSMax Reitz } 1236141f3bdSMax Reitz } 1246141f3bdSMax Reitz ] 1256141f3bdSMax Reitz } 1266141f3bdSMax Reitz } 1276141f3bdSMax Reitz} 1286141f3bdSMax Reitz{ "execute": "human-monitor-command", 1296141f3bdSMax Reitz "arguments": { 1306141f3bdSMax Reitz "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"' 1316141f3bdSMax Reitz } 1326141f3bdSMax Reitz} 1336141f3bdSMax Reitz{ "execute": "quit" } 1346141f3bdSMax ReitzEOF 1356141f3bdSMax Reitz 1366141f3bdSMax Reitzecho 137cf29a570SBenoît Canetecho "== using quorum rewrite corrupted mode ==" 138cf29a570SBenoît Canet 139cf29a570SBenoît Canetquorum="$quorum,file.rewrite-corrupted=on" 140cf29a570SBenoît Canet 141cf29a570SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 142cf29a570SBenoît Canet 143cf29a570SBenoît Canetecho 144cf29a570SBenoît Canetecho "== checking that quorum has corrected the corrupted file ==" 145cf29a570SBenoît Canet 146cf29a570SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 147cf29a570SBenoît Canet 148cf29a570SBenoît Canetecho 149c7fc5bc2SBenoît Canetecho "== breaking quorum ==" 150c7fc5bc2SBenoît Canet 151c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 152cf29a570SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 153cf29a570SBenoît Canet 154c7fc5bc2SBenoît Canetecho 155c7fc5bc2SBenoît Canetecho "== checking that quorum is broken ==" 156c7fc5bc2SBenoît Canet 157c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 158c7fc5bc2SBenoît Canet 159c7fc5bc2SBenoît Canet# success, all done 160c7fc5bc2SBenoît Canetecho "*** done" 161c7fc5bc2SBenoît Canetrm -f $seq.full 162c7fc5bc2SBenoît Canetstatus=0 163