]> Git Repo - qemu.git/blob - tests/qemu-iotests/033
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20190521-3' into staging
[qemu.git] / tests / qemu-iotests / 033
1 #!/usr/bin/env bash
2 #
3 # Test aligned and misaligned write zeroes operations.
4 #
5 # Copyright (C) 2012 Red Hat, Inc.
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 [email protected]
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         _cleanup_test_img
32 }
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38
39 _supported_fmt generic
40 _supported_proto generic
41
42
43 size=128M
44 _make_test_img $size
45
46 do_test()
47 {
48         local align=$1
49         local iocmd=$2
50         local img=$3
51         if [ "$IMGOPTSSYNTAX" = "true" ]
52         then
53             IO_OPEN_ARG="$img"
54             IO_EXTRA_ARGS="--image-opts"
55         else
56             IO_OPEN_ARG="-o driver=$IMGFMT,file.align=$align blkdebug::$img"
57             IO_EXTRA_ARGS=""
58         fi
59         {
60                 echo "open $IO_OPEN_ARG"
61                 echo $iocmd
62         } | $QEMU_IO $IO_EXTRA_ARGS
63 }
64
65 echo
66 echo "=== Test aligned and misaligned write zeroes operations ==="
67
68 for write_zero_cmd in "write -z" "aio_write -z"; do
69 for align in 512 4k; do
70         echo
71         echo "== preparing image =="
72         do_test $align "write -P 0xa 0x200 0x400" "$TEST_IMG" | _filter_qemu_io
73         do_test $align "write -P 0xa 0x20000 0x600" "$TEST_IMG" | _filter_qemu_io
74         do_test $align "$write_zero_cmd 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
75
76         echo
77         echo "== verifying patterns (1) =="
78         do_test $align "read -P 0xa 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
79         do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
80         do_test $align "read -P 0xa 0x20400 0x200" "$TEST_IMG" | _filter_qemu_io
81
82         echo
83         echo "== rewriting zeroes =="
84         do_test $align "write -P 0xb 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
85         do_test $align "$write_zero_cmd 0x10000 0x10000" "$TEST_IMG" | _filter_qemu_io
86
87         echo
88         echo "== verifying patterns (2) =="
89         do_test $align "read -P 0x0 0x400 0x20000" "$TEST_IMG" | _filter_qemu_io
90
91         echo
92         echo "== rewriting unaligned zeroes =="
93         do_test $align "write -P 0xb 0x0 0x1000" "$TEST_IMG" | _filter_qemu_io
94         do_test $align "$write_zero_cmd 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
95
96         echo
97         echo "== verifying patterns (3) =="
98         do_test $align "read -P 0xb 0x0 0x200" "$TEST_IMG" | _filter_qemu_io
99         do_test $align "read -P 0x0 0x200 0x200" "$TEST_IMG" | _filter_qemu_io
100         do_test $align "read -P 0xb 0x400 0xc00" "$TEST_IMG" | _filter_qemu_io
101
102         echo
103 done
104 done
105
106 _cleanup_test_img
107
108 # Trigger truncate that would shrink qcow2 L1 table, which is done by
109 #   clearing one entry (8 bytes) with bdrv_co_pwrite_zeroes()
110
111 echo
112 echo "=== Test misaligned write zeroes via truncate ==="
113 echo
114
115 # any size will do, but the smaller the size the smaller the required image
116 CLUSTER_SIZE=$((4 * 1024))
117 L2_COVERAGE=$(($CLUSTER_SIZE * $CLUSTER_SIZE / 8))
118 _make_test_img $(($L2_COVERAGE * 2))
119
120 do_test 512 "write -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io
121 # next L2 table
122 do_test 512 "write -P 1 $L2_COVERAGE 0x200" "$TEST_IMG" | _filter_qemu_io
123
124 # only interested in qcow2 here; also other formats might respond with
125 #  "not supported" error message
126 if [ $IMGFMT = "qcow2" ]; then
127     do_test 512 "truncate $L2_COVERAGE" "$TEST_IMG" | _filter_qemu_io
128 fi
129
130 do_test 512 "read -P 1 0 0x200" "$TEST_IMG" | _filter_qemu_io
131
132 # success, all done
133 echo
134 echo "*** done"
135 rm -f $seq.full
136 status=0
This page took 0.035946 seconds and 4 git commands to generate.