1*e4f58749SKevin Wolf#!/bin/bash 2*e4f58749SKevin Wolf# 3*e4f58749SKevin Wolf# Test some qemu-img convert cases 4*e4f58749SKevin Wolf# 5*e4f58749SKevin Wolf# Copyright (C) 2015 Red Hat, Inc. 6*e4f58749SKevin Wolf# 7*e4f58749SKevin Wolf# This program is free software; you can redistribute it and/or modify 8*e4f58749SKevin Wolf# it under the terms of the GNU General Public License as published by 9*e4f58749SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 10*e4f58749SKevin Wolf# (at your option) any later version. 11*e4f58749SKevin Wolf# 12*e4f58749SKevin Wolf# This program is distributed in the hope that it will be useful, 13*e4f58749SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*e4f58749SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*e4f58749SKevin Wolf# GNU General Public License for more details. 16*e4f58749SKevin Wolf# 17*e4f58749SKevin Wolf# You should have received a copy of the GNU General Public License 18*e4f58749SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*e4f58749SKevin Wolf# 20*e4f58749SKevin Wolf 21*e4f58749SKevin Wolf# creator 22*e4f58749SKevin Wolfowner=kwolf@redhat.com 23*e4f58749SKevin Wolf 24*e4f58749SKevin Wolfseq="$(basename $0)" 25*e4f58749SKevin Wolfecho "QA output created by $seq" 26*e4f58749SKevin Wolf 27*e4f58749SKevin Wolfhere="$PWD" 28*e4f58749SKevin Wolftmp=/tmp/$$ 29*e4f58749SKevin Wolfstatus=1 # failure is the default! 30*e4f58749SKevin Wolf 31*e4f58749SKevin Wolf_cleanup() 32*e4f58749SKevin Wolf{ 33*e4f58749SKevin Wolf rm -f "$TEST_IMG".[123] 34*e4f58749SKevin Wolf _cleanup_test_img 35*e4f58749SKevin Wolf} 36*e4f58749SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 37*e4f58749SKevin Wolf 38*e4f58749SKevin Wolf# get standard environment, filters and checks 39*e4f58749SKevin Wolf. ./common.rc 40*e4f58749SKevin Wolf. ./common.filter 41*e4f58749SKevin Wolf 42*e4f58749SKevin Wolf_supported_fmt qcow2 43*e4f58749SKevin Wolf_supported_proto file 44*e4f58749SKevin Wolf_supported_os Linux 45*e4f58749SKevin Wolf 46*e4f58749SKevin Wolf 47*e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M 48*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir 49*e4f58749SKevin Wolf 50*e4f58749SKevin Wolf 51*e4f58749SKevin Wolfecho 52*e4f58749SKevin Wolfecho "=== Check allocation status regression with -B ===" 53*e4f58749SKevin Wolfecho 54*e4f58749SKevin Wolf 55*e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 56*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 57*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 58*e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map 59*e4f58749SKevin Wolf 60*e4f58749SKevin Wolf 61*e4f58749SKevin Wolfecho 62*e4f58749SKevin Wolfecho "=== Check that zero clusters are kept in overlay ===" 63*e4f58749SKevin Wolfecho 64*e4f58749SKevin Wolf 65*e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 66*e4f58749SKevin Wolf 67*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 68*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 69*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 70*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 71*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 72*e4f58749SKevin Wolf 73*e4f58749SKevin Wolf$QEMU_IO -c "write -z 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 74*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 75*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 76*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG" "$TEST_IMG".orig 77*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 78*e4f58749SKevin Wolf 79*e4f58749SKevin Wolf 80*e4f58749SKevin Wolfecho 81*e4f58749SKevin Wolfecho "=== Concatenate multiple source images ===" 82*e4f58749SKevin Wolfecho 83*e4f58749SKevin Wolf 84*e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 4M 85*e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 4M 86*e4f58749SKevin WolfTEST_IMG="$TEST_IMG".3 _make_test_img 4M 87*e4f58749SKevin Wolf 88*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 64k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 89*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 64k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 90*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 0 64k" "$TEST_IMG".3 2>&1 | _filter_qemu_io | _filter_testdir 91*e4f58749SKevin Wolf 92*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 93*e4f58749SKevin Wolf$QEMU_IMG map "$TEST_IMG" | _filter_qemu_img_map 94*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 95*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 96*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 97*e4f58749SKevin Wolf 98*e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[123] "$TEST_IMG" 99*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 100*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 101*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 4M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 102*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 8M 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 103*e4f58749SKevin Wolf 104*e4f58749SKevin Wolf# -B can't be combined with concatenation 105*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 106*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TEST_IMG".[123] "$TEST_IMG" 107*e4f58749SKevin Wolf 108*e4f58749SKevin Wolf 109*e4f58749SKevin Wolfecho 110*e4f58749SKevin Wolfecho "=== Compression with misaligned allocations and image sizes ===" 111*e4f58749SKevin Wolfecho 112*e4f58749SKevin Wolf 113*e4f58749SKevin WolfTEST_IMG="$TEST_IMG".1 _make_test_img 1023k -o cluster_size=1024 114*e4f58749SKevin WolfTEST_IMG="$TEST_IMG".2 _make_test_img 1023k -o cluster_size=1024 115*e4f58749SKevin Wolf 116*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 16k 16k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 117*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 130k 130k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 118*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x33 1022k 1k" "$TEST_IMG".1 2>&1 | _filter_qemu_io | _filter_testdir 119*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x44 0k 1k" "$TEST_IMG".2 2>&1 | _filter_qemu_io | _filter_testdir 120*e4f58749SKevin Wolf 121*e4f58749SKevin Wolf$QEMU_IMG convert -c -O $IMGFMT "$TEST_IMG".[12] "$TEST_IMG" 122*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG" | _filter_qemu_img_map 123*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 0k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 124*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 16k 16k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 125*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32k 98k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 126*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 130k 130k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 127*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 260k 762k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 128*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x33 1022k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 129*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x44 1023k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 130*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 1024k 1022k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 131*e4f58749SKevin Wolf 132*e4f58749SKevin Wolf 133*e4f58749SKevin Wolfecho 134*e4f58749SKevin Wolfecho "=== Full allocation with -S 0 ===" 135*e4f58749SKevin Wolfecho 136*e4f58749SKevin Wolf 137*e4f58749SKevin Wolf# Standalone image 138*e4f58749SKevin Wolf_make_test_img 64M 139*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 140*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 3M 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 141*e4f58749SKevin Wolf 142*e4f58749SKevin Wolfecho 143*e4f58749SKevin Wolfecho convert -S 0: 144*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 145*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 146*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 147*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 148*e4f58749SKevin Wolf 149*e4f58749SKevin Wolfecho 150*e4f58749SKevin Wolfecho convert -c -S 0: 151*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 152*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 153*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 3M 61M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 154*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 155*e4f58749SKevin Wolf 156*e4f58749SKevin Wolf# With backing file 157*e4f58749SKevin WolfTEST_IMG="$TEST_IMG".base _make_test_img 64M 158*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x11 0 32M" "$TEST_IMG".base 2>&1 | _filter_qemu_io | _filter_testdir 159*e4f58749SKevin Wolf 160*e4f58749SKevin Wolf_make_test_img -b "$TEST_IMG".base 64M 161*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0x22 0 3M" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 162*e4f58749SKevin Wolf 163*e4f58749SKevin Wolfecho 164*e4f58749SKevin Wolfecho convert -S 0 with source backing file: 165*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 166*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 167*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 168*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 169*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 170*e4f58749SKevin Wolf 171*e4f58749SKevin Wolfecho 172*e4f58749SKevin Wolfecho convert -c -S 0 with source backing file: 173*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 174*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 175*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 176*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 177*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 178*e4f58749SKevin Wolf 179*e4f58749SKevin Wolf# With keeping the backing file 180*e4f58749SKevin Wolfecho 181*e4f58749SKevin Wolfecho convert -S 0 -B ... 182*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -S 0 "$TEST_IMG" "$TEST_IMG".orig 183*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 184*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 185*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 186*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 187*e4f58749SKevin Wolf 188*e4f58749SKevin Wolfecho 189*e4f58749SKevin Wolfecho convert -c -S 0 -B ... 190*e4f58749SKevin Wolf$QEMU_IMG convert -O $IMGFMT -c -S 0 "$TEST_IMG" "$TEST_IMG".orig 191*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x22 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 192*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0x11 3M 29M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 193*e4f58749SKevin Wolf$QEMU_IO -c "read -P 0 32M 32M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _filter_testdir 194*e4f58749SKevin Wolf$QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 195*e4f58749SKevin Wolf 196*e4f58749SKevin Wolf 197*e4f58749SKevin Wolfecho 198*e4f58749SKevin Wolfecho "=== Non-zero -S ===" 199*e4f58749SKevin Wolfecho 200*e4f58749SKevin Wolf 201*e4f58749SKevin Wolf_make_test_img 64M -o cluster_size=1k 202*e4f58749SKevin Wolf$QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 203*e4f58749SKevin Wolf$QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 204*e4f58749SKevin Wolf$QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 205*e4f58749SKevin Wolf$QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir 206*e4f58749SKevin Wolf 207*e4f58749SKevin Wolffor min_sparse in 4k 8k; do 208*e4f58749SKevin Wolf echo 209*e4f58749SKevin Wolf echo convert -S $min_sparse 210*e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 211*e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 212*e4f58749SKevin Wolf 213*e4f58749SKevin Wolf echo 214*e4f58749SKevin Wolf echo convert -c -S $min_sparse 215*e4f58749SKevin Wolf # For compressed images, -S values other than 0 are ignored 216*e4f58749SKevin Wolf $QEMU_IMG convert -O $IMGFMT -o cluster_size=1k -c -S $min_sparse "$TEST_IMG" "$TEST_IMG".orig 217*e4f58749SKevin Wolf $QEMU_IMG map --output=json "$TEST_IMG".orig | _filter_qemu_img_map 218*e4f58749SKevin Wolfdone 219*e4f58749SKevin Wolf 220*e4f58749SKevin Wolf# success, all done 221*e4f58749SKevin Wolfecho '*** done' 222*e4f58749SKevin Wolfrm -f $seq.full 223*e4f58749SKevin Wolfstatus=0 224