Merge remote-tracking branch 'remotes/ehabkost/tags/x86-next-for-5.1-pull-request...
[qemu/ar7.git] / tests / qemu-iotests / 122
blob0f3d4ca851bfe26b05770a9864bb0fe0373d4f91
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 -F $IMGFMT
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 \
58 -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig
59 $QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
62 echo
63 echo "=== Check that zero clusters are kept in overlay ==="
64 echo
66 _make_test_img -b "$TEST_IMG".base -F $IMGFMT
68 $QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
69 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
70 "$TEST_IMG" "$TEST_IMG".orig
71 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
72 $QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
73 "$TEST_IMG" "$TEST_IMG".orig
74 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
76 $QEMU_IO -c "write -z 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
77 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
78 "$TEST_IMG" "$TEST_IMG".orig
79 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
80 $QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
81 "$TEST_IMG" "$TEST_IMG".orig
82 $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
85 echo
86 echo "=== Converting to an overlay larger than its backing file ==="
87 echo
89 TEST_IMG="$TEST_IMG".base _make_test_img 256M
90 # Needs to be at least how much an L2 table covers
91 # (64 kB/entry * 64 kB / 8 B/entry = 512 MB)
92 # That way, qcow2 will yield at least two status request responses.
93 # With just a single response, it would always say "Allocated in the
94 # backing file", so the optimization qemu-img convert tries to do is
95 # done automatically. Once it has to be queried twice, however (and
96 # one of the queries is completely after the end of the backing file),
97 # the block layer will automatically add a ZERO flag that qemu-img
98 # convert used to follow up with a zero write to the target.
99 # We do not want such a zero write, however, because we are past the
100 # end of the backing file on the target as well, so we do not need to
101 # write anything there.
102 _make_test_img -b "$TEST_IMG".base 768M -F $IMGFMT
104 # Use compat=0.10 as the output so there is no zero cluster support
105 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
106 -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig
107 # See that nothing has been allocated past 64M
108 $QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
110 echo
112 # Just before the end of the backing file
113 $QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io
114 # Somewhere in the second L2 table
115 $QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io
117 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
118 -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig
120 $QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
121 $QEMU_IO -c 'read -P 0x11 255M 1M' \
122 -c 'read -P 0x22 600M 1M' \
123 "$TEST_IMG".orig \
124 | _filter_qemu_io
127 echo
128 echo "=== Concatenate multiple source images ==="
129 echo
131 TEST_IMG="$TEST_IMG".1 _make_test_img 4M
132 TEST_IMG="$TEST_IMG".2 _make_test_img 4M
133 TEST_IMG="$TEST_IMG".3 _make_test_img 4M
135 $QEMU_IO -c "write -P 0x11 0 64k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
136 $QEMU_IO -c "write -P 0x22 0 64k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir
137 $QEMU_IO -c "write -P 0x33 0 64k" "$TEST_IMG".3 2>&1 | _filter_qemu_io | _filter_testdir
139 $QEMU_IMG convert -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG"
140 $QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
141 $QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
142 $QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
143 $QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
145 $QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG"
146 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
147 $QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
148 $QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
149 $QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
151 # -B can't be combined with concatenation
152 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG"
153 $QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG"
156 echo
157 echo "=== Compression with misaligned allocations and image sizes ==="
158 echo
160 TEST_IMG="$TEST_IMG".1 _make_test_img 1023k -o cluster_size=1024
161 TEST_IMG="$TEST_IMG".2 _make_test_img 1023k -o cluster_size=1024
163 $QEMU_IO -c "write -P 0x11 16k 16k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
164 $QEMU_IO -c "write -P 0x22 130k 130k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
165 $QEMU_IO -c "write -P 0x33 1022k 1k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
166 $QEMU_IO -c "write -P 0x44 0k 1k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir
168 $QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[12] "$TEST_IMG"
169 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
170 $QEMU_IO -c "read -P 0 0k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
171 $QEMU_IO -c "read -P 0x11 16k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
172 $QEMU_IO -c "read -P 0 32k 98k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
173 $QEMU_IO -c "read -P 0x22 130k 130k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
174 $QEMU_IO -c "read -P 0 260k 762k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
175 $QEMU_IO -c "read -P 0x33 1022k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
176 $QEMU_IO -c "read -P 0x44 1023k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
177 $QEMU_IO -c "read -P 0 1024k 1022k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
180 echo
181 echo "=== Full allocation with -S 0 ==="
182 echo
184 # Standalone image
185 _make_test_img 64M
186 $QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
187 $QEMU_IO -c "write -P 0 3M 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
189 echo
190 echo convert -S 0:
191 $QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
192 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
193 $QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
194 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
196 echo
197 echo convert -c -S 0:
198 $QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
199 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
200 $QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
201 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
203 # With backing file
204 TEST_IMG="$TEST_IMG".base _make_test_img 64M
205 $QEMU_IO -c "write -P 0x11 0 32M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir
207 _make_test_img -b "$TEST_IMG".base 64M -F $IMGFMT
208 $QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
210 echo
211 echo convert -S 0 with source backing file:
212 $QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
213 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
214 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
215 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
216 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
218 echo
219 echo convert -c -S 0 with source backing file:
220 $QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
221 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
222 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
223 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
224 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
226 # With keeping the backing file
227 echo
228 echo convert -S 0 -B ...
229 $QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
230 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
231 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
232 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
233 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
235 echo
236 echo convert -c -S 0 -B ...
237 $QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
238 $QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
239 $QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
240 $QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
241 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
244 echo
245 echo "=== Non-zero -S ==="
246 echo
248 _make_test_img 64M -o cluster_size=1k
249 $QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
250 $QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
251 $QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
252 $QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
254 for min_sparse in 4k 8k; do
255 echo
256 echo convert -S $min_sparse
257 $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig
258 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
260 echo
261 echo convert -c -S $min_sparse
262 # For compressed images, -S values other than 0 are ignored
263 $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -c -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig
264 $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
265 done
268 echo
269 echo '=== -n to a non-zero image ==='
270 echo
272 # Keep source zero
273 _make_test_img 64M
275 # Output is not zero, but has bdrv_has_zero_init() == 1
276 TEST_IMG="$TEST_IMG".orig _make_test_img 64M
277 $QEMU_IO -c "write -P 42 0 64k" "$TEST_IMG".orig | _filter_qemu_io
279 # Convert with -n, which should not assume that the target is zeroed
280 $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG".orig
282 $QEMU_IMG compare "$TEST_IMG" "$TEST_IMG".orig
284 echo
285 echo '=== -n to an empty image ==='
286 echo
288 TEST_IMG="$TEST_IMG".orig _make_test_img 64M
290 # Convert with -n, which should not result in a fully allocated image, not even
291 # with compat=0.10 (because the target doesn't have a backing file)
292 for compat in "1.1" "0.10"; do
293 IMGOPTS="compat=$compat" _make_test_img 64M
294 $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG".orig "$TEST_IMG"
295 $QEMU_IMG map --output=json "$TEST_IMG"
296 done
298 echo
299 echo '=== -n to an empty image with a backing file ==='
300 echo
302 TEST_IMG="$TEST_IMG".orig _make_test_img 64M
303 TEST_IMG="$TEST_IMG".base _make_test_img 64M
305 # Convert with -n, which should still not result in a fully allocated image for
306 # compat=1.1 (because it can use zero clusters), but it should be fully
307 # allocated with compat=0.10
308 for compat in "1.1" "0.10"; do
309 IMGOPTS="compat=$compat" _make_test_img -b "$TEST_IMG".base -F $IMGFMT 64M
310 $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG".orig "$TEST_IMG"
311 $QEMU_IMG map --output=json "$TEST_IMG"
312 done
314 echo
315 echo '=== -n -B to an image without a backing file ==='
316 echo
318 # Base for the output
319 TEST_IMG="$TEST_IMG".base _make_test_img 64M
321 # Output that does have $TEST_IMG.base set as its (implicit) backing file
322 TEST_IMG="$TEST_IMG".orig _make_test_img 64M
324 # Convert with -n, which should not confuse -B with "target BDS has a
325 # backing file"
326 $QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -n "$TEST_IMG" "$TEST_IMG".orig
328 echo
329 echo '=== -n incompatible with -o ==='
330 echo
332 $QEMU_IMG convert -O $IMGFMT -o preallocation=metadata -n \
333 "$TEST_IMG" "$TEST_IMG".orig && echo "unexpected success"
335 # success, all done
336 echo '*** done'
337 rm -f $seq.full
338 status=0