xref: /openbmc/qemu/tests/qemu-iotests/081 (revision 393aac1629c8f82b7c448c8615745e89984899a8)
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
22 owner=benoit@irqsave.net
23 
24 seq=`basename $0`
25 echo "QA output created by $seq"
26 
27 status=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 }
35 trap "_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 
45 do_run_qemu()
46 {
47     echo Testing: "$@" | _filter_imgfmt
48     $QEMU -nographic -qmp stdio -serial none "$@"
49     echo
50 }
51 
52 run_qemu()
53 {
54     do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\
55                           | _filter_qemu_io | _filter_generated_node_ids
56 }
57 
58 test_quorum=$($QEMU_IMG --help|grep quorum)
59 [ "$test_quorum" = "" ] && _supported_fmt quorum
60 
61 quorum="driver=raw,file.driver=quorum,file.vote-threshold=2"
62 quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
63 quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
64 quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
65 quorum="$quorum,file.children.0.driver=raw"
66 quorum="$quorum,file.children.1.driver=raw"
67 quorum="$quorum,file.children.2.driver=raw"
68 
69 echo
70 echo "== creating quorum files =="
71 
72 size=10M
73 
74 TEST_IMG="$TEST_DIR/1.raw" _make_test_img $size
75 TEST_IMG="$TEST_DIR/2.raw" _make_test_img $size
76 TEST_IMG="$TEST_DIR/3.raw" _make_test_img $size
77 
78 echo
79 echo "== writing images =="
80 
81 $QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io
82 
83 echo
84 echo "== 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 
90 echo
91 echo "== corrupting image =="
92 
93 $QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io
94 
95 echo
96 echo "== checking quorum correction =="
97 
98 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
99 
100 echo
101 echo "== checking mixed reference/option specification =="
102 
103 run_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" }
145 EOF
146 
147 echo
148 echo "== using quorum rewrite corrupted mode =="
149 
150 quorum="$quorum,file.rewrite-corrupted=on"
151 
152 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
153 
154 echo
155 echo "== 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 
159 echo
160 echo "== 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 
165 echo
166 echo "== checking that quorum is broken =="
167 
168 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
169 
170 echo
171 echo "== checking the blkverify mode with broken content =="
172 
173 quorum="driver=raw,file.driver=quorum,file.vote-threshold=2,file.blkverify=on"
174 quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw"
175 quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw"
176 quorum="$quorum,file.children.0.driver=raw"
177 quorum="$quorum,file.children.1.driver=raw"
178 
179 $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io
180 
181 echo
182 echo "== 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 
187 echo
188 echo "== 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 
192 echo
193 echo "== checking the blkverify mode with invalid settings =="
194 
195 quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw"
196 quorum="$quorum,file.children.2.driver=raw"
197 
198 $QEMU_IO -c "open -o $quorum" | _filter_qemu_io
199 
200 echo
201 echo "== dynamically adding a child to a quorum =="
202 
203 for 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" }
244 EOF
245 done
246 
247 echo
248 echo "== dynamically removing a child from a quorum =="
249 
250 for 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" }
282 EOF
283     done
284 done
285 
286 # success, all done
287 echo "*** done"
288 rm -f $seq.full
289 status=0
290