1#!/bin/bash 2# 3# Test Quorum block driver 4# 5# Copyright (C) 2013 Nodalink, SARL. 6# 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. 11# 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. 16# 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/>. 19# 20 21# creator 22owner=benoit@irqsave.net 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27here=`pwd` 28tmp=/tmp/$$ 29status=1 # failure is the default! 30 31_cleanup() 32{ 33 rm -rf $TEST_DIR/1.raw 34 rm -rf $TEST_DIR/2.raw 35 rm -rf $TEST_DIR/3.raw 36} 37trap "_cleanup; exit \$status" 0 1 2 3 15 38 39# get standard environment, filters and checks 40. ./common.rc 41. ./common.filter 42 43_supported_fmt raw 44_supported_proto generic 45_supported_os Linux 46 47function do_run_qemu() 48{ 49 echo Testing: "$@" | _filter_imgfmt 50 $QEMU -nographic -qmp stdio -serial none "$@" 51 echo 52} 53 54function run_qemu() 55{ 56 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp | _filter_qemu_io 57} 58 59quorum="file.driver=quorum,file.children.0.file.filename=$TEST_DIR/1.raw" 60quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" 61quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw,file.vote-threshold=2" 62 63echo 64echo "== creating quorum files ==" 65 66size=10M 67 68TEST_IMG="$TEST_DIR/1.raw" _make_test_img $size 69TEST_IMG="$TEST_DIR/2.raw" _make_test_img $size 70TEST_IMG="$TEST_DIR/3.raw" _make_test_img $size 71 72echo 73echo "== writing images ==" 74 75$QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io 76 77echo 78echo "== checking quorum write ==" 79 80$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 81$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 82$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io 83 84echo 85echo "== corrupting image ==" 86 87$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 88 89echo 90echo "== checking quorum correction ==" 91 92$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 93 94echo 95echo "== checking mixed reference/option specification ==" 96 97run_qemu -drive "file=$TEST_DIR/2.raw,format=$IMGFMT,if=none,id=drive2" <<EOF 98{ "execute": "qmp_capabilities" } 99{ "execute": "blockdev-add", 100 "arguments": { 101 "options": { 102 "driver": "quorum", 103 "id": "drive0-quorum", 104 "vote-threshold": 2, 105 "children": [ 106 { 107 "driver": "raw", 108 "file": { 109 "driver": "file", 110 "filename": "$TEST_DIR/1.raw" 111 } 112 }, 113 "drive2", 114 { 115 "driver": "raw", 116 "file": { 117 "driver": "file", 118 "filename": "$TEST_DIR/3.raw" 119 } 120 } 121 ] 122 } 123 } 124} 125{ "execute": "human-monitor-command", 126 "arguments": { 127 "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"' 128 } 129} 130{ "execute": "quit" } 131EOF 132 133echo 134echo "== breaking quorum ==" 135 136$QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 137echo 138echo "== checking that quorum is broken ==" 139 140$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 141 142 143# success, all done 144echo "*** done" 145rm -f $seq.full 146status=0 147