Philippe Mathieu-Daudé | 11a82d1 | 2019-03-07 15:58:38 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 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 | |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 27 | status=1 # failure is the default! |
| 28 | |
| 29 | _cleanup() |
| 30 | { |
Max Reitz | f91ecbd | 2019-11-07 17:37:01 +0100 | [diff] [blame] | 31 | _rm_test_img "$TEST_DIR/1.raw" |
| 32 | _rm_test_img "$TEST_DIR/2.raw" |
| 33 | _rm_test_img "$TEST_DIR/3.raw" |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 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 |
Peter Lieven | c5f7c0a | 2014-10-20 13:47:11 +0200 | [diff] [blame] | 42 | _supported_proto file |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 43 | _supported_os Linux |
Thomas Huth | 21b43d0 | 2019-08-23 15:35:52 +0200 | [diff] [blame] | 44 | _require_drivers quorum |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 45 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 46 | do_run_qemu() |
Max Reitz | 6141f3b | 2014-02-21 22:30:38 +0100 | [diff] [blame] | 47 | { |
| 48 | echo Testing: "$@" | _filter_imgfmt |
| 49 | $QEMU -nographic -qmp stdio -serial none "$@" |
| 50 | echo |
| 51 | } |
| 52 | |
Eric Blake | 8cedcff | 2018-11-16 15:50:02 -0600 | [diff] [blame] | 53 | run_qemu() |
Max Reitz | 6141f3b | 2014-02-21 22:30:38 +0100 | [diff] [blame] | 54 | { |
Jeff Cody | 15489c7 | 2015-10-12 19:36:50 -0400 | [diff] [blame] | 55 | do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp\ |
| 56 | | _filter_qemu_io | _filter_generated_node_ids |
Max Reitz | 6141f3b | 2014-02-21 22:30:38 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Kevin Wolf | 8f9e835 | 2014-11-20 16:27:07 +0100 | [diff] [blame] | 59 | quorum="driver=raw,file.driver=quorum,file.vote-threshold=2" |
| 60 | quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 61 | quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" |
Kevin Wolf | 8f9e835 | 2014-11-20 16:27:07 +0100 | [diff] [blame] | 62 | quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw" |
| 63 | quorum="$quorum,file.children.0.driver=raw" |
| 64 | quorum="$quorum,file.children.1.driver=raw" |
| 65 | quorum="$quorum,file.children.2.driver=raw" |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 66 | |
| 67 | echo |
| 68 | echo "== creating quorum files ==" |
| 69 | |
| 70 | size=10M |
| 71 | |
| 72 | TEST_IMG="$TEST_DIR/1.raw" _make_test_img $size |
| 73 | TEST_IMG="$TEST_DIR/2.raw" _make_test_img $size |
| 74 | TEST_IMG="$TEST_DIR/3.raw" _make_test_img $size |
| 75 | |
| 76 | echo |
| 77 | echo "== writing images ==" |
| 78 | |
| 79 | $QEMU_IO -c "open -o $quorum" -c "write -P 0x32 0 $size" | _filter_qemu_io |
| 80 | |
| 81 | echo |
| 82 | echo "== checking quorum write ==" |
| 83 | |
| 84 | $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io |
| 85 | $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io |
| 86 | $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/3.raw" | _filter_qemu_io |
| 87 | |
| 88 | echo |
| 89 | echo "== corrupting image ==" |
| 90 | |
| 91 | $QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io |
| 92 | |
| 93 | echo |
| 94 | echo "== checking quorum correction ==" |
| 95 | |
| 96 | $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io |
| 97 | |
| 98 | echo |
Max Reitz | 6141f3b | 2014-02-21 22:30:38 +0100 | [diff] [blame] | 99 | echo "== checking mixed reference/option specification ==" |
| 100 | |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 101 | run_qemu <<EOF |
Max Reitz | 6141f3b | 2014-02-21 22:30:38 +0100 | [diff] [blame] | 102 | { "execute": "qmp_capabilities" } |
| 103 | { "execute": "blockdev-add", |
| 104 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 105 | "node-name": "drive2", |
| 106 | "driver": "$IMGFMT", |
| 107 | "file": { |
| 108 | "driver": "file", |
| 109 | "filename": "$TEST_DIR/2.raw" |
Max Reitz | 8e9e653 | 2015-10-19 17:53:10 +0200 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
| 113 | { "execute": "blockdev-add", |
| 114 | "arguments": { |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 115 | "driver": "quorum", |
| 116 | "node-name": "drive0-quorum", |
| 117 | "vote-threshold": 2, |
| 118 | "children": [ |
| 119 | { |
| 120 | "driver": "$IMGFMT", |
| 121 | "file": { |
| 122 | "driver": "file", |
| 123 | "filename": "$TEST_DIR/1.raw" |
Max Reitz | 6141f3b | 2014-02-21 22:30:38 +0100 | [diff] [blame] | 124 | } |
Kevin Wolf | 0153d2f | 2016-10-07 17:05:04 +0200 | [diff] [blame] | 125 | }, |
| 126 | "drive2", |
| 127 | { |
| 128 | "driver": "$IMGFMT", |
| 129 | "file": { |
| 130 | "driver": "file", |
| 131 | "filename": "$TEST_DIR/3.raw" |
| 132 | } |
| 133 | } |
| 134 | ] |
Max Reitz | 6141f3b | 2014-02-21 22:30:38 +0100 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | { "execute": "human-monitor-command", |
| 138 | "arguments": { |
| 139 | "command-line": 'qemu-io drive0-quorum "read -P 0x32 0 $size"' |
| 140 | } |
| 141 | } |
| 142 | { "execute": "quit" } |
| 143 | EOF |
| 144 | |
| 145 | echo |
Benoît Canet | cf29a57 | 2014-06-11 15:24:10 +0200 | [diff] [blame] | 146 | echo "== using quorum rewrite corrupted mode ==" |
| 147 | |
| 148 | quorum="$quorum,file.rewrite-corrupted=on" |
| 149 | |
| 150 | $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io |
| 151 | |
| 152 | echo |
| 153 | echo "== checking that quorum has corrected the corrupted file ==" |
| 154 | |
| 155 | $QEMU_IO -c "read -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io |
| 156 | |
| 157 | echo |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 158 | echo "== breaking quorum ==" |
| 159 | |
| 160 | $QEMU_IO -c "write -P 0x41 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io |
Benoît Canet | cf29a57 | 2014-06-11 15:24:10 +0200 | [diff] [blame] | 161 | $QEMU_IO -c "write -P 0x42 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io |
| 162 | |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 163 | echo |
| 164 | echo "== checking that quorum is broken ==" |
| 165 | |
| 166 | $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io |
| 167 | |
Alberto Garcia | 82c4c85 | 2018-10-17 17:33:51 +0300 | [diff] [blame] | 168 | echo |
| 169 | echo "== checking the blkverify mode with broken content ==" |
| 170 | |
| 171 | quorum="driver=raw,file.driver=quorum,file.vote-threshold=2,file.blkverify=on" |
| 172 | quorum="$quorum,file.children.0.file.filename=$TEST_DIR/1.raw" |
| 173 | quorum="$quorum,file.children.1.file.filename=$TEST_DIR/2.raw" |
| 174 | quorum="$quorum,file.children.0.driver=raw" |
| 175 | quorum="$quorum,file.children.1.driver=raw" |
| 176 | |
| 177 | $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io |
| 178 | |
| 179 | echo |
| 180 | echo "== writing the same data to both files ==" |
| 181 | |
| 182 | $QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/1.raw" | _filter_qemu_io |
| 183 | $QEMU_IO -c "write -P 0x32 0 $size" "$TEST_DIR/2.raw" | _filter_qemu_io |
| 184 | |
| 185 | echo |
| 186 | echo "== checking the blkverify mode with valid content ==" |
| 187 | |
| 188 | $QEMU_IO -c "open -o $quorum" -c "read -P 0x32 0 $size" | _filter_qemu_io |
| 189 | |
| 190 | echo |
| 191 | echo "== checking the blkverify mode with invalid settings ==" |
| 192 | |
| 193 | quorum="$quorum,file.children.2.file.filename=$TEST_DIR/3.raw" |
| 194 | quorum="$quorum,file.children.2.driver=raw" |
| 195 | |
| 196 | $QEMU_IO -c "open -o $quorum" | _filter_qemu_io |
| 197 | |
Alberto Garcia | 04f600e | 2018-10-18 11:59:04 +0300 | [diff] [blame] | 198 | echo |
| 199 | echo "== dynamically adding a child to a quorum ==" |
| 200 | |
| 201 | for verify in false true; do |
| 202 | run_qemu <<EOF |
| 203 | { "execute": "qmp_capabilities" } |
| 204 | { "execute": "blockdev-add", |
| 205 | "arguments": { |
| 206 | "driver": "quorum", |
| 207 | "node-name": "drive0-quorum", |
| 208 | "vote-threshold": 2, |
| 209 | "blkverify": ${verify}, |
| 210 | "children": [ |
| 211 | { |
| 212 | "driver": "$IMGFMT", |
| 213 | "file": { |
| 214 | "driver": "file", |
| 215 | "filename": "$TEST_DIR/1.raw" |
| 216 | } |
| 217 | }, |
| 218 | { |
| 219 | "driver": "$IMGFMT", |
| 220 | "file": { |
| 221 | "driver": "file", |
| 222 | "filename": "$TEST_DIR/2.raw" |
| 223 | } |
| 224 | } |
| 225 | ] |
| 226 | } |
| 227 | } |
| 228 | { "execute": "blockdev-add", |
| 229 | "arguments": { |
| 230 | "node-name": "drive3", |
| 231 | "driver": "$IMGFMT", |
| 232 | "file": { |
| 233 | "driver": "file", |
| 234 | "filename": "$TEST_DIR/2.raw" |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | { "execute": "x-blockdev-change", |
| 239 | "arguments": { "parent": "drive0-quorum", |
| 240 | "node": "drive3" } } |
| 241 | { "execute": "quit" } |
| 242 | EOF |
| 243 | done |
| 244 | |
| 245 | echo |
| 246 | echo "== dynamically removing a child from a quorum ==" |
| 247 | |
| 248 | for verify in false true; do |
| 249 | for vote_threshold in 1 2; do |
| 250 | run_qemu <<EOF |
| 251 | { "execute": "qmp_capabilities" } |
| 252 | { "execute": "blockdev-add", |
| 253 | "arguments": { |
| 254 | "driver": "quorum", |
| 255 | "node-name": "drive0-quorum", |
| 256 | "vote-threshold": ${vote_threshold}, |
| 257 | "blkverify": ${verify}, |
| 258 | "children": [ |
| 259 | { |
| 260 | "driver": "$IMGFMT", |
| 261 | "file": { |
| 262 | "driver": "file", |
| 263 | "filename": "$TEST_DIR/1.raw" |
| 264 | } |
| 265 | }, |
| 266 | { |
| 267 | "driver": "$IMGFMT", |
| 268 | "file": { |
| 269 | "driver": "file", |
| 270 | "filename": "$TEST_DIR/2.raw" |
| 271 | } |
| 272 | } |
| 273 | ] |
| 274 | } |
| 275 | } |
| 276 | { "execute": "x-blockdev-change", |
| 277 | "arguments": { "parent": "drive0-quorum", |
| 278 | "child": "children.1" } } |
| 279 | { "execute": "quit" } |
| 280 | EOF |
| 281 | done |
| 282 | done |
| 283 | |
Benoît Canet | c7fc5bc | 2014-02-21 22:21:21 +0100 | [diff] [blame] | 284 | # success, all done |
| 285 | echo "*** done" |
| 286 | rm -f $seq.full |
| 287 | status=0 |