1e4f58749SKevin Wolf#!/bin/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 Wolfhere="$PWD" 28e4f58749SKevin Wolfstatus=1 # failure is the default! 29e4f58749SKevin Wolf 30e4f58749SKevin Wolf_cleanup() 31e4f58749SKevin Wolf{ 32e4f58749SKevin Wolf rm -f "$TEST_IMG".[123] 33e4f58749SKevin Wolf _cleanup_test_img 34e4f58749SKevin Wolf} 35e4f58749SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 36e4f58749SKevin Wolf 37e4f58749SKevin Wolf# get standard environment, filters and checks 38e4f58749SKevin Wolf. ./common.rc 39e4f58749SKevin Wolf. ./common.filter 40e4f58749SKevin Wolf 41e4f58749SKevin Wolf_supported_fmt qcow2 42e4f58749SKevin Wolf_supported_proto file 43e4f58749SKevin Wolf_supported_os Linux 44e4f58749SKevin Wolf 45e4f58749SKevin Wolf 46e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M 47e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir 48e4f58749SKevin Wolf 49e4f58749SKevin Wolf 50e4f58749SKevin Wolfecho 51e4f58749SKevin Wolfecho "=== Check allocation status regression with -B ===" 52e4f58749SKevin Wolfecho 53e4f58749SKevin Wolf 54e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 55e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 56e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 57e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 58e4f58749SKevin Wolf 59e4f58749SKevin Wolf 60e4f58749SKevin Wolfecho 61e4f58749SKevin Wolfecho "=== Check that zero clusters are kept in overlay ===" 62e4f58749SKevin Wolfecho 63e4f58749SKevin Wolf 64e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 65e4f58749SKevin Wolf 66e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 67e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 68e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 69e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 70e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 71e4f58749SKevin Wolf 72e4f58749SKevin Wolf$QEMU_IO -c "write -z 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 73e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$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$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 76e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 77e4f58749SKevin Wolf 78e4f58749SKevin Wolf 79e4f58749SKevin Wolfecho 80*0682854fSMax Reitzecho "=== Converting to an overlay larger than its backing file ===" 81*0682854fSMax Reitzecho 82*0682854fSMax Reitz 83*0682854fSMax ReitzTEST_IMG="$TEST_IMG".base _make_test_img 256M 84*0682854fSMax Reitz# Needs to be at least how much an L2 table covers 85*0682854fSMax Reitz# (64 kB/entry * 64 kB / 8 B/entry = 512 MB) 86*0682854fSMax Reitz# That way, qcow2 will yield at least two status request responses. 87*0682854fSMax Reitz# With just a single response, it would always say "Allocated in the 88*0682854fSMax Reitz# backing file", so the optimization qemu-img convert tries to do is 89*0682854fSMax Reitz# done automatically. Once it has to be queried twice, however (and 90*0682854fSMax Reitz# one of the queries is completely after the end of the backing file), 91*0682854fSMax Reitz# the block layer will automatically add a ZERO flag that qemu-img 92*0682854fSMax Reitz# convert used to follow up with a zero write to the target. 93*0682854fSMax Reitz# We do not want such a zero write, however, because we are past the 94*0682854fSMax Reitz# end of the backing file on the target as well, so we do not need to 95*0682854fSMax Reitz# write anything there. 96*0682854fSMax Reitz_make_test_img -b "$TEST_IMG".base 768M 97*0682854fSMax Reitz 98*0682854fSMax Reitz# Use compat=0.10 as the output so there is no zero cluster support 99*0682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \ 100*0682854fSMax Reitz "$TEST_IMG" "$TEST_IMG".orig 101*0682854fSMax Reitz# See that nothing has been allocated past 64M 102*0682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 103*0682854fSMax Reitz 104*0682854fSMax Reitzecho 105*0682854fSMax Reitz 106*0682854fSMax Reitz# Just before the end of the backing file 107*0682854fSMax Reitz$QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io 108*0682854fSMax Reitz# Somewhere in the second L2 table 109*0682854fSMax Reitz$QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io 110*0682854fSMax Reitz 111*0682854fSMax Reitz$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=0.10 \ 112*0682854fSMax Reitz "$TEST_IMG" "$TEST_IMG".orig 113*0682854fSMax Reitz 114*0682854fSMax Reitz$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 115*0682854fSMax Reitz$QEMU_IO -c 'read -P 0x11 255M 1M' \ 116*0682854fSMax Reitz -c 'read -P 0x22 600M 1M' \ 117*0682854fSMax Reitz "$TEST_IMG".orig \ 118*0682854fSMax Reitz | _filter_qemu_io 119*0682854fSMax Reitz 120*0682854fSMax Reitz 121*0682854fSMax Reitzecho 122e4f58749SKevin Wolfecho "=== Concatenate multiple source images ===" 123e4f58749SKevin Wolfecho 124e4f58749SKevin Wolf 125e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 4M 126e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 4M 127e4f58749SKevin WolfTEST_IMG="$TEST_IMG".3 _make_test_img 4M 128e4f58749SKevin Wolf 129e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 130e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 64k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 131e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 0 64k" "$TEST_IMG".3 2>&1 | _filter_qemu_io | _filter_testdir 132e4f58749SKevin Wolf 133e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 134e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 135e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 136e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 137e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 138e4f58749SKevin Wolf 139e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 140e4f58749SKevin Wolf$QEMU_IMG map --output=json "$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# -B can't be combined with concatenation 146e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 147e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 148e4f58749SKevin Wolf 149e4f58749SKevin Wolf 150e4f58749SKevin Wolfecho 151e4f58749SKevin Wolfecho "=== Compression with misaligned allocations and image sizes ===" 152e4f58749SKevin Wolfecho 153e4f58749SKevin Wolf 154e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 1023k -o cluster_size=1024 155e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 1023k -o cluster_size=1024 156e4f58749SKevin Wolf 157e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 16k 16k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 158e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 130k 130k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 159e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 1022k 1k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 160e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x44 0k 1k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 161e4f58749SKevin Wolf 162e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[12] "$TEST_IMG" 163e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 164e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 165e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 16k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 166e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32k 98k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 167e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 130k 130k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 168e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 260k 762k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 169e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 1022k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 170e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x44 1023k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 171e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 1024k 1022k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 172e4f58749SKevin Wolf 173e4f58749SKevin Wolf 174e4f58749SKevin Wolfecho 175e4f58749SKevin Wolfecho "=== Full allocation with -S 0 ===" 176e4f58749SKevin Wolfecho 177e4f58749SKevin Wolf 178e4f58749SKevin Wolf# Standalone image 179e4f58749SKevin Wolf_make_test_img 64M 180e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 181e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 3M 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 182e4f58749SKevin Wolf 183e4f58749SKevin Wolfecho 184e4f58749SKevin Wolfecho convert -S 0: 185e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 186e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 187e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 188e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 189e4f58749SKevin Wolf 190e4f58749SKevin Wolfecho 191e4f58749SKevin Wolfecho convert -c -S 0: 192e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -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 Wolf# With backing file 198e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M 199e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 32M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir 200e4f58749SKevin Wolf 201e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 64M 202e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 203e4f58749SKevin Wolf 204e4f58749SKevin Wolfecho 205e4f58749SKevin Wolfecho convert -S 0 with source backing file: 206e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 207e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 208e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 209e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 210e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 211e4f58749SKevin Wolf 212e4f58749SKevin Wolfecho 213e4f58749SKevin Wolfecho convert -c -S 0 with source backing file: 214e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 215e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 216e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 217e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 218e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 219e4f58749SKevin Wolf 220e4f58749SKevin Wolf# With keeping the backing file 221e4f58749SKevin Wolfecho 222e4f58749SKevin Wolfecho convert -S 0 -B ... 223e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 224e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 225e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 226e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 227e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 228e4f58749SKevin Wolf 229e4f58749SKevin Wolfecho 230e4f58749SKevin Wolfecho convert -c -S 0 -B ... 231e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 232e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 233e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 234e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 235e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 236e4f58749SKevin Wolf 237e4f58749SKevin Wolf 238e4f58749SKevin Wolfecho 239e4f58749SKevin Wolfecho "=== Non-zero -S ===" 240e4f58749SKevin Wolfecho 241e4f58749SKevin Wolf 242e4f58749SKevin Wolf_make_test_img 64M -o cluster_size=1k 243e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 244e4f58749SKevin Wolf$QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 245e4f58749SKevin Wolf$QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 246e4f58749SKevin Wolf$QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 247e4f58749SKevin Wolf 248e4f58749SKevin Wolffor min_sparse in 4k 8k; do 249e4f58749SKevin Wolf echo 250e4f58749SKevin Wolf echo convert -S $min_sparse 251e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 252e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 253e4f58749SKevin Wolf 254e4f58749SKevin Wolf echo 255e4f58749SKevin Wolf echo convert -c -S $min_sparse 256e4f58749SKevin Wolf # For compressed images, -S values other than 0 are ignored 257e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -c -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 258e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 259e4f58749SKevin Wolfdone 260e4f58749SKevin Wolf 261e4f58749SKevin Wolf# success, all done 262e4f58749SKevin Wolfecho '*** done' 263e4f58749SKevin Wolfrm -f $seq.full 264e4f58749SKevin Wolfstatus=0 265