xref: /openbmc/qemu/tests/qemu-iotests/081 (revision ec150c7e)
1#!/usr/bin/env 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
27status=1	# failure is the default!
28
29_cleanup()
30{
31    rm -rf $TEST_DIR/1.raw
32    rm -rf $TEST_DIR/2.raw
33    rm -rf $TEST_DIR/3.raw
34}
35trap "_cleanup; exit \$status" 0 1 2 3 15
36
37# get standard environment, filters and checks
38. ./common.rc
39. ./common.filter
40
41_supported_fmt raw
42_supported_proto file
43_supported_os Linux
44
45do_run_qemu()
46{
47    echo Testing: "$@" | _filter_imgfmt
48    $QEMU -nographic -qmp stdio -serial none "$@"
49    echo
50}
51
52run_qemu()
53{
54    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\
55                          | _filter_qemu_io | _filter_generated_node_ids
56}
57
58test_quorum=$($QEMU_IMG --help|grep quorum)
59[ "$test_quorum" = "" ] && _supported_fmt quorum
60
61quorum="driver=raw,file.driver=quorum,file.vote-threshold=2"
62quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
63quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
64quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
65quorum="$quorum,file.children.0.driver=raw"
66quorum="$quorum,file.children.1.driver=raw"
67quorum="$quorum,file.children.2.driver=raw"
68
69echo
70echo "== creating quorum files =="
71
72size=10M
73
74TEST_IMG="$TEST_DIR/1.raw" _make_test_img $size
75TEST_IMG="$TEST_DIR/2.raw" _make_test_img $size
76TEST_IMG="$TEST_DIR/3.raw" _make_test_img $size
77
78echo
79echo "== writing images =="
80
81$QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io
82
83echo
84echo "== checking quorum write =="
85
86$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
87$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
88$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io
89
90echo
91echo "== corrupting image =="
92
93$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
94
95echo
96echo "== checking quorum correction =="
97
98$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
99
100echo
101echo "== checking mixed reference/option specification =="
102
103run_qemu <<EOF
104{ "execute": "qmp_capabilities" }
105{ "execute": "blockdev-add",
106    "arguments": {
107        "node-name": "drive2",
108        "driver": "$IMGFMT",
109        "file": {
110            "driver": "file",
111            "filename": "$TEST_DIR/2.raw"
112        }
113    }
114}
115{ "execute": "blockdev-add",
116    "arguments": {
117        "driver": "quorum",
118        "node-name": "drive0-quorum",
119        "vote-threshold": 2,
120        "children": [
121            {
122                "driver": "$IMGFMT",
123                "file": {
124                    "driver": "file",
125                    "filename": "$TEST_DIR/1.raw"
126                }
127            },
128            "drive2",
129            {
130                "driver": "$IMGFMT",
131                "file": {
132                    "driver": "file",
133                    "filename": "$TEST_DIR/3.raw"
134                }
135            }
136        ]
137    }
138}
139{ "execute": "human-monitor-command",
140    "arguments": {
141        "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"'
142    }
143}
144{ "execute": "quit" }
145EOF
146
147echo
148echo "== using quorum rewrite corrupted mode =="
149
150quorum="$quorum,file.rewrite-corrupted=on"
151
152$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
153
154echo
155echo "== checking that quorum has corrected the corrupted file =="
156
157$QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
158
159echo
160echo "== breaking quorum =="
161
162$QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
163$QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
164
165echo
166echo "== checking that quorum is broken =="
167
168$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
169
170echo
171echo "== checking the blkverify mode with broken content =="
172
173quorum="driver=raw,file.driver=quorum,file.vote-threshold=2,file.blkverify=on"
174quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
175quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
176quorum="$quorum,file.children.0.driver=raw"
177quorum="$quorum,file.children.1.driver=raw"
178
179$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
180
181echo
182echo "== writing the same data to both files =="
183
184$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io
185$QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
186
187echo
188echo "== checking the blkverify mode with valid content =="
189
190$QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
191
192echo
193echo "== checking the blkverify mode with invalid settings =="
194
195quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
196quorum="$quorum,file.children.2.driver=raw"
197
198$QEMU_IO -c "open -o $quorum" | _filter_qemu_io
199
200echo
201echo "== dynamically adding a child to a quorum =="
202
203for verify in false true; do
204    run_qemu <<EOF
205    { "execute": "qmp_capabilities" }
206    { "execute": "blockdev-add",
207        "arguments": {
208            "driver": "quorum",
209            "node-name": "drive0-quorum",
210            "vote-threshold": 2,
211            "blkverify": ${verify},
212            "children": [
213                {
214                    "driver": "$IMGFMT",
215                    "file": {
216                        "driver": "file",
217                        "filename": "$TEST_DIR/1.raw"
218                    }
219                },
220                {
221                    "driver": "$IMGFMT",
222                    "file": {
223                        "driver": "file",
224                        "filename": "$TEST_DIR/2.raw"
225                    }
226                }
227            ]
228        }
229    }
230    { "execute": "blockdev-add",
231        "arguments": {
232            "node-name": "drive3",
233            "driver": "$IMGFMT",
234            "file": {
235                "driver": "file",
236                "filename": "$TEST_DIR/2.raw"
237            }
238        }
239    }
240    { "execute": "x-blockdev-change",
241      "arguments": { "parent": "drive0-quorum",
242                     "node": "drive3" } }
243    { "execute": "quit" }
244EOF
245done
246
247echo
248echo "== dynamically removing a child from a quorum =="
249
250for verify in false true; do
251    for vote_threshold in 1 2; do
252        run_qemu <<EOF
253        { "execute": "qmp_capabilities" }
254        { "execute": "blockdev-add",
255            "arguments": {
256                "driver": "quorum",
257                "node-name": "drive0-quorum",
258                "vote-threshold": ${vote_threshold},
259                "blkverify": ${verify},
260                "children": [
261                    {
262                        "driver": "$IMGFMT",
263                        "file": {
264                            "driver": "file",
265                            "filename": "$TEST_DIR/1.raw"
266                        }
267                    },
268                    {
269                        "driver": "$IMGFMT",
270                        "file": {
271                            "driver": "file",
272                            "filename": "$TEST_DIR/2.raw"
273                        }
274                    }
275                ]
276            }
277        }
278        { "execute": "x-blockdev-change",
279          "arguments": { "parent": "drive0-quorum",
280                         "child": "children.1" } }
281        { "execute": "quit" }
282EOF
283    done
284done
285
286# success, all done
287echo "*** done"
288rm -f $seq.full
289status=0
290