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