1*11a82d14SPhilippe 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{ 31e4f58749SKevin Wolf rm -f "$TEST_IMG".[123] 32e4f58749SKevin Wolf _cleanup_test_img 33e4f58749SKevin Wolf} 34e4f58749SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 35e4f58749SKevin Wolf 36e4f58749SKevin Wolf# get standard environment, filters and checks 37e4f58749SKevin Wolf. ./common.rc 38e4f58749SKevin Wolf. ./common.filter 39e4f58749SKevin Wolf 40e4f58749SKevin Wolf_supported_fmt qcow2 41e4f58749SKevin Wolf_supported_proto file 42e4f58749SKevin Wolf_supported_os Linux 43e4f58749SKevin Wolf 44e4f58749SKevin Wolf 45e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M 46e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir 47e4f58749SKevin Wolf 48e4f58749SKevin Wolf 49e4f58749SKevin Wolfecho 50e4f58749SKevin Wolfecho "=== Check allocation status regression with -B ===" 51e4f58749SKevin Wolfecho 52e4f58749SKevin Wolf 53e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 54e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 55e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 56e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 57e4f58749SKevin Wolf 58e4f58749SKevin Wolf 59e4f58749SKevin Wolfecho 60e4f58749SKevin Wolfecho "=== Check that zero clusters are kept in overlay ===" 61e4f58749SKevin Wolfecho 62e4f58749SKevin Wolf 63e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 64e4f58749SKevin Wolf 65e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 66e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 67e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 68e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -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 71e4f58749SKevin Wolf$QEMU_IO -c "write -z 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 72e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 73e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 74e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -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 77e4f58749SKevin Wolf 78e4f58749SKevin Wolfecho 790682854fSMax Reitzecho "=== Converting to an overlay larger than its backing file ===" 800682854fSMax Reitzecho 810682854fSMax Reitz 820682854fSMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img 256M 830682854fSMax Reitz# Needs to be at least how much an L2 table covers 840682854fSMax Reitz# (64 kB/entry * 64 kB / 8 B/entry = 512 MB) 850682854fSMax Reitz# That way, qcow2 will yield at least two status request responses. 860682854fSMax Reitz# With just a single response, it would always say "Allocated in the 870682854fSMax Reitz# backing file", so the optimization qemu-img convert tries to do is 880682854fSMax Reitz# done automatically. Once it has to be queried twice, however (and 890682854fSMax Reitz# one of the queries is completely after the end of the backing file), 900682854fSMax Reitz# the block layer will automatically add a ZERO flag that qemu-img 910682854fSMax Reitz# convert used to follow up with a zero write to the target. 920682854fSMax Reitz# We do not want such a zero write, however, because we are past the 930682854fSMax Reitz# end of the backing file on the target as well, so we do not need to 940682854fSMax Reitz# write anything there. 950682854fSMax Reitz_make_test_img -b "$TEST_IMG".base 768M 960682854fSMax Reitz 970682854fSMax Reitz# Use compat=0.10 as the output so there is no zero cluster support 980682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \ 990682854fSMax Reitz "$TEST_IMG" "$TEST_IMG".orig 1000682854fSMax Reitz# See that nothing has been allocated past 64M 1010682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 1020682854fSMax Reitz 1030682854fSMax Reitzecho 1040682854fSMax Reitz 1050682854fSMax Reitz# Just before the end of the backing file 1060682854fSMax Reitz$QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io 1070682854fSMax Reitz# Somewhere in the second L2 table 1080682854fSMax Reitz$QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io 1090682854fSMax Reitz 1100682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \ 1110682854fSMax Reitz "$TEST_IMG" "$TEST_IMG".orig 1120682854fSMax Reitz 1130682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 1140682854fSMax Reitz$QEMU_IO -c 'read -P 0x11 255M 1M' \ 1150682854fSMax Reitz -c 'read -P 0x22 600M 1M' \ 1160682854fSMax Reitz "$TEST_IMG".orig \ 1170682854fSMax Reitz | _filter_qemu_io 1180682854fSMax Reitz 1190682854fSMax Reitz 1200682854fSMax Reitzecho 121e4f58749SKevin Wolfecho "=== Concatenate multiple source images ===" 122e4f58749SKevin Wolfecho 123e4f58749SKevin Wolf 124e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 4M 125e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 4M 126e4f58749SKevin WolfTEST_IMG="$TEST_IMG".3 _make_test_img 4M 127e4f58749SKevin Wolf 128e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 129e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 64k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 130e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 0 64k" "$TEST_IMG".3 2>&1 | _filter_qemu_io | _filter_testdir 131e4f58749SKevin Wolf 132e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 133e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 134e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 135e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 136e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 137e4f58749SKevin Wolf 138e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 139e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 140e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 141e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 142e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 143e4f58749SKevin Wolf 144e4f58749SKevin Wolf# -B can't be combined with concatenation 145e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 146e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 147e4f58749SKevin Wolf 148e4f58749SKevin Wolf 149e4f58749SKevin Wolfecho 150e4f58749SKevin Wolfecho "=== Compression with misaligned allocations and image sizes ===" 151e4f58749SKevin Wolfecho 152e4f58749SKevin Wolf 153e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 1023k -o cluster_size=1024 154e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 1023k -o cluster_size=1024 155e4f58749SKevin Wolf 156e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 16k 16k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 157e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 130k 130k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 158e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 1022k 1k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 159e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x44 0k 1k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 160e4f58749SKevin Wolf 161e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[12] "$TEST_IMG" 162e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 163e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 164e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 16k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 165e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32k 98k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 166e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 130k 130k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 167e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 260k 762k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 168e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 1022k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 169e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x44 1023k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 170e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 1024k 1022k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 171e4f58749SKevin Wolf 172e4f58749SKevin Wolf 173e4f58749SKevin Wolfecho 174e4f58749SKevin Wolfecho "=== Full allocation with -S 0 ===" 175e4f58749SKevin Wolfecho 176e4f58749SKevin Wolf 177e4f58749SKevin Wolf# Standalone image 178e4f58749SKevin Wolf_make_test_img 64M 179e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 180e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 3M 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 181e4f58749SKevin Wolf 182e4f58749SKevin Wolfecho 183e4f58749SKevin Wolfecho convert -S 0: 184e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 185e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 186e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 187e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 188e4f58749SKevin Wolf 189e4f58749SKevin Wolfecho 190e4f58749SKevin Wolfecho convert -c -S 0: 191e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -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 Wolf# With backing file 197e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M 198e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 32M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir 199e4f58749SKevin Wolf 200e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 64M 201e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 202e4f58749SKevin Wolf 203e4f58749SKevin Wolfecho 204e4f58749SKevin Wolfecho convert -S 0 with source backing file: 205e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 206e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 207e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 208e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 209e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 210e4f58749SKevin Wolf 211e4f58749SKevin Wolfecho 212e4f58749SKevin Wolfecho convert -c -S 0 with source backing file: 213e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -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 Wolf# With keeping the backing file 220e4f58749SKevin Wolfecho 221e4f58749SKevin Wolfecho convert -S 0 -B ... 222e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 223e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 224e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 225e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 226e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 227e4f58749SKevin Wolf 228e4f58749SKevin Wolfecho 229e4f58749SKevin Wolfecho convert -c -S 0 -B ... 230e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -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 Wolf 237e4f58749SKevin Wolfecho 238e4f58749SKevin Wolfecho "=== Non-zero -S ===" 239e4f58749SKevin Wolfecho 240e4f58749SKevin Wolf 241e4f58749SKevin Wolf_make_test_img 64M -o cluster_size=1k 242e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 243e4f58749SKevin Wolf$QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 244e4f58749SKevin Wolf$QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 245e4f58749SKevin Wolf$QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 246e4f58749SKevin Wolf 247e4f58749SKevin Wolffor min_sparse in 4k 8k; do 248e4f58749SKevin Wolf echo 249e4f58749SKevin Wolf echo convert -S $min_sparse 250e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 251e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 252e4f58749SKevin Wolf 253e4f58749SKevin Wolf echo 254e4f58749SKevin Wolf echo convert -c -S $min_sparse 255e4f58749SKevin Wolf # For compressed images, -S values other than 0 are ignored 256e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -c -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 257e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 258e4f58749SKevin Wolfdone 259e4f58749SKevin Wolf 260e4f58749SKevin Wolf# success, all done 261e4f58749SKevin Wolfecho '*** done' 262e4f58749SKevin Wolfrm -f $seq.full 263e4f58749SKevin Wolfstatus=0 264