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 55*b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base -F $IMGFMT 56e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 57*b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base \ 58*b66ff2c2SEric Blake -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig 59e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 60e4f58749SKevin Wolf 61e4f58749SKevin Wolf 62e4f58749SKevin Wolfecho 63e4f58749SKevin Wolfecho "=== Check that zero clusters are kept in overlay ===" 64e4f58749SKevin Wolfecho 65e4f58749SKevin Wolf 66*b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base -F $IMGFMT 67e4f58749SKevin Wolf 68e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 69*b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \ 70*b66ff2c2SEric Blake "$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 72*b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \ 73*b66ff2c2SEric Blake "$TEST_IMG" "$TEST_IMG".orig 74e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 75e4f58749SKevin Wolf 76e4f58749SKevin Wolf$QEMU_IO -c "write -z 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 77*b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \ 78*b66ff2c2SEric Blake "$TEST_IMG" "$TEST_IMG".orig 79e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 80*b66ff2c2SEric Blake$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base -o backing_fmt=$IMGFMT \ 81*b66ff2c2SEric Blake "$TEST_IMG" "$TEST_IMG".orig 82e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 83e4f58749SKevin Wolf 84e4f58749SKevin Wolf 85e4f58749SKevin Wolfecho 860682854fSMax Reitzecho "=== Converting to an overlay larger than its backing file ===" 870682854fSMax Reitzecho 880682854fSMax Reitz 890682854fSMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img 256M 900682854fSMax Reitz# Needs to be at least how much an L2 table covers 910682854fSMax Reitz# (64 kB/entry * 64 kB / 8 B/entry = 512 MB) 920682854fSMax Reitz# That way, qcow2 will yield at least two status request responses. 930682854fSMax Reitz# With just a single response, it would always say "Allocated in the 940682854fSMax Reitz# backing file", so the optimization qemu-img convert tries to do is 950682854fSMax Reitz# done automatically. Once it has to be queried twice, however (and 960682854fSMax Reitz# one of the queries is completely after the end of the backing file), 970682854fSMax Reitz# the block layer will automatically add a ZERO flag that qemu-img 980682854fSMax Reitz# convert used to follow up with a zero write to the target. 990682854fSMax Reitz# We do not want such a zero write, however, because we are past the 1000682854fSMax Reitz# end of the backing file on the target as well, so we do not need to 1010682854fSMax Reitz# write anything there. 102*b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base 768M -F $IMGFMT 1030682854fSMax Reitz 1040682854fSMax Reitz# Use compat=0.10 as the output so there is no zero cluster support 1050682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \ 106*b66ff2c2SEric Blake -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig 1070682854fSMax Reitz# See that nothing has been allocated past 64M 1080682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 1090682854fSMax Reitz 1100682854fSMax Reitzecho 1110682854fSMax Reitz 1120682854fSMax Reitz# Just before the end of the backing file 1130682854fSMax Reitz$QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io 1140682854fSMax Reitz# Somewhere in the second L2 table 1150682854fSMax Reitz$QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io 1160682854fSMax Reitz 1170682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \ 118*b66ff2c2SEric Blake -o backing_fmt=$IMGFMT "$TEST_IMG" "$TEST_IMG".orig 1190682854fSMax Reitz 1200682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 1210682854fSMax Reitz$QEMU_IO -c 'read -P 0x11 255M 1M' \ 1220682854fSMax Reitz -c 'read -P 0x22 600M 1M' \ 1230682854fSMax Reitz "$TEST_IMG".orig \ 1240682854fSMax Reitz | _filter_qemu_io 1250682854fSMax Reitz 1260682854fSMax Reitz 1270682854fSMax Reitzecho 128e4f58749SKevin Wolfecho "=== Concatenate multiple source images ===" 129e4f58749SKevin Wolfecho 130e4f58749SKevin Wolf 131e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 4M 132e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 4M 133e4f58749SKevin WolfTEST_IMG="$TEST_IMG".3 _make_test_img 4M 134e4f58749SKevin Wolf 135e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 136e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 64k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 137e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 0 64k" "$TEST_IMG".3 2>&1 | _filter_qemu_io | _filter_testdir 138e4f58749SKevin Wolf 139e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 140e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 141e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 142e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 143e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 144e4f58749SKevin Wolf 145e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 146e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 147e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 148e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 149e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 150e4f58749SKevin Wolf 151e4f58749SKevin Wolf# -B can't be combined with concatenation 152e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 153e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 154e4f58749SKevin Wolf 155e4f58749SKevin Wolf 156e4f58749SKevin Wolfecho 157e4f58749SKevin Wolfecho "=== Compression with misaligned allocations and image sizes ===" 158e4f58749SKevin Wolfecho 159e4f58749SKevin Wolf 160e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 1023k -o cluster_size=1024 161e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 1023k -o cluster_size=1024 162e4f58749SKevin Wolf 163e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 16k 16k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 164e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 130k 130k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 165e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 1022k 1k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 166e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x44 0k 1k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 167e4f58749SKevin Wolf 168e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[12] "$TEST_IMG" 169e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 170e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 171e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 16k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 172e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32k 98k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 173e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 130k 130k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 174e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 260k 762k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 175e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 1022k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 176e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x44 1023k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 177e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 1024k 1022k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 178e4f58749SKevin Wolf 179e4f58749SKevin Wolf 180e4f58749SKevin Wolfecho 181e4f58749SKevin Wolfecho "=== Full allocation with -S 0 ===" 182e4f58749SKevin Wolfecho 183e4f58749SKevin Wolf 184e4f58749SKevin Wolf# Standalone image 185e4f58749SKevin Wolf_make_test_img 64M 186e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 187e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 3M 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 188e4f58749SKevin Wolf 189e4f58749SKevin Wolfecho 190e4f58749SKevin Wolfecho convert -S 0: 191e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 192e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 193e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 194e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 195e4f58749SKevin Wolf 196e4f58749SKevin Wolfecho 197e4f58749SKevin Wolfecho convert -c -S 0: 198e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 199e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 200e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 201e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 202e4f58749SKevin Wolf 203e4f58749SKevin Wolf# With backing file 204e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M 205e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 32M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir 206e4f58749SKevin Wolf 207*b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG".base 64M -F $IMGFMT 208e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 209e4f58749SKevin Wolf 210e4f58749SKevin Wolfecho 211e4f58749SKevin Wolfecho convert -S 0 with source backing file: 212e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 213e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 214e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 215e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 216e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 217e4f58749SKevin Wolf 218e4f58749SKevin Wolfecho 219e4f58749SKevin Wolfecho convert -c -S 0 with source backing file: 220e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 221e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 222e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 223e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 224e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 225e4f58749SKevin Wolf 226e4f58749SKevin Wolf# With keeping the backing file 227e4f58749SKevin Wolfecho 228e4f58749SKevin Wolfecho convert -S 0 -B ... 229e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 230e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 231e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 232e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 233e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 234e4f58749SKevin Wolf 235e4f58749SKevin Wolfecho 236e4f58749SKevin Wolfecho convert -c -S 0 -B ... 237e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 238e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 239e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 240e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 241e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 242e4f58749SKevin Wolf 243e4f58749SKevin Wolf 244e4f58749SKevin Wolfecho 245e4f58749SKevin Wolfecho "=== Non-zero -S ===" 246e4f58749SKevin Wolfecho 247e4f58749SKevin Wolf 248e4f58749SKevin Wolf_make_test_img 64M -o cluster_size=1k 249e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 250e4f58749SKevin Wolf$QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 251e4f58749SKevin Wolf$QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 252e4f58749SKevin Wolf$QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 253e4f58749SKevin Wolf 254e4f58749SKevin Wolffor min_sparse in 4k 8k; do 255e4f58749SKevin Wolf echo 256e4f58749SKevin Wolf echo convert -S $min_sparse 257e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 258e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 259e4f58749SKevin Wolf 260e4f58749SKevin Wolf echo 261e4f58749SKevin Wolf echo convert -c -S $min_sparse 262e4f58749SKevin Wolf # For compressed images, -S values other than 0 are ignored 263e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -c -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 264e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 265e4f58749SKevin Wolfdone 266e4f58749SKevin Wolf 267c2acc95bSMax Reitz 268c2acc95bSMax Reitzecho 269c2acc95bSMax Reitzecho '=== -n to a non-zero image ===' 270c2acc95bSMax Reitzecho 271c2acc95bSMax Reitz 272c2acc95bSMax Reitz# Keep source zero 273c2acc95bSMax Reitz_make_test_img 64M 274c2acc95bSMax Reitz 275c2acc95bSMax Reitz# Output is not zero, but has bdrv_has_zero_init() == 1 276c2acc95bSMax ReitzTEST_IMG="$TEST_IMG".orig _make_test_img 64M 277c2acc95bSMax Reitz$QEMU_IO -c "write -P 42 0 64k" "$TEST_IMG".orig | _filter_qemu_io 278c2acc95bSMax Reitz 279c2acc95bSMax Reitz# Convert with -n, which should not assume that the target is zeroed 280c2acc95bSMax Reitz$QEMU_IMG convert -O $IMGFMT -n "$TEST_IMG" "$TEST_IMG".orig 281c2acc95bSMax Reitz 282c2acc95bSMax Reitz$QEMU_IMG compare "$TEST_IMG" "$TEST_IMG".orig 283c2acc95bSMax Reitz 284f535cc90SMax Reitzecho 285f535cc90SMax Reitzecho '=== -n -B to an image without a backing file ===' 286f535cc90SMax Reitzecho 287f535cc90SMax Reitz 288f535cc90SMax Reitz# Base for the output 289f535cc90SMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img 64M 290f535cc90SMax Reitz 291f535cc90SMax Reitz# Output that does have $TEST_IMG.base set as its (implicit) backing file 292f535cc90SMax ReitzTEST_IMG="$TEST_IMG".orig _make_test_img 64M 293f535cc90SMax Reitz 294f535cc90SMax Reitz# Convert with -n, which should not confuse -B with "target BDS has a 295f535cc90SMax Reitz# backing file" 296f535cc90SMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -n "$TEST_IMG" "$TEST_IMG".orig 297f535cc90SMax Reitz 29825956af3SEric Blakeecho 29925956af3SEric Blakeecho '=== -n incompatible with -o ===' 30025956af3SEric Blakeecho 30125956af3SEric Blake 30225956af3SEric Blake$QEMU_IMG convert -O $IMGFMT -o preallocation=metadata -n \ 30325956af3SEric Blake "$TEST_IMG" "$TEST_IMG".orig && echo "unexpected success" 30425956af3SEric Blake 305e4f58749SKevin Wolf# success, all done 306e4f58749SKevin Wolfecho '*** done' 307e4f58749SKevin Wolfrm -f $seq.full 308e4f58749SKevin Wolfstatus=0 309