xref: /qemu/tests/qemu-iotests/122 (revision 1cd2ad11d37c48f284f557954e1df675b126264c)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw
3e4f58749SKevin Wolf#
4e4f58749SKevin Wolf# Test some qemu-img convert cases
5e4f58749SKevin Wolf#
6e4f58749SKevin Wolf# Copyright (C) 2015 Red Hat, Inc.
7e4f58749SKevin Wolf#
8e4f58749SKevin Wolf# This program is free software; you can redistribute it and/or modify
9e4f58749SKevin Wolf# it under the terms of the GNU General Public License as published by
10e4f58749SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
11e4f58749SKevin Wolf# (at your option) any later version.
12e4f58749SKevin Wolf#
13e4f58749SKevin Wolf# This program is distributed in the hope that it will be useful,
14e4f58749SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
15e4f58749SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16e4f58749SKevin Wolf# GNU General Public License for more details.
17e4f58749SKevin Wolf#
18e4f58749SKevin Wolf# You should have received a copy of the GNU General Public License
19e4f58749SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20e4f58749SKevin Wolf#
21e4f58749SKevin Wolf
22e4f58749SKevin Wolf# creator
23e4f58749SKevin Wolfowner=kwolf@redhat.com
24e4f58749SKevin Wolf
25e4f58749SKevin Wolfseq="$(basename $0)"
26e4f58749SKevin Wolfecho "QA output created by $seq"
27e4f58749SKevin Wolf
28e4f58749SKevin Wolfstatus=1	# failure is the default!
29e4f58749SKevin Wolf
30e4f58749SKevin Wolf_cleanup()
31e4f58749SKevin Wolf{
32f91ecbd7SMax Reitz    for img in "$TEST_IMG".[123]; do
33f91ecbd7SMax Reitz        _rm_test_img "$img"
34f91ecbd7SMax Reitz    done
35e4f58749SKevin Wolf    _cleanup_test_img
36e4f58749SKevin Wolf}
37e4f58749SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
38e4f58749SKevin Wolf
39e4f58749SKevin Wolf# get standard environment, filters and checks
40e4f58749SKevin Wolf. ./common.rc
41e4f58749SKevin Wolf. ./common.filter
42e4f58749SKevin Wolf
43e4f58749SKevin Wolf_supported_fmt qcow2
44e4f58749SKevin Wolf_supported_proto file
45e4f58749SKevin Wolf_supported_os Linux
46e4f58749SKevin Wolf
47e4f58749SKevin Wolf
48e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M
49e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir
50e4f58749SKevin Wolf
51e4f58749SKevin Wolf
52e4f58749SKevin Wolfecho
53e4f58749SKevin Wolfecho "=== Check allocation status regression with -B ==="
54e4f58749SKevin Wolfecho
55e4f58749SKevin Wolf
56b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base -F $IMGFMT
57e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
58b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base \
59b66ff2c2SEric Blake    -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig
60e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
61e4f58749SKevin Wolf
62e4f58749SKevin Wolf
63e4f58749SKevin Wolfecho
64e4f58749SKevin Wolfecho "=== Check that zero clusters are kept in overlay ==="
65e4f58749SKevin Wolfecho
66e4f58749SKevin Wolf
67b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base -F $IMGFMT
68e4f58749SKevin Wolf
69e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
701899bf47SEric Blake$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -F $IMGFMT \
71b66ff2c2SEric Blake    "$TEST_IMG" "$TEST_IMG".orig
72e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
73b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
74b66ff2c2SEric Blake    "$TEST_IMG" "$TEST_IMG".orig
75e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
76e4f58749SKevin Wolf
77e4f58749SKevin Wolf$QEMU_IO -c "write -z 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
78b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
79b66ff2c2SEric Blake    "$TEST_IMG" "$TEST_IMG".orig
80e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
81b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \
82b66ff2c2SEric Blake    "$TEST_IMG" "$TEST_IMG".orig
83e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
84e4f58749SKevin Wolf
85e4f58749SKevin Wolf
86e4f58749SKevin Wolfecho
870682854fSMax Reitzecho "=== Converting to an overlay larger than its backing file ==="
880682854fSMax Reitzecho
890682854fSMax Reitz
900682854fSMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img 256M
910682854fSMax Reitz# Needs to be at least how much an L2 table covers
920682854fSMax Reitz# (64 kB/entry * 64 kB / 8 B/entry = 512 MB)
930682854fSMax Reitz# That way, qcow2 will yield at least two status request responses.
940682854fSMax Reitz# With just a single response, it would always say "Allocated in the
950682854fSMax Reitz# backing file", so the optimization qemu-img convert tries to do is
960682854fSMax Reitz# done automatically.  Once it has to be queried twice, however (and
970682854fSMax Reitz# one of the queries is completely after the end of the backing file),
980682854fSMax Reitz# the block layer will automatically add a ZERO flag that qemu-img
990682854fSMax Reitz# convert used to follow up with a zero write to the target.
1000682854fSMax Reitz# We do not want such a zero write, however, because we are past the
1010682854fSMax Reitz# end of the backing file on the target as well, so we do not need to
1020682854fSMax Reitz# write anything there.
103b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base 768M -F $IMGFMT
1040682854fSMax Reitz
1050682854fSMax Reitz# Use compat=0.10 as the output so there is no zero cluster support
1060682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
107b66ff2c2SEric Blake    -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig
1080682854fSMax Reitz# See that nothing has been allocated past 64M
1090682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
1100682854fSMax Reitz
1110682854fSMax Reitzecho
1120682854fSMax Reitz
1130682854fSMax Reitz# Just before the end of the backing file
1140682854fSMax Reitz$QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io
1150682854fSMax Reitz# Somewhere in the second L2 table
1160682854fSMax Reitz$QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io
1170682854fSMax Reitz
1180682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \
119b66ff2c2SEric Blake    -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig
1200682854fSMax Reitz
1210682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map
1220682854fSMax Reitz$QEMU_IO -c 'read -P 0x11 255M 1M' \
1230682854fSMax Reitz         -c 'read -P 0x22 600M 1M' \
1240682854fSMax Reitz         "$TEST_IMG".orig \
1250682854fSMax Reitz    | _filter_qemu_io
1260682854fSMax Reitz
1270682854fSMax Reitz
1280682854fSMax Reitzecho
129e4f58749SKevin Wolfecho "=== Concatenate multiple source images ==="
130e4f58749SKevin Wolfecho
131e4f58749SKevin Wolf
132e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 4M
133e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 4M
134e4f58749SKevin WolfTEST_IMG="$TEST_IMG".3 _make_test_img 4M
135e4f58749SKevin Wolf
136e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
137e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 64k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir
138e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 0 64k" "$TEST_IMG".3 2>&1 | _filter_qemu_io | _filter_testdir
139e4f58749SKevin Wolf
140e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG"
141e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map
142e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
143e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
144e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
145e4f58749SKevin Wolf
146e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG"
147e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
148e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
149e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
150e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
151e4f58749SKevin Wolf
152e4f58749SKevin Wolf# -B can't be combined with concatenation
153e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG"
154e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG"
155e4f58749SKevin Wolf
156e4f58749SKevin Wolf
157e4f58749SKevin Wolfecho
158e4f58749SKevin Wolfecho "=== Compression with misaligned allocations and image sizes ==="
159e4f58749SKevin Wolfecho
160e4f58749SKevin Wolf
161e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 1023k -o cluster_size=1024
162e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 1023k -o cluster_size=1024
163e4f58749SKevin Wolf
164e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11   16k  16k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
165e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22  130k 130k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
166e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 1022k   1k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir
167e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x44    0k   1k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir
168e4f58749SKevin Wolf
169e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[12] "$TEST_IMG"
170e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map
171e4f58749SKevin Wolf$QEMU_IO -c "read -P 0       0k   16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
172e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11   16k   16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
173e4f58749SKevin Wolf$QEMU_IO -c "read -P 0      32k   98k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
174e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22  130k  130k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
175e4f58749SKevin Wolf$QEMU_IO -c "read -P 0     260k  762k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
176e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 1022k    1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
177e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x44 1023k    1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
178e4f58749SKevin Wolf$QEMU_IO -c "read -P 0    1024k 1022k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
179e4f58749SKevin Wolf
180e4f58749SKevin Wolf
181e4f58749SKevin Wolfecho
182e4f58749SKevin Wolfecho "=== Full allocation with -S 0 ==="
183e4f58749SKevin Wolfecho
184e4f58749SKevin Wolf
185e4f58749SKevin Wolf# Standalone image
186e4f58749SKevin Wolf_make_test_img 64M
187e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
188e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 3M 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
189e4f58749SKevin Wolf
190e4f58749SKevin Wolfecho
191e4f58749SKevin Wolfecho convert -S 0:
192e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
193e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
194e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
195e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
196e4f58749SKevin Wolf
197e4f58749SKevin Wolfecho
198e4f58749SKevin Wolfecho convert -c -S 0:
199e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
200e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
201e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
202e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
203e4f58749SKevin Wolf
204e4f58749SKevin Wolf# With backing file
205e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M
206e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 32M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir
207e4f58749SKevin Wolf
208b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base 64M -F $IMGFMT
209e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
210e4f58749SKevin Wolf
211e4f58749SKevin Wolfecho
212e4f58749SKevin Wolfecho convert -S 0 with source backing file:
213e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
214e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
215e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
216e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
217e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
218e4f58749SKevin Wolf
219e4f58749SKevin Wolfecho
220e4f58749SKevin Wolfecho convert -c -S 0 with source backing file:
221e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
222e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
223e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
224e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
225e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
226e4f58749SKevin Wolf
227e4f58749SKevin Wolf# With keeping the backing file
228e4f58749SKevin Wolfecho
229e4f58749SKevin Wolfecho convert -S 0 -B ...
230e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig
231e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
232e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
233e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
234e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
235e4f58749SKevin Wolf
236e4f58749SKevin Wolfecho
237e4f58749SKevin Wolfecho convert -c -S 0 -B ...
238e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig
239e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
240e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
241e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir
242e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
243e4f58749SKevin Wolf
244e4f58749SKevin Wolf
245e4f58749SKevin Wolfecho
246e4f58749SKevin Wolfecho "=== Non-zero -S ==="
247e4f58749SKevin Wolfecho
248e4f58749SKevin Wolf
249e4f58749SKevin Wolf_make_test_img 64M -o cluster_size=1k
250e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
251e4f58749SKevin Wolf$QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
252e4f58749SKevin Wolf$QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
253e4f58749SKevin Wolf$QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
254*51cd8bddSKevin Wolf$QEMU_IO -c "write -P 0 65k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir
255e4f58749SKevin Wolf
256e4f58749SKevin Wolffor min_sparse in 4k 8k; do
257e4f58749SKevin Wolf    echo
258e4f58749SKevin Wolf    echo convert -S $min_sparse
259e4f58749SKevin Wolf    $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig
260e4f58749SKevin Wolf    $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
261e4f58749SKevin Wolf
262e4f58749SKevin Wolf    echo
263e4f58749SKevin Wolf    echo convert -c -S $min_sparse
264e4f58749SKevin Wolf    # For compressed images, -S values other than 0 are ignored
265e4f58749SKevin Wolf    $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -c -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig
266e4f58749SKevin Wolf    $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map
267e4f58749SKevin Wolfdone
268e4f58749SKevin Wolf
269c2acc95bSMax Reitz
270c2acc95bSMax Reitzecho
271c2acc95bSMax Reitzecho '=== -n to a non-zero image ==='
272c2acc95bSMax Reitzecho
273c2acc95bSMax Reitz
274c2acc95bSMax Reitz# Keep source zero
275c2acc95bSMax Reitz_make_test_img 64M
276c2acc95bSMax Reitz
277c2acc95bSMax Reitz# Output is not zero, but has bdrv_has_zero_init() == 1
278c2acc95bSMax ReitzTEST_IMG="$TEST_IMG".orig _make_test_img 64M
279c2acc95bSMax Reitz$QEMU_IO -c "write -P 42 0 64k" "$TEST_IMG".orig | _filter_qemu_io
280c2acc95bSMax Reitz
281c2acc95bSMax Reitz# Convert with -n, which should not assume that the target is zeroed
282c2acc95bSMax Reitz$QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG".orig
283c2acc95bSMax Reitz
284c2acc95bSMax Reitz$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG".orig
285c2acc95bSMax Reitz
286f535cc90SMax Reitzecho
2874a01e27dSKevin Wolfecho '=== -n to an empty image ==='
2884a01e27dSKevin Wolfecho
2894a01e27dSKevin Wolf
2904a01e27dSKevin WolfTEST_IMG="$TEST_IMG".orig _make_test_img 64M
2914a01e27dSKevin Wolf
2924a01e27dSKevin Wolf# Convert with -n, which should not result in a fully allocated image, not even
2934a01e27dSKevin Wolf# with compat=0.10 (because the target doesn't have a backing file)
2944a01e27dSKevin Wolffor compat in "1.1" "0.10"; do
2954a01e27dSKevin Wolf    IMGOPTS="compat=$compat" _make_test_img 64M
2964a01e27dSKevin Wolf    $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG".orig "$TEST_IMG"
2974a01e27dSKevin Wolf    $QEMU_IMG map --output=json "$TEST_IMG"
2984a01e27dSKevin Wolfdone
2994a01e27dSKevin Wolf
3004a01e27dSKevin Wolfecho
3014a01e27dSKevin Wolfecho '=== -n to an empty image with a backing file ==='
3024a01e27dSKevin Wolfecho
3034a01e27dSKevin Wolf
3044a01e27dSKevin WolfTEST_IMG="$TEST_IMG".orig _make_test_img 64M
3054a01e27dSKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M
3064a01e27dSKevin Wolf
3074a01e27dSKevin Wolf# Convert with -n, which should still not result in a fully allocated image for
3084a01e27dSKevin Wolf# compat=1.1 (because it can use zero clusters), but it should be fully
3094a01e27dSKevin Wolf# allocated with compat=0.10
3104a01e27dSKevin Wolffor compat in "1.1" "0.10"; do
3114a01e27dSKevin Wolf    IMGOPTS="compat=$compat" _make_test_img -b "$TEST_IMG".base -F $IMGFMT 64M
3124a01e27dSKevin Wolf    $QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG".orig "$TEST_IMG"
3134a01e27dSKevin Wolf    $QEMU_IMG map --output=json "$TEST_IMG"
3144a01e27dSKevin Wolfdone
3154a01e27dSKevin Wolf
3164a01e27dSKevin Wolfecho
317f535cc90SMax Reitzecho '=== -n -B to an image without a backing file ==='
318f535cc90SMax Reitzecho
319f535cc90SMax Reitz
320f535cc90SMax Reitz# Base for the output
321f535cc90SMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img 64M
322f535cc90SMax Reitz
323f535cc90SMax Reitz# Output that does have $TEST_IMG.base set as its (implicit) backing file
324f535cc90SMax ReitzTEST_IMG="$TEST_IMG".orig _make_test_img 64M
325f535cc90SMax Reitz
326f535cc90SMax Reitz# Convert with -n, which should not confuse -B with "target BDS has a
327f535cc90SMax Reitz# backing file"
328f535cc90SMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -n "$TEST_IMG" "$TEST_IMG".orig
329f535cc90SMax Reitz
33025956af3SEric Blakeecho
33125956af3SEric Blakeecho '=== -n incompatible with -o ==='
33225956af3SEric Blakeecho
33325956af3SEric Blake
33425956af3SEric Blake$QEMU_IMG convert -O $IMGFMT -o preallocation=metadata -n \
33525956af3SEric Blake	  "$TEST_IMG" "$TEST_IMG".orig && echo "unexpected success"
33625956af3SEric Blake
337e4f58749SKevin Wolf# success, all done
338e4f58749SKevin Wolfecho '*** done'
339e4f58749SKevin Wolfrm -f $seq.full
340e4f58749SKevin Wolfstatus=0
341