docs: rstfy vfio-ap documentation
[qemu/ar7.git] / tests / qemu-iotests / 122
blobf7a3ae684a7c1b298d3f4a2d808b9f3e671c5fce
1 #!/usr/bin/env bash
3 # Test some qemu-img convert cases
5 # Copyright (C) 2015 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=kwolf@redhat.com
24 seq="$(basename $0)"
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 _cleanup()
31 for img in "$TEST_IMG".[123]; do
32 _rm_test_img "$img"
33 done
34 _cleanup_test_img
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
42 _supported_fmt qcow2
43 _supported_proto file
44 _supported_os Linux
47 TEST_IMG="$TEST_IMG".base _make_test_img 64M
48 $QEMU_IO -c "write -P 0x11 0 64M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir
51 echo
52 echo "=== Check allocation status regression with -B ==="
53 echo
55 _make_test_img -b "$TEST_IMG".base
56 $QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
57 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig
58 $QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
61 echo
62 echo "=== Check that zero clusters are kept in overlay ==="
63 echo
65 _make_test_img -b "$TEST_IMG".base
67 $QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
68 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig
69 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
70 $QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig
71 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
73 $QEMU_IO -c "write -z 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
74 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig
75 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
76 $QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig
77 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
80 echo
81 echo "=== Converting to an overlay larger than its backing file ==="
82 echo
84 TEST_IMG="$TEST_IMG".base _make_test_img 256M
85 # Needs to be at least how much an L2 table covers
86 # (64 kB/entry * 64 kB / 8 B/entry = 512 MB)
87 # That way, qcow2 will yield at least two status request responses.
88 # With just a single response, it would always say "Allocated in the
89 # backing file", so the optimization qemu-img convert tries to do is
90 # done automatically. Once it has to be queried twice, however (and
91 # one of the queries is completely after the end of the backing file),
92 # the block layer will automatically add a ZERO flag that qemu-img
93 # convert used to follow up with a zero write to the target.
94 # We do not want such a zero write, however, because we are past the
95 # end of the backing file on the target as well, so we do not need to
96 # write anything there.
97 _make_test_img -b "$TEST_IMG".base 768M
99 # Use compat=0.10 as the output so there is no zero cluster support
100 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
101 "$TEST_IMG" "$TEST_IMG".orig
102 # See that nothing has been allocated past 64M
103 $QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
105 echo
107 # Just before the end of the backing file
108 $QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io
109 # Somewhere in the second L2 table
110 $QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io
112 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
113 "$TEST_IMG" "$TEST_IMG".orig
115 $QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
116 $QEMU_IO -c 'read -P 0x11 255M 1M' \
117 -c 'read -P 0x22 600M 1M' \
118 "$TEST_IMG".orig \
119 | _filter_qemu_io
122 echo
123 echo "=== Concatenate multiple source images ==="
124 echo
126 TEST_IMG="$TEST_IMG".1 _make_test_img 4M
127 TEST_IMG="$TEST_IMG".2 _make_test_img 4M
128 TEST_IMG="$TEST_IMG".3 _make_test_img 4M
130 $QEMU_IO -c "write -P 0x11 0 64k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
131 $QEMU_IO -c "write -P 0x22 0 64k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir
132 $QEMU_IO -c "write -P 0x33 0 64k" "$TEST_IMG".3 2>&1 | _filter_qemu_io | _filter_testdir
134 $QEMU_IMG convert -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG"
135 $QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
136 $QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
137 $QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
138 $QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
140 $QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG"
141 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
142 $QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
143 $QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
144 $QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
146 # -B can't be combined with concatenation
147 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG"
148 $QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG"
151 echo
152 echo "=== Compression with misaligned allocations and image sizes ==="
153 echo
155 TEST_IMG="$TEST_IMG".1 _make_test_img 1023k -o cluster_size=1024
156 TEST_IMG="$TEST_IMG".2 _make_test_img 1023k -o cluster_size=1024
158 $QEMU_IO -c "write -P 0x11 16k 16k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
159 $QEMU_IO -c "write -P 0x22 130k 130k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
160 $QEMU_IO -c "write -P 0x33 1022k 1k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
161 $QEMU_IO -c "write -P 0x44 0k 1k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir
163 $QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[12] "$TEST_IMG"
164 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
165 $QEMU_IO -c "read -P 0 0k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
166 $QEMU_IO -c "read -P 0x11 16k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
167 $QEMU_IO -c "read -P 0 32k 98k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
168 $QEMU_IO -c "read -P 0x22 130k 130k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
169 $QEMU_IO -c "read -P 0 260k 762k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
170 $QEMU_IO -c "read -P 0x33 1022k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
171 $QEMU_IO -c "read -P 0x44 1023k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
172 $QEMU_IO -c "read -P 0 1024k 1022k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
175 echo
176 echo "=== Full allocation with -S 0 ==="
177 echo
179 # Standalone image
180 _make_test_img 64M
181 $QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
182 $QEMU_IO -c "write -P 0 3M 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
184 echo
185 echo convert -S 0:
186 $QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
187 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
188 $QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
189 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
191 echo
192 echo convert -c -S 0:
193 $QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
194 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
195 $QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
196 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
198 # With backing file
199 TEST_IMG="$TEST_IMG".base _make_test_img 64M
200 $QEMU_IO -c "write -P 0x11 0 32M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir
202 _make_test_img -b "$TEST_IMG".base 64M
203 $QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
205 echo
206 echo convert -S 0 with source backing file:
207 $QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
208 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
209 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
210 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
211 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
213 echo
214 echo convert -c -S 0 with source backing file:
215 $QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
216 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
217 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
218 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
219 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
221 # With keeping the backing file
222 echo
223 echo convert -S 0 -B ...
224 $QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
225 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
226 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
227 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
228 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
230 echo
231 echo convert -c -S 0 -B ...
232 $QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
233 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
234 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
235 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
236 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
239 echo
240 echo "=== Non-zero -S ==="
241 echo
243 _make_test_img 64M -o cluster_size=1k
244 $QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
245 $QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
246 $QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
247 $QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
249 for min_sparse in 4k 8k; do
250 echo
251 echo convert -S $min_sparse
252 $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig
253 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
255 echo
256 echo convert -c -S $min_sparse
257 # For compressed images, -S values other than 0 are ignored
258 $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -c -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig
259 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
260 done
263 echo
264 echo '=== -n to a non-zero image ==='
265 echo
267 # Keep source zero
268 _make_test_img 64M
270 # Output is not zero, but has bdrv_has_zero_init() == 1
271 TEST_IMG="$TEST_IMG".orig _make_test_img 64M
272 $QEMU_IO -c "write -P 42 0 64k" "$TEST_IMG".orig | _filter_qemu_io
274 # Convert with -n, which should not assume that the target is zeroed
275 $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG".orig
277 $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG".orig
279 echo
280 echo '=== -n -B to an image without a backing file ==='
281 echo
283 # Base for the output
284 TEST_IMG="$TEST_IMG".base _make_test_img 64M
286 # Output that does have $TEST_IMG.base set as its (implicit) backing file
287 TEST_IMG="$TEST_IMG".orig _make_test_img 64M
289 # Convert with -n, which should not confuse -B with "target BDS has a
290 # backing file"
291 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -n "$TEST_IMG" "$TEST_IMG".orig
293 # success, all done
294 echo '*** done'
295 rm -f $seq.full
296 status=0