qapi/error: Check format string argument in error_*prepend()
[qemu/armbru.git] / tests / qemu-iotests / 154
blob7f1c0d9bd98109cb3fd0c28b6a6ca2b0b821cc6f
1 #!/usr/bin/env bash
3 # qcow2 specific bdrv_pwrite_zeroes tests with backing files (complements 034)
5 # Copyright (C) 2016-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=kwolf@redhat.com
24 seq=`basename $0`
25 echo "QA output created by $seq"
27 status=1 # failure is the default!
29 _cleanup()
31 _cleanup_test_img
33 trap "_cleanup; exit \$status" 0 1 2 3 15
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
39 _supported_fmt qcow2
40 _supported_proto file
41 _supported_os Linux
43 CLUSTER_SIZE=4k
44 size=$((128 * 1024 * 1024))
46 # This test requires zero clusters, added in v3 images
47 _unsupported_imgopts compat=0.10
49 echo
50 echo == backing file contains zeros ==
52 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
53 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
55 # Make sure that the whole cluster is allocated even for partial write_zeroes
56 # when the backing file contains zeros
58 # X = non-zero data sector in backing file
59 # - = sector unallocated in whole backing chain
60 # 0 = sector touched by write_zeroes request
62 # 1. Tail unaligned: 00 00 -- --
63 # 2. Head unaligned: -- -- 00 00
64 # 3. Both unaligned: -- 00 00 --
65 # 4. Both, 2 clusters: -- -- -- 00 | 00 -- -- --
67 $QEMU_IO -c "write -z 0 2k" "$TEST_IMG" | _filter_qemu_io
68 $QEMU_IO -c "write -z 10k 2k" "$TEST_IMG" | _filter_qemu_io
69 $QEMU_IO -c "write -z 17k 2k" "$TEST_IMG" | _filter_qemu_io
70 $QEMU_IO -c "write -z 27k 2k" "$TEST_IMG" | _filter_qemu_io
71 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
73 echo
74 echo == backing file contains non-zero data before write_zeroes ==
76 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
77 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
79 # Single cluster; non-zero data at the cluster start
80 # ... | XX -- 00 -- | ...
81 $QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io
82 $QEMU_IO -c "write -z 34k 1k" "$TEST_IMG" | _filter_qemu_io
83 $QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io
84 $QEMU_IO -c "read -P 0 33k 3k" "$TEST_IMG" | _filter_qemu_io
86 # Single cluster; non-zero data exists, but not at the cluster start
87 # ... | -- XX 00 -- | ...
88 $QEMU_IO -c "write -P 0x11 65k 1k" "$TEST_IMG.base" | _filter_qemu_io
89 $QEMU_IO -c "write -z 66k 1k" "$TEST_IMG" | _filter_qemu_io
90 $QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io
91 $QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io
92 $QEMU_IO -c "read -P 0 66k 2k" "$TEST_IMG" | _filter_qemu_io
94 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
96 echo
97 echo == backing file contains non-zero data after write_zeroes ==
99 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
100 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
102 # Single cluster; non-zero data directly after request
103 # ... | -- 00 XX -- | ...
104 $QEMU_IO -c "write -P 0x11 34k 1k" "$TEST_IMG.base" | _filter_qemu_io
105 $QEMU_IO -c "write -z 33k 1k" "$TEST_IMG" | _filter_qemu_io
106 $QEMU_IO -c "read -P 0 32k 2k" "$TEST_IMG" | _filter_qemu_io
107 $QEMU_IO -c "read -P 0x11 34k 1k" "$TEST_IMG" | _filter_qemu_io
108 $QEMU_IO -c "read -P 0 35k 1k" "$TEST_IMG" | _filter_qemu_io
110 # Single cluster; non-zero data exists, but not directly after request
111 # ... | -- 00 -- XX | ...
112 $QEMU_IO -c "write -P 0x11 43k 1k" "$TEST_IMG.base" | _filter_qemu_io
113 $QEMU_IO -c "write -z 41k 1k" "$TEST_IMG" | _filter_qemu_io
114 $QEMU_IO -c "read -P 0x11 43k 1k" "$TEST_IMG" | _filter_qemu_io
115 $QEMU_IO -c "read -P 0 40k 3k" "$TEST_IMG" | _filter_qemu_io
117 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
119 echo
120 echo == write_zeroes covers non-zero data ==
122 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
123 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
125 # non-zero data at front of request
126 # Backing file: -- XX -- --
127 # Active layer: -- 00 00 --
129 $QEMU_IO -c "write -P 0x11 5k 1k" "$TEST_IMG.base" | _filter_qemu_io
130 $QEMU_IO -c "write -z 5k 2k" "$TEST_IMG" | _filter_qemu_io
131 $QEMU_IO -c "read -P 0 4k 4k" "$TEST_IMG" | _filter_qemu_io
133 # non-zero data at end of request
134 # Backing file: -- -- XX --
135 # Active layer: -- 00 00 --
137 $QEMU_IO -c "write -P 0x11 14k 1k" "$TEST_IMG.base" | _filter_qemu_io
138 $QEMU_IO -c "write -z 13k 2k" "$TEST_IMG" | _filter_qemu_io
139 $QEMU_IO -c "read -P 0 12k 4k" "$TEST_IMG" | _filter_qemu_io
141 # non-zero data matches size of request
142 # Backing file: -- XX XX --
143 # Active layer: -- 00 00 --
145 $QEMU_IO -c "write -P 0x11 21k 2k" "$TEST_IMG.base" | _filter_qemu_io
146 $QEMU_IO -c "write -z 21k 2k" "$TEST_IMG" | _filter_qemu_io
147 $QEMU_IO -c "read -P 0 20k 4k" "$TEST_IMG" | _filter_qemu_io
149 # non-zero data smaller than request
150 # Backing file: -- -X X- --
151 # Active layer: -- 00 00 --
153 $QEMU_IO -c "write -P 0x11 30208 1k" "$TEST_IMG.base" | _filter_qemu_io
154 $QEMU_IO -c "write -z 29k 2k" "$TEST_IMG" | _filter_qemu_io
155 $QEMU_IO -c "read -P 0 28k 4k" "$TEST_IMG" | _filter_qemu_io
157 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
159 echo
160 echo == spanning two clusters, non-zero before request ==
162 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
163 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
165 # Two clusters; non-zero data before request:
166 # 1. At cluster start: 32k: XX -- -- 00 | 00 -- -- --
167 # 2. Between unallocated space: 48k: -- XX -- 00 | 00 -- -- --
168 # 3. Directly before request: 64k: -- -- XX 00 | 00 -- -- --
170 $QEMU_IO -c "write -P 0x11 32k 1k" "$TEST_IMG.base" | _filter_qemu_io
171 $QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io
172 $QEMU_IO -c "read -P 0x11 32k 1k" "$TEST_IMG" | _filter_qemu_io
173 $QEMU_IO -c "read -P 0 33k 7k" "$TEST_IMG" | _filter_qemu_io
175 $QEMU_IO -c "write -P 0x11 49k 1k" "$TEST_IMG.base" | _filter_qemu_io
176 $QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io
177 $QEMU_IO -c "read -P 0 48k 1k" "$TEST_IMG" | _filter_qemu_io
178 $QEMU_IO -c "read -P 0x11 49k 1k" "$TEST_IMG" | _filter_qemu_io
179 $QEMU_IO -c "read -P 0 50k 6k" "$TEST_IMG" | _filter_qemu_io
181 $QEMU_IO -c "write -P 0x11 66k 1k" "$TEST_IMG.base" | _filter_qemu_io
182 $QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io
183 $QEMU_IO -c "read -P 0 64k 2k" "$TEST_IMG" | _filter_qemu_io
184 $QEMU_IO -c "read -P 0x11 66k 1k" "$TEST_IMG" | _filter_qemu_io
185 $QEMU_IO -c "read -P 0 67k 5k" "$TEST_IMG" | _filter_qemu_io
187 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
189 echo
190 echo == spanning two clusters, non-zero after request ==
192 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
193 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
195 # Two clusters; non-zero data after request:
196 # 1. Directly after request: 32k: -- -- -- 00 | 00 XX -- --
197 # 2. Between unallocated space: 48k: -- -- -- 00 | 00 -- XX --
198 # 3. At cluster end: 64k: -- -- -- 00 | 00 -- -- XX
200 $QEMU_IO -c "write -P 0x11 37k 1k" "$TEST_IMG.base" | _filter_qemu_io
201 $QEMU_IO -c "write -z 35k 2k" "$TEST_IMG" | _filter_qemu_io
202 $QEMU_IO -c "read -P 0 32k 5k" "$TEST_IMG" | _filter_qemu_io
203 $QEMU_IO -c "read -P 0x11 37k 1k" "$TEST_IMG" | _filter_qemu_io
204 $QEMU_IO -c "read -P 0 38k 2k" "$TEST_IMG" | _filter_qemu_io
206 $QEMU_IO -c "write -P 0x11 54k 1k" "$TEST_IMG.base" | _filter_qemu_io
207 $QEMU_IO -c "write -z 51k 2k" "$TEST_IMG" | _filter_qemu_io
208 $QEMU_IO -c "read -P 0 48k 6k" "$TEST_IMG" | _filter_qemu_io
209 $QEMU_IO -c "read -P 0x11 54k 1k" "$TEST_IMG" | _filter_qemu_io
210 $QEMU_IO -c "read -P 0 55k 1k" "$TEST_IMG" | _filter_qemu_io
212 $QEMU_IO -c "write -P 0x11 71k 1k" "$TEST_IMG.base" | _filter_qemu_io
213 $QEMU_IO -c "write -z 67k 2k" "$TEST_IMG" | _filter_qemu_io
214 $QEMU_IO -c "read -P 0 64k 7k" "$TEST_IMG" | _filter_qemu_io
215 $QEMU_IO -c "read -P 0x11 71k 1k" "$TEST_IMG" | _filter_qemu_io
217 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
219 echo
220 echo == spanning two clusters, partially overwriting backing file ==
222 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
223 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
225 # Backing file: -- -- XX XX | XX XX -- --
226 # Active layer: -- -- XX 00 | 00 XX -- --
228 $QEMU_IO -c "write -P 0x11 2k 4k" "$TEST_IMG.base" | _filter_qemu_io
229 $QEMU_IO -c "write -z 3k 2k" "$TEST_IMG" | _filter_qemu_io
230 $QEMU_IO -c "read -P 0 0k 2k" "$TEST_IMG" | _filter_qemu_io
231 $QEMU_IO -c "read -P 0x11 2k 1k" "$TEST_IMG" | _filter_qemu_io
232 $QEMU_IO -c "read -P 0 3k 2k" "$TEST_IMG" | _filter_qemu_io
233 $QEMU_IO -c "read -P 0x11 5k 1k" "$TEST_IMG" | _filter_qemu_io
234 $QEMU_IO -c "read -P 0 6k 2k" "$TEST_IMG" | _filter_qemu_io
236 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
238 echo
239 echo == spanning multiple clusters, non-zero in first cluster ==
241 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
242 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
244 # Backing file: 64k: XX XX -- -- | -- -- -- -- | -- -- -- --
245 # Active layer: 64k: XX XX 00 00 | 00 00 00 00 | 00 -- -- --
247 $QEMU_IO -c "write -P 0x11 64k 2k" "$TEST_IMG.base" | _filter_qemu_io
248 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
249 $QEMU_IO -c "read -P 0x11 64k 2k" "$TEST_IMG" | _filter_qemu_io
250 $QEMU_IO -c "read -P 0 66k 10k" "$TEST_IMG" | _filter_qemu_io
252 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
254 echo
255 echo == spanning multiple clusters, non-zero in intermediate cluster ==
257 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
258 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
260 # Backing file: 64k: -- -- -- -- | -- XX XX -- | -- -- -- --
261 # Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- -- --
263 $QEMU_IO -c "write -P 0x11 69k 2k" "$TEST_IMG.base" | _filter_qemu_io
264 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
265 $QEMU_IO -c "read -P 0 64k 12k" "$TEST_IMG" | _filter_qemu_io
267 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
269 echo
270 echo == spanning multiple clusters, non-zero in final cluster ==
272 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
273 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
275 # Backing file: 64k: -- -- -- -- | -- -- -- -- | -- -- XX XX
276 # Active layer: 64k: -- -- 00 00 | 00 00 00 00 | 00 -- XX XX
278 $QEMU_IO -c "write -P 0x11 74k 2k" "$TEST_IMG.base" | _filter_qemu_io
279 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
280 $QEMU_IO -c "read -P 0 64k 10k" "$TEST_IMG" | _filter_qemu_io
281 $QEMU_IO -c "read -P 0x11 74k 2k" "$TEST_IMG" | _filter_qemu_io
283 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
285 echo
286 echo == spanning multiple clusters, partially overwriting backing file ==
288 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $size
289 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT
291 # Backing file: 64k: -- XX XX XX | XX XX XX XX | XX XX XX --
292 # Active layer: 64k: -- XX 00 00 | 00 00 00 00 | 00 XX XX --
294 $QEMU_IO -c "write -P 0x11 65k 10k" "$TEST_IMG.base" | _filter_qemu_io
295 $QEMU_IO -c "write -z 66k 7k" "$TEST_IMG" | _filter_qemu_io
296 $QEMU_IO -c "read -P 0 64k 1k" "$TEST_IMG" | _filter_qemu_io
297 $QEMU_IO -c "read -P 0x11 65k 1k" "$TEST_IMG" | _filter_qemu_io
298 $QEMU_IO -c "read -P 0 66k 7k" "$TEST_IMG" | _filter_qemu_io
299 $QEMU_IO -c "read -P 0x11 73k 2k" "$TEST_IMG" | _filter_qemu_io
300 $QEMU_IO -c "read -P 0 75k 1k" "$TEST_IMG" | _filter_qemu_io
302 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
304 echo
305 echo == unaligned image tail cluster, no allocation needed ==
307 # With no backing file, write to all or part of unallocated partial cluster
308 # will mark the cluster as zero, but does not allocate.
309 # Re-create the image each time to get back to unallocated clusters.
311 # Write at the front: sector-wise, the request is: 128m... | 00 -- -- --
312 _make_test_img $((size + 2048))
313 $QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
314 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
315 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
317 # Write at the back: sector-wise, the request is: 128m... | -- -- -- 00
318 _make_test_img $((size + 2048))
319 $QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
320 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
321 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
323 # Write at middle: sector-wise, the request is: 128m... | -- 00 00 --
324 _make_test_img $((size + 2048))
325 $QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
326 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
327 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
329 # Write entire cluster: sector-wise, the request is: 128m... | 00 00 00 00
330 _make_test_img $((size + 2048))
331 $QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
332 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
333 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
335 # Repeat with backing file holding unallocated cluster.
336 CLUSTER_SIZE=2048 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
338 # Write at the front: sector-wise, the request is:
339 # backing: 128m... | -- --
340 # active: 128m... | 00 -- -- --
341 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
342 $QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
343 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
344 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
346 # Write at the back: sector-wise, the request is:
347 # backing: 128m... | -- --
348 # active: 128m... | -- -- -- 00
349 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
350 $QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
351 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
352 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
354 # Write at middle: sector-wise, the request is:
355 # backing: 128m... | -- --
356 # active: 128m... | -- 00 00 --
357 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
358 $QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
359 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
360 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
362 # Write entire cluster: sector-wise, the request is:
363 # backing: 128m... | -- --
364 # active: 128m... | 00 00 00 00
365 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
366 $QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
367 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
368 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
370 # Repeat with backing file holding zero'd cluster
371 $QEMU_IO -c "write -z $size 512" "$TEST_IMG.base" | _filter_qemu_io
373 # Write at the front: sector-wise, the request is:
374 # backing: 128m... | 00 00
375 # active: 128m... | 00 -- -- --
376 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
377 $QEMU_IO -c "write -z $size 512" "$TEST_IMG" | _filter_qemu_io
378 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
379 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
381 # Write at the back: sector-wise, the request is:
382 # backing: 128m... | 00 00
383 # active: 128m... | -- -- -- 00
384 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
385 $QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
386 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
387 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
389 # Write at middle: sector-wise, the request is:
390 # backing: 128m... | 00 00
391 # active: 128m... | -- 00 00 --
392 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
393 $QEMU_IO -c "write -z $((size + 512)) 1024" "$TEST_IMG" | _filter_qemu_io
394 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
395 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
397 # Write entire cluster: sector-wise, the request is:
398 # backing: 128m... | 00 00
399 # active: 128m... | 00 00 00 00
400 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
401 $QEMU_IO -c "write -z $size 2048" "$TEST_IMG" | _filter_qemu_io
402 $QEMU_IO -c "alloc $size 2048" "$TEST_IMG" | _filter_qemu_io
403 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
405 # A preallocated cluster maintains its allocation, whether it stays as
406 # data due to a partial write:
407 # Convert 128m... | XX XX => ... | XX 00
408 _make_test_img $((size + 1024))
409 $QEMU_IO -c "write -P 1 $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
410 $QEMU_IO -c "write -z $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
411 $QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
412 $QEMU_IO -c "read -P 0 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
413 $QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
414 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
416 # or because it is the entire cluster and can use the zero flag:
417 # Convert 128m... | XX XX => ... | 00 00
418 $QEMU_IO -c "write -z $((size)) 1024" "$TEST_IMG" | _filter_qemu_io
419 $QEMU_IO -c "alloc $size 1024" "$TEST_IMG" | _filter_qemu_io
420 $QEMU_IO -c "read -P 0 $size 1024" "$TEST_IMG" | _filter_qemu_io
421 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
423 echo
424 echo == unaligned image tail cluster, allocation required ==
426 # Write beyond backing file must COW
427 # Backing file: 128m... | XX --
428 # Active layer: 128m... | -- -- 00 --
429 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
430 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
431 $QEMU_IO -c "write -P 1 $((size)) 512" "$TEST_IMG.base" | _filter_qemu_io
432 $QEMU_IO -c "write -z $((size + 1024)) 512" "$TEST_IMG" | _filter_qemu_io
433 $QEMU_IO -c "read -P 1 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
434 $QEMU_IO -c "read -P 0 $((size + 512)) 1536" "$TEST_IMG" | _filter_qemu_io
435 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
437 # Writes at boundaries of (partial) cluster must not lose mid-cluster data
438 # Backing file: 128m: ... | -- XX
439 # Active layer: 128m: ... | 00 -- -- 00
440 CLUSTER_SIZE=512 TEST_IMG="$TEST_IMG.base" _make_test_img $((size + 1024))
441 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $((size + 2048))
442 $QEMU_IO -c "write -P 1 $((size + 512)) 512" "$TEST_IMG.base" | _filter_qemu_io
443 $QEMU_IO -c "write -z $((size)) 512" "$TEST_IMG" | _filter_qemu_io
444 $QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
445 $QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
446 $QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
447 $QEMU_IO -c "write -z $((size + 1536)) 512" "$TEST_IMG" | _filter_qemu_io
448 $QEMU_IO -c "read -P 0 $((size)) 512" "$TEST_IMG" | _filter_qemu_io
449 $QEMU_IO -c "read -P 1 $((size + 512)) 512" "$TEST_IMG" | _filter_qemu_io
450 $QEMU_IO -c "read -P 0 $((size + 1024)) 1024" "$TEST_IMG" | _filter_qemu_io
451 $QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
453 # success, all done
454 echo "*** done"
455 rm -f $seq.full
456 status=0