qapi/error: Check format string argument in error_*prepend()
[qemu/armbru.git] / tests / qemu-iotests / 197
blob95f05b0e346084846fbbc5d3a9433e94dc6a72c0
1 #!/usr/bin/env bash
3 # Test case for copy-on-read into qcow2
5 # Copyright (C) 2017 Red Hat, Inc.
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.
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.
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/>.
21 # creator
22 owner=eblake@redhat.com
24 seq="$(basename $0)"
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 # get standard environment, filters and checks
30 . ./common.rc
31 . ./common.filter
33 TEST_WRAP="$TEST_DIR/t.wrap.qcow2"
34 BLKDBG_CONF="$TEST_DIR/blkdebug.conf"
36 # Sanity check: our use of blkdebug fails if $TEST_DIR contains spaces
37 # or other problems
38 case "$TEST_DIR" in
39 *[^-_a-zA-Z0-9/]*)
40 _notrun "Suspicious TEST_DIR='$TEST_DIR', cowardly refusing to run" ;;
41 esac
43 _cleanup()
45 _cleanup_test_img
46 _rm_test_img "$TEST_WRAP"
47 rm -f "$BLKDBG_CONF"
49 trap "_cleanup; exit \$status" 0 1 2 3 15
51 # Test is supported for any backing file; but we force qcow2 for our wrapper.
52 _supported_fmt generic
53 _supported_proto generic
54 # LUKS support may be possible, but it complicates things.
55 _unsupported_fmt luks
56 _unsupported_imgopts "subformat=streamOptimized"
58 echo
59 echo '=== Copy-on-read ==='
60 echo
62 # Prep the images
63 # VPC rounds image sizes to a specific geometry, force a specific size.
64 if [ "$IMGFMT" = "vpc" ]; then
65 IMGOPTS=$(_optstr_add "$IMGOPTS" "force_size")
67 _make_test_img 4G
68 $QEMU_IO -c "write -P 55 3G 1k" "$TEST_IMG" | _filter_qemu_io
69 IMGPROTO=file IMGFMT=qcow2 TEST_IMG_FILE="$TEST_WRAP" \
70 _make_test_img --no-opts -F "$IMGFMT" -b "$TEST_IMG" | _filter_img_create
71 $QEMU_IO -f qcow2 -c "write -z -u 1M 64k" "$TEST_WRAP" | _filter_qemu_io
73 # Ensure that a read of two clusters, but where one is already allocated,
74 # does not re-write the allocated cluster
75 cat > "$BLKDBG_CONF" <<EOF
76 [inject-error]
77 event = "cor_write"
78 sector = "2048"
79 EOF
80 $QEMU_IO -c "open -C \
81 -o driver=blkdebug,config=$BLKDBG_CONF,image.driver=qcow2 $TEST_WRAP" \
82 -c "read -P 0 1M 128k" | _filter_qemu_io
84 # Read the areas we want copied. A zero-length read should still be a
85 # no-op. The next read is under 2G, but aligned so that rounding to
86 # clusters copies more than 2G of zeroes. The final read will pick up
87 # the non-zero data in the same cluster. Since a 2G read may exhaust
88 # memory on some machines (particularly 32-bit), we skip the test if
89 # that fails due to memory pressure.
90 $QEMU_IO -f qcow2 -C -c "read 0 0" "$TEST_WRAP" | _filter_qemu_io
91 output=$($QEMU_IO -f qcow2 -C -c "read -P 0 1k $((2*1024*1024*1024 - 512))" \
92 "$TEST_WRAP" 2>&1 | _filter_qemu_io)
93 case $output in
94 *allocate*)
95 _notrun "Insufficent memory to run test" ;;
96 *) printf '%s\n' "$output" ;;
97 esac
98 $QEMU_IO -f qcow2 -C -c "read -P 0 $((3*1024*1024*1024 + 1024)) 1k" \
99 "$TEST_WRAP" | _filter_qemu_io
101 # Copy-on-read is incompatible with read-only
102 $QEMU_IO -f qcow2 -C -r "$TEST_WRAP" 2>&1 | _filter_testdir
104 # Break the backing chain, and show that images are identical, and that
105 # we properly copied over explicit zeros.
106 $QEMU_IMG rebase -u -b "" -f qcow2 "$TEST_WRAP"
107 $QEMU_IO -f qcow2 -c map "$TEST_WRAP"
108 _check_test_img
109 $QEMU_IMG compare -f $IMGFMT -F qcow2 "$TEST_IMG" "$TEST_WRAP"
111 echo
112 echo '=== Partial final cluster ==='
113 echo
115 _make_test_img 1024
116 $QEMU_IO -f $IMGFMT -C -c 'read 0 1024' "$TEST_IMG" | _filter_qemu_io
117 $QEMU_IO -f $IMGFMT -c map "$TEST_IMG"
118 _check_test_img
120 # success, all done
121 echo '*** done'
122 status=0