1*f4e732a0SMax Reitz#!/bin/bash 2*f4e732a0SMax Reitz# 3*f4e732a0SMax Reitz# Test that qemu-img convert -S 0 fully allocates the target image 4*f4e732a0SMax Reitz# 5*f4e732a0SMax Reitz# Copyright (C) 2016 Red Hat, Inc. 6*f4e732a0SMax Reitz# 7*f4e732a0SMax Reitz# This program is free software; you can redistribute it and/or modify 8*f4e732a0SMax Reitz# it under the terms of the GNU General Public License as published by 9*f4e732a0SMax Reitz# the Free Software Foundation; either version 2 of the License, or 10*f4e732a0SMax Reitz# (at your option) any later version. 11*f4e732a0SMax Reitz# 12*f4e732a0SMax Reitz# This program is distributed in the hope that it will be useful, 13*f4e732a0SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*f4e732a0SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*f4e732a0SMax Reitz# GNU General Public License for more details. 16*f4e732a0SMax Reitz# 17*f4e732a0SMax Reitz# You should have received a copy of the GNU General Public License 18*f4e732a0SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*f4e732a0SMax Reitz# 20*f4e732a0SMax Reitz 21*f4e732a0SMax Reitz# creator 22*f4e732a0SMax Reitzowner=mreitz@redhat.com 23*f4e732a0SMax Reitz 24*f4e732a0SMax Reitzseq="$(basename $0)" 25*f4e732a0SMax Reitzecho "QA output created by $seq" 26*f4e732a0SMax Reitz 27*f4e732a0SMax Reitzhere="$PWD" 28*f4e732a0SMax Reitztmp=/tmp/$$ 29*f4e732a0SMax Reitzstatus=1 # failure is the default! 30*f4e732a0SMax Reitz 31*f4e732a0SMax Reitz_cleanup() 32*f4e732a0SMax Reitz{ 33*f4e732a0SMax Reitz _cleanup_test_img 34*f4e732a0SMax Reitz} 35*f4e732a0SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 36*f4e732a0SMax Reitz 37*f4e732a0SMax Reitz# get standard environment, filters and checks 38*f4e732a0SMax Reitz. ./common.rc 39*f4e732a0SMax Reitz. ./common.filter 40*f4e732a0SMax Reitz 41*f4e732a0SMax Reitz_supported_fmt generic 42*f4e732a0SMax Reitz_supported_proto file 43*f4e732a0SMax Reitz_supported_os Linux 44*f4e732a0SMax Reitz 45*f4e732a0SMax Reitz 46*f4e732a0SMax Reitzon_disk_size() 47*f4e732a0SMax Reitz{ 48*f4e732a0SMax Reitz du "$@" | sed -e 's/\t\+.*//' 49*f4e732a0SMax Reitz} 50*f4e732a0SMax Reitz 51*f4e732a0SMax Reitz 52*f4e732a0SMax Reitzimg_size=1048576 53*f4e732a0SMax Reitz 54*f4e732a0SMax Reitz 55*f4e732a0SMax Reitzecho 56*f4e732a0SMax Reitzecho '=== Comparing empty image against sparse conversion ===' 57*f4e732a0SMax Reitzecho 58*f4e732a0SMax Reitz 59*f4e732a0SMax Reitz_make_test_img $img_size 60*f4e732a0SMax Reitz 61*f4e732a0SMax Reitzempty_size=$(on_disk_size "$TEST_IMG") 62*f4e732a0SMax Reitz 63*f4e732a0SMax Reitz 64*f4e732a0SMax Reitz$QEMU_IMG_PROG convert -O "$IMGFMT" -S 512 \ 65*f4e732a0SMax Reitz "json:{ 'driver': 'null-co', 'size': $img_size, 'read-zeroes': true }" \ 66*f4e732a0SMax Reitz "$TEST_IMG" 67*f4e732a0SMax Reitz 68*f4e732a0SMax Reitzsparse_convert_size=$(on_disk_size "$TEST_IMG") 69*f4e732a0SMax Reitz 70*f4e732a0SMax Reitz 71*f4e732a0SMax Reitzif [ "$empty_size" -eq "$sparse_convert_size" ]; then 72*f4e732a0SMax Reitz echo 'Equal image size' 73*f4e732a0SMax Reitzelse 74*f4e732a0SMax Reitz echo 'Different image size' 75*f4e732a0SMax Reitzfi 76*f4e732a0SMax Reitz 77*f4e732a0SMax Reitz 78*f4e732a0SMax Reitzecho 79*f4e732a0SMax Reitzecho '=== Comparing full image against non-sparse conversion ===' 80*f4e732a0SMax Reitzecho 81*f4e732a0SMax Reitz 82*f4e732a0SMax Reitz_make_test_img $img_size 83*f4e732a0SMax Reitz$QEMU_IO -c "write 0 $img_size" "$TEST_IMG" | _filter_qemu_io 84*f4e732a0SMax Reitz 85*f4e732a0SMax Reitzfull_size=$(on_disk_size "$TEST_IMG") 86*f4e732a0SMax Reitz 87*f4e732a0SMax Reitz 88*f4e732a0SMax Reitz$QEMU_IMG convert -O "$IMGFMT" -S 0 \ 89*f4e732a0SMax Reitz "json:{ 'driver': 'null-co', 'size': $img_size, 'read-zeroes': true }" \ 90*f4e732a0SMax Reitz "$TEST_IMG" 91*f4e732a0SMax Reitz 92*f4e732a0SMax Reitznon_sparse_convert_size=$(on_disk_size "$TEST_IMG") 93*f4e732a0SMax Reitz 94*f4e732a0SMax Reitz 95*f4e732a0SMax Reitzif [ "$full_size" -eq "$non_sparse_convert_size" ]; then 96*f4e732a0SMax Reitz echo 'Equal image size' 97*f4e732a0SMax Reitzelse 98*f4e732a0SMax Reitz echo 'Different image size' 99*f4e732a0SMax Reitzfi 100*f4e732a0SMax Reitz 101*f4e732a0SMax Reitz 102*f4e732a0SMax Reitz# success, all done 103*f4e732a0SMax Reitzecho "*** done" 104*f4e732a0SMax Reitzrm -f $seq.full 105*f4e732a0SMax Reitzstatus=0 106