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 Canetstatus=1 # failure is the default! 29c7fc5bc2SBenoît Canet 30c7fc5bc2SBenoît Canet_cleanup() 31c7fc5bc2SBenoît Canet{ 32c7fc5bc2SBenoît Canet rm -rf $TEST_DIR/1.raw 33c7fc5bc2SBenoît Canet rm -rf $TEST_DIR/2.raw 34c7fc5bc2SBenoît Canet rm -rf $TEST_DIR/3.raw 35c7fc5bc2SBenoît Canet} 36c7fc5bc2SBenoît Canettrap "_cleanup; exit \$status" 0 1 2 3 15 37c7fc5bc2SBenoît Canet 38c7fc5bc2SBenoît Canet# get standard environment, filters and checks 39c7fc5bc2SBenoît Canet. ./common.rc 40c7fc5bc2SBenoît Canet. ./common.filter 41c7fc5bc2SBenoît Canet 42c7fc5bc2SBenoît Canet_supported_fmt raw 43c5f7c0afSPeter Lieven_supported_proto file 44c7fc5bc2SBenoît Canet_supported_os Linux 45c7fc5bc2SBenoît Canet 466141f3bdSMax Reitzfunction do_run_qemu() 476141f3bdSMax Reitz{ 486141f3bdSMax Reitz echo Testing: "$@" | _filter_imgfmt 496141f3bdSMax Reitz $QEMU -nographic -qmp stdio -serial none "$@" 506141f3bdSMax Reitz echo 516141f3bdSMax Reitz} 526141f3bdSMax Reitz 536141f3bdSMax Reitzfunction run_qemu() 546141f3bdSMax Reitz{ 5515489c76SJeff Cody do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\ 5615489c76SJeff Cody | _filter_qemu_io | _filter_generated_node_ids 576141f3bdSMax Reitz} 586141f3bdSMax Reitz 594b350f1dSBenoît Canettest_quorum=$($QEMU_IMG --help|grep quorum) 604b350f1dSBenoît Canet[ "$test_quorum" = "" ] && _supported_fmt quorum 614b350f1dSBenoît Canet 628f9e835fSKevin Wolfquorum="driver=raw,file.driver=quorum,file.vote-threshold=2" 638f9e835fSKevin Wolfquorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" 64c7fc5bc2SBenoît Canetquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" 658f9e835fSKevin Wolfquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw" 668f9e835fSKevin Wolfquorum="$quorum,file.children.0.driver=raw" 678f9e835fSKevin Wolfquorum="$quorum,file.children.1.driver=raw" 688f9e835fSKevin Wolfquorum="$quorum,file.children.2.driver=raw" 69c7fc5bc2SBenoît Canet 70c7fc5bc2SBenoît Canetecho 71c7fc5bc2SBenoît Canetecho "== creating quorum files ==" 72c7fc5bc2SBenoît Canet 73c7fc5bc2SBenoît Canetsize=10M 74c7fc5bc2SBenoît Canet 75c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/1.raw" _make_test_img $size 76c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/2.raw" _make_test_img $size 77c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/3.raw" _make_test_img $size 78c7fc5bc2SBenoît Canet 79c7fc5bc2SBenoît Canetecho 80c7fc5bc2SBenoît Canetecho "== writing images ==" 81c7fc5bc2SBenoît Canet 82c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io 83c7fc5bc2SBenoît Canet 84c7fc5bc2SBenoît Canetecho 85c7fc5bc2SBenoît Canetecho "== checking quorum write ==" 86c7fc5bc2SBenoît Canet 87c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 88c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 89c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io 90c7fc5bc2SBenoît Canet 91c7fc5bc2SBenoît Canetecho 92c7fc5bc2SBenoît Canetecho "== corrupting image ==" 93c7fc5bc2SBenoît Canet 94c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 95c7fc5bc2SBenoît Canet 96c7fc5bc2SBenoît Canetecho 97c7fc5bc2SBenoît Canetecho "== checking quorum correction ==" 98c7fc5bc2SBenoît Canet 99c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 100c7fc5bc2SBenoît Canet 101c7fc5bc2SBenoît Canetecho 1026141f3bdSMax Reitzecho "== checking mixed reference/option specification ==" 1036141f3bdSMax Reitz 1048e9e6530SMax Reitzrun_qemu <<EOF 1056141f3bdSMax Reitz{ "execute": "qmp_capabilities" } 1066141f3bdSMax Reitz{ "execute": "blockdev-add", 1076141f3bdSMax Reitz "arguments": { 1088e9e6530SMax Reitz "node-name": "drive2", 1098e9e6530SMax Reitz "driver": "$IMGFMT", 1108e9e6530SMax Reitz "file": { 1118e9e6530SMax Reitz "driver": "file", 1128e9e6530SMax Reitz "filename": "$TEST_DIR/2.raw" 1138e9e6530SMax Reitz } 1148e9e6530SMax Reitz } 1158e9e6530SMax Reitz} 1168e9e6530SMax Reitz{ "execute": "blockdev-add", 1178e9e6530SMax Reitz "arguments": { 1186141f3bdSMax Reitz "driver": "quorum", 11926d5fa10SKevin Wolf "node-name": "drive0-quorum", 1206141f3bdSMax Reitz "vote-threshold": 2, 1216141f3bdSMax Reitz "children": [ 1226141f3bdSMax Reitz { 1238e9e6530SMax Reitz "driver": "$IMGFMT", 1246141f3bdSMax Reitz "file": { 1256141f3bdSMax Reitz "driver": "file", 1266141f3bdSMax Reitz "filename": "$TEST_DIR/1.raw" 1276141f3bdSMax Reitz } 1286141f3bdSMax Reitz }, 1296141f3bdSMax Reitz "drive2", 1306141f3bdSMax Reitz { 1318e9e6530SMax Reitz "driver": "$IMGFMT", 1326141f3bdSMax Reitz "file": { 1336141f3bdSMax Reitz "driver": "file", 1346141f3bdSMax Reitz "filename": "$TEST_DIR/3.raw" 1356141f3bdSMax Reitz } 1366141f3bdSMax Reitz } 1376141f3bdSMax Reitz ] 1386141f3bdSMax Reitz } 1396141f3bdSMax Reitz} 1406141f3bdSMax Reitz{ "execute": "human-monitor-command", 1416141f3bdSMax Reitz "arguments": { 1426141f3bdSMax Reitz "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"' 1436141f3bdSMax Reitz } 1446141f3bdSMax Reitz} 1456141f3bdSMax Reitz{ "execute": "quit" } 1466141f3bdSMax ReitzEOF 1476141f3bdSMax Reitz 1486141f3bdSMax Reitzecho 149cf29a570SBenoît Canetecho "== using quorum rewrite corrupted mode ==" 150cf29a570SBenoît Canet 151cf29a570SBenoît Canetquorum="$quorum,file.rewrite-corrupted=on" 152cf29a570SBenoît Canet 153cf29a570SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 154cf29a570SBenoît Canet 155cf29a570SBenoît Canetecho 156cf29a570SBenoît Canetecho "== checking that quorum has corrected the corrupted file ==" 157cf29a570SBenoît Canet 158cf29a570SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 159cf29a570SBenoît Canet 160cf29a570SBenoît Canetecho 161c7fc5bc2SBenoît Canetecho "== breaking quorum ==" 162c7fc5bc2SBenoît Canet 163c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 164cf29a570SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 165cf29a570SBenoît Canet 166c7fc5bc2SBenoît Canetecho 167c7fc5bc2SBenoît Canetecho "== checking that quorum is broken ==" 168c7fc5bc2SBenoît Canet 169c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 170c7fc5bc2SBenoît Canet 17182c4c859SAlberto Garciaecho 17282c4c859SAlberto Garciaecho "== checking the blkverify mode with broken content ==" 17382c4c859SAlberto Garcia 17482c4c859SAlberto Garciaquorum="driver=raw,file.driver=quorum,file.vote-threshold=2,file.blkverify=on" 17582c4c859SAlberto Garciaquorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" 17682c4c859SAlberto Garciaquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" 17782c4c859SAlberto Garciaquorum="$quorum,file.children.0.driver=raw" 17882c4c859SAlberto Garciaquorum="$quorum,file.children.1.driver=raw" 17982c4c859SAlberto Garcia 18082c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 18182c4c859SAlberto Garcia 18282c4c859SAlberto Garciaecho 18382c4c859SAlberto Garciaecho "== writing the same data to both files ==" 18482c4c859SAlberto Garcia 18582c4c859SAlberto Garcia$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io 18682c4c859SAlberto Garcia$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io 18782c4c859SAlberto Garcia 18882c4c859SAlberto Garciaecho 18982c4c859SAlberto Garciaecho "== checking the blkverify mode with valid content ==" 19082c4c859SAlberto Garcia 19182c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io 19282c4c859SAlberto Garcia 19382c4c859SAlberto Garciaecho 19482c4c859SAlberto Garciaecho "== checking the blkverify mode with invalid settings ==" 19582c4c859SAlberto Garcia 19682c4c859SAlberto Garciaquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw" 19782c4c859SAlberto Garciaquorum="$quorum,file.children.2.driver=raw" 19882c4c859SAlberto Garcia 19982c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" | _filter_qemu_io 20082c4c859SAlberto Garcia 201*04f600efSAlberto Garciaecho 202*04f600efSAlberto Garciaecho "== dynamically adding a child to a quorum ==" 203*04f600efSAlberto Garcia 204*04f600efSAlberto Garciafor verify in false true; do 205*04f600efSAlberto Garcia run_qemu <<EOF 206*04f600efSAlberto Garcia { "execute": "qmp_capabilities" } 207*04f600efSAlberto Garcia { "execute": "blockdev-add", 208*04f600efSAlberto Garcia "arguments": { 209*04f600efSAlberto Garcia "driver": "quorum", 210*04f600efSAlberto Garcia "node-name": "drive0-quorum", 211*04f600efSAlberto Garcia "vote-threshold": 2, 212*04f600efSAlberto Garcia "blkverify": ${verify}, 213*04f600efSAlberto Garcia "children": [ 214*04f600efSAlberto Garcia { 215*04f600efSAlberto Garcia "driver": "$IMGFMT", 216*04f600efSAlberto Garcia "file": { 217*04f600efSAlberto Garcia "driver": "file", 218*04f600efSAlberto Garcia "filename": "$TEST_DIR/1.raw" 219*04f600efSAlberto Garcia } 220*04f600efSAlberto Garcia }, 221*04f600efSAlberto Garcia { 222*04f600efSAlberto Garcia "driver": "$IMGFMT", 223*04f600efSAlberto Garcia "file": { 224*04f600efSAlberto Garcia "driver": "file", 225*04f600efSAlberto Garcia "filename": "$TEST_DIR/2.raw" 226*04f600efSAlberto Garcia } 227*04f600efSAlberto Garcia } 228*04f600efSAlberto Garcia ] 229*04f600efSAlberto Garcia } 230*04f600efSAlberto Garcia } 231*04f600efSAlberto Garcia { "execute": "blockdev-add", 232*04f600efSAlberto Garcia "arguments": { 233*04f600efSAlberto Garcia "node-name": "drive3", 234*04f600efSAlberto Garcia "driver": "$IMGFMT", 235*04f600efSAlberto Garcia "file": { 236*04f600efSAlberto Garcia "driver": "file", 237*04f600efSAlberto Garcia "filename": "$TEST_DIR/2.raw" 238*04f600efSAlberto Garcia } 239*04f600efSAlberto Garcia } 240*04f600efSAlberto Garcia } 241*04f600efSAlberto Garcia { "execute": "x-blockdev-change", 242*04f600efSAlberto Garcia "arguments": { "parent": "drive0-quorum", 243*04f600efSAlberto Garcia "node": "drive3" } } 244*04f600efSAlberto Garcia { "execute": "quit" } 245*04f600efSAlberto GarciaEOF 246*04f600efSAlberto Garciadone 247*04f600efSAlberto Garcia 248*04f600efSAlberto Garciaecho 249*04f600efSAlberto Garciaecho "== dynamically removing a child from a quorum ==" 250*04f600efSAlberto Garcia 251*04f600efSAlberto Garciafor verify in false true; do 252*04f600efSAlberto Garcia for vote_threshold in 1 2; do 253*04f600efSAlberto Garcia run_qemu <<EOF 254*04f600efSAlberto Garcia { "execute": "qmp_capabilities" } 255*04f600efSAlberto Garcia { "execute": "blockdev-add", 256*04f600efSAlberto Garcia "arguments": { 257*04f600efSAlberto Garcia "driver": "quorum", 258*04f600efSAlberto Garcia "node-name": "drive0-quorum", 259*04f600efSAlberto Garcia "vote-threshold": ${vote_threshold}, 260*04f600efSAlberto Garcia "blkverify": ${verify}, 261*04f600efSAlberto Garcia "children": [ 262*04f600efSAlberto Garcia { 263*04f600efSAlberto Garcia "driver": "$IMGFMT", 264*04f600efSAlberto Garcia "file": { 265*04f600efSAlberto Garcia "driver": "file", 266*04f600efSAlberto Garcia "filename": "$TEST_DIR/1.raw" 267*04f600efSAlberto Garcia } 268*04f600efSAlberto Garcia }, 269*04f600efSAlberto Garcia { 270*04f600efSAlberto Garcia "driver": "$IMGFMT", 271*04f600efSAlberto Garcia "file": { 272*04f600efSAlberto Garcia "driver": "file", 273*04f600efSAlberto Garcia "filename": "$TEST_DIR/2.raw" 274*04f600efSAlberto Garcia } 275*04f600efSAlberto Garcia } 276*04f600efSAlberto Garcia ] 277*04f600efSAlberto Garcia } 278*04f600efSAlberto Garcia } 279*04f600efSAlberto Garcia { "execute": "x-blockdev-change", 280*04f600efSAlberto Garcia "arguments": { "parent": "drive0-quorum", 281*04f600efSAlberto Garcia "child": "children.1" } } 282*04f600efSAlberto Garcia { "execute": "quit" } 283*04f600efSAlberto GarciaEOF 284*04f600efSAlberto Garcia done 285*04f600efSAlberto Garciadone 286*04f600efSAlberto Garcia 287c7fc5bc2SBenoît Canet# success, all done 288c7fc5bc2SBenoît Canetecho "*** done" 289c7fc5bc2SBenoît Canetrm -f $seq.full 290c7fc5bc2SBenoît Canetstatus=0 291