xref: /qemu/tests/qemu-iotests/081 (revision 55f2c014d7a4f79bc22dc7f018ef785b5d6baf49)
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
45c7fc5bc2SBenoît Canet
468cedcffdSEric Blakedo_run_qemu()
476141f3bdSMax Reitz{
48*55f2c014SMax Reitz    echo Testing: "$@"
496141f3bdSMax Reitz    $QEMU -nographic -qmp stdio -serial none "$@"
506141f3bdSMax Reitz    echo
516141f3bdSMax Reitz}
526141f3bdSMax Reitz
538cedcffdSEric Blakerun_qemu()
546141f3bdSMax Reitz{
55*55f2c014SMax Reitz    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_imgfmt | _filter_qemu \
56*55f2c014SMax Reitz                          | _filter_qmp | _filter_qemu_io \
57*55f2c014SMax Reitz                          | _filter_generated_node_ids
586141f3bdSMax Reitz}
596141f3bdSMax Reitz
608f9e835fSKevin Wolfquorum="driver=raw,file.driver=quorum,file.vote-threshold=2"
618f9e835fSKevin Wolfquorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
62c7fc5bc2SBenoît Canetquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
638f9e835fSKevin Wolfquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
648f9e835fSKevin Wolfquorum="$quorum,file.children.0.driver=raw"
658f9e835fSKevin Wolfquorum="$quorum,file.children.1.driver=raw"
668f9e835fSKevin Wolfquorum="$quorum,file.children.2.driver=raw"
67c7fc5bc2SBenoît Canet
68c7fc5bc2SBenoît Canetecho
69c7fc5bc2SBenoît Canetecho "== creating quorum files =="
70c7fc5bc2SBenoît Canet
71c7fc5bc2SBenoît Canetsize=10M
72c7fc5bc2SBenoît Canet
73c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/1.raw" _make_test_img $size
74c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/2.raw" _make_test_img $size
75c7fc5bc2SBenoît CanetTEST_IMG="$TEST_DIR/3.raw" _make_test_img $size
76c7fc5bc2SBenoît Canet
77c7fc5bc2SBenoît Canetecho
78c7fc5bc2SBenoît Canetecho "== writing images =="
79c7fc5bc2SBenoît Canet
80c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io
81c7fc5bc2SBenoît Canet
82c7fc5bc2SBenoît Canetecho
83c7fc5bc2SBenoît Canetecho "== checking quorum write =="
84c7fc5bc2SBenoît Canet
85c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
86c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
87c7fc5bc2SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io
88c7fc5bc2SBenoît Canet
89c7fc5bc2SBenoît Canetecho
90c7fc5bc2SBenoît Canetecho "== corrupting image =="
91c7fc5bc2SBenoît Canet
92c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
93c7fc5bc2SBenoît Canet
94c7fc5bc2SBenoît Canetecho
95c7fc5bc2SBenoît Canetecho "== checking quorum correction =="
96c7fc5bc2SBenoît Canet
97c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
98c7fc5bc2SBenoît Canet
99c7fc5bc2SBenoît Canetecho
1006141f3bdSMax Reitzecho "== checking mixed reference/option specification =="
1016141f3bdSMax Reitz
1028e9e6530SMax Reitzrun_qemu <<EOF
1036141f3bdSMax Reitz{ "execute": "qmp_capabilities" }
1046141f3bdSMax Reitz{ "execute": "blockdev-add",
1056141f3bdSMax Reitz    "arguments": {
1068e9e6530SMax Reitz        "node-name": "drive2",
1078e9e6530SMax Reitz        "driver": "$IMGFMT",
1088e9e6530SMax Reitz        "file": {
1098e9e6530SMax Reitz            "driver": "file",
1108e9e6530SMax Reitz            "filename": "$TEST_DIR/2.raw"
1118e9e6530SMax Reitz        }
1128e9e6530SMax Reitz    }
1138e9e6530SMax Reitz}
1148e9e6530SMax Reitz{ "execute": "blockdev-add",
1158e9e6530SMax Reitz    "arguments": {
1166141f3bdSMax Reitz        "driver": "quorum",
11726d5fa10SKevin Wolf        "node-name": "drive0-quorum",
1186141f3bdSMax Reitz        "vote-threshold": 2,
1196141f3bdSMax Reitz        "children": [
1206141f3bdSMax Reitz            {
1218e9e6530SMax Reitz                "driver": "$IMGFMT",
1226141f3bdSMax Reitz                "file": {
1236141f3bdSMax Reitz                    "driver": "file",
1246141f3bdSMax Reitz                    "filename": "$TEST_DIR/1.raw"
1256141f3bdSMax Reitz                }
1266141f3bdSMax Reitz            },
1276141f3bdSMax Reitz            "drive2",
1286141f3bdSMax Reitz            {
1298e9e6530SMax Reitz                "driver": "$IMGFMT",
1306141f3bdSMax Reitz                "file": {
1316141f3bdSMax Reitz                    "driver": "file",
1326141f3bdSMax Reitz                    "filename": "$TEST_DIR/3.raw"
1336141f3bdSMax Reitz                }
1346141f3bdSMax Reitz            }
1356141f3bdSMax Reitz        ]
1366141f3bdSMax Reitz    }
1376141f3bdSMax Reitz}
1386141f3bdSMax Reitz{ "execute": "human-monitor-command",
1396141f3bdSMax Reitz    "arguments": {
1406141f3bdSMax Reitz        "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"'
1416141f3bdSMax Reitz    }
1426141f3bdSMax Reitz}
1436141f3bdSMax Reitz{ "execute": "quit" }
1446141f3bdSMax ReitzEOF
1456141f3bdSMax Reitz
1466141f3bdSMax Reitzecho
147cf29a570SBenoît Canetecho "== using quorum rewrite corrupted mode =="
148cf29a570SBenoît Canet
149cf29a570SBenoît Canetquorum="$quorum,file.rewrite-corrupted=on"
150cf29a570SBenoît Canet
151cf29a570SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
152cf29a570SBenoît Canet
153cf29a570SBenoît Canetecho
154cf29a570SBenoît Canetecho "== checking that quorum has corrected the corrupted file =="
155cf29a570SBenoît Canet
156cf29a570SBenoît Canet$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
157cf29a570SBenoît Canet
158cf29a570SBenoît Canetecho
159c7fc5bc2SBenoît Canetecho "== breaking quorum =="
160c7fc5bc2SBenoît Canet
161c7fc5bc2SBenoît Canet$QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
162cf29a570SBenoît Canet$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
163cf29a570SBenoît Canet
164c7fc5bc2SBenoît Canetecho
165c7fc5bc2SBenoît Canetecho "== checking that quorum is broken =="
166c7fc5bc2SBenoît Canet
167c7fc5bc2SBenoît Canet$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
168c7fc5bc2SBenoît Canet
16982c4c859SAlberto Garciaecho
17082c4c859SAlberto Garciaecho "== checking the blkverify mode with broken content =="
17182c4c859SAlberto Garcia
17282c4c859SAlberto Garciaquorum="driver=raw,file.driver=quorum,file.vote-threshold=2,file.blkverify=on"
17382c4c859SAlberto Garciaquorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
17482c4c859SAlberto Garciaquorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
17582c4c859SAlberto Garciaquorum="$quorum,file.children.0.driver=raw"
17682c4c859SAlberto Garciaquorum="$quorum,file.children.1.driver=raw"
17782c4c859SAlberto Garcia
17882c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
17982c4c859SAlberto Garcia
18082c4c859SAlberto Garciaecho
18182c4c859SAlberto Garciaecho "== writing the same data to both files =="
18282c4c859SAlberto Garcia
18382c4c859SAlberto Garcia$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
18482c4c859SAlberto Garcia$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
18582c4c859SAlberto Garcia
18682c4c859SAlberto Garciaecho
18782c4c859SAlberto Garciaecho "== checking the blkverify mode with valid content =="
18882c4c859SAlberto Garcia
18982c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
19082c4c859SAlberto Garcia
19182c4c859SAlberto Garciaecho
19282c4c859SAlberto Garciaecho "== checking the blkverify mode with invalid settings =="
19382c4c859SAlberto Garcia
19482c4c859SAlberto Garciaquorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
19582c4c859SAlberto Garciaquorum="$quorum,file.children.2.driver=raw"
19682c4c859SAlberto Garcia
19782c4c859SAlberto Garcia$QEMU_IO -c "open -o $quorum" | _filter_qemu_io
19882c4c859SAlberto Garcia
19904f600efSAlberto Garciaecho
20004f600efSAlberto Garciaecho "== dynamically adding a child to a quorum =="
20104f600efSAlberto Garcia
20204f600efSAlberto Garciafor verify in false true; do
20304f600efSAlberto Garcia    run_qemu <<EOF
20404f600efSAlberto Garcia    { "execute": "qmp_capabilities" }
20504f600efSAlberto Garcia    { "execute": "blockdev-add",
20604f600efSAlberto Garcia        "arguments": {
20704f600efSAlberto Garcia            "driver": "quorum",
20804f600efSAlberto Garcia            "node-name": "drive0-quorum",
20904f600efSAlberto Garcia            "vote-threshold": 2,
21004f600efSAlberto Garcia            "blkverify": ${verify},
21104f600efSAlberto Garcia            "children": [
21204f600efSAlberto Garcia                {
21304f600efSAlberto Garcia                    "driver": "$IMGFMT",
21404f600efSAlberto Garcia                    "file": {
21504f600efSAlberto Garcia                        "driver": "file",
21604f600efSAlberto Garcia                        "filename": "$TEST_DIR/1.raw"
21704f600efSAlberto Garcia                    }
21804f600efSAlberto Garcia                },
21904f600efSAlberto Garcia                {
22004f600efSAlberto Garcia                    "driver": "$IMGFMT",
22104f600efSAlberto Garcia                    "file": {
22204f600efSAlberto Garcia                        "driver": "file",
22304f600efSAlberto Garcia                        "filename": "$TEST_DIR/2.raw"
22404f600efSAlberto Garcia                    }
22504f600efSAlberto Garcia                }
22604f600efSAlberto Garcia            ]
22704f600efSAlberto Garcia        }
22804f600efSAlberto Garcia    }
22904f600efSAlberto Garcia    { "execute": "blockdev-add",
23004f600efSAlberto Garcia        "arguments": {
23104f600efSAlberto Garcia            "node-name": "drive3",
23204f600efSAlberto Garcia            "driver": "$IMGFMT",
23304f600efSAlberto Garcia            "file": {
23404f600efSAlberto Garcia                "driver": "file",
23504f600efSAlberto Garcia                "filename": "$TEST_DIR/2.raw"
23604f600efSAlberto Garcia            }
23704f600efSAlberto Garcia        }
23804f600efSAlberto Garcia    }
23904f600efSAlberto Garcia    { "execute": "x-blockdev-change",
24004f600efSAlberto Garcia      "arguments": { "parent": "drive0-quorum",
24104f600efSAlberto Garcia                     "node": "drive3" } }
24204f600efSAlberto Garcia    { "execute": "quit" }
24304f600efSAlberto GarciaEOF
24404f600efSAlberto Garciadone
24504f600efSAlberto Garcia
24604f600efSAlberto Garciaecho
24704f600efSAlberto Garciaecho "== dynamically removing a child from a quorum =="
24804f600efSAlberto Garcia
24904f600efSAlberto Garciafor verify in false true; do
25004f600efSAlberto Garcia    for vote_threshold in 1 2; do
25104f600efSAlberto Garcia        run_qemu <<EOF
25204f600efSAlberto Garcia        { "execute": "qmp_capabilities" }
25304f600efSAlberto Garcia        { "execute": "blockdev-add",
25404f600efSAlberto Garcia            "arguments": {
25504f600efSAlberto Garcia                "driver": "quorum",
25604f600efSAlberto Garcia                "node-name": "drive0-quorum",
25704f600efSAlberto Garcia                "vote-threshold": ${vote_threshold},
25804f600efSAlberto Garcia                "blkverify": ${verify},
25904f600efSAlberto Garcia                "children": [
26004f600efSAlberto Garcia                    {
26104f600efSAlberto Garcia                        "driver": "$IMGFMT",
26204f600efSAlberto Garcia                        "file": {
26304f600efSAlberto Garcia                            "driver": "file",
26404f600efSAlberto Garcia                            "filename": "$TEST_DIR/1.raw"
26504f600efSAlberto Garcia                        }
26604f600efSAlberto Garcia                    },
26704f600efSAlberto Garcia                    {
26804f600efSAlberto Garcia                        "driver": "$IMGFMT",
26904f600efSAlberto Garcia                        "file": {
27004f600efSAlberto Garcia                            "driver": "file",
27104f600efSAlberto Garcia                            "filename": "$TEST_DIR/2.raw"
27204f600efSAlberto Garcia                        }
27304f600efSAlberto Garcia                    }
27404f600efSAlberto Garcia                ]
27504f600efSAlberto Garcia            }
27604f600efSAlberto Garcia        }
27704f600efSAlberto Garcia        { "execute": "x-blockdev-change",
27804f600efSAlberto Garcia          "arguments": { "parent": "drive0-quorum",
27904f600efSAlberto Garcia                         "child": "children.1" } }
28004f600efSAlberto Garcia        { "execute": "quit" }
28104f600efSAlberto GarciaEOF
28204f600efSAlberto Garcia    done
28304f600efSAlberto Garciadone
28404f600efSAlberto Garcia
285c7fc5bc2SBenoît Canet# success, all done
286c7fc5bc2SBenoît Canetecho "*** done"
287c7fc5bc2SBenoît Canetrm -f $seq.full
288c7fc5bc2SBenoît Canetstatus=0
289