xref: /qemu/tests/qemu-iotests/106 (revision a2c7e082123a17dc1e31262ad136a3b45b3b0cb6)
1*a2c7e082SMax Reitz#!/bin/bash
2*a2c7e082SMax Reitz#
3*a2c7e082SMax Reitz# Test preallocated resize of raw images
4*a2c7e082SMax Reitz#
5*a2c7e082SMax Reitz# Copyright (C) 2017 Red Hat, Inc.
6*a2c7e082SMax Reitz#
7*a2c7e082SMax Reitz# This program is free software; you can redistribute it and/or modify
8*a2c7e082SMax Reitz# it under the terms of the GNU General Public License as published by
9*a2c7e082SMax Reitz# the Free Software Foundation; either version 2 of the License, or
10*a2c7e082SMax Reitz# (at your option) any later version.
11*a2c7e082SMax Reitz#
12*a2c7e082SMax Reitz# This program is distributed in the hope that it will be useful,
13*a2c7e082SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*a2c7e082SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*a2c7e082SMax Reitz# GNU General Public License for more details.
16*a2c7e082SMax Reitz#
17*a2c7e082SMax Reitz# You should have received a copy of the GNU General Public License
18*a2c7e082SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*a2c7e082SMax Reitz#
20*a2c7e082SMax Reitz
21*a2c7e082SMax Reitz# creator
22*a2c7e082SMax Reitzowner=mreitz@redhat.com
23*a2c7e082SMax Reitz
24*a2c7e082SMax Reitzseq=$(basename $0)
25*a2c7e082SMax Reitzecho "QA output created by $seq"
26*a2c7e082SMax Reitz
27*a2c7e082SMax Reitzhere=$PWD
28*a2c7e082SMax Reitzstatus=1	# failure is the default!
29*a2c7e082SMax Reitz
30*a2c7e082SMax Reitz_cleanup()
31*a2c7e082SMax Reitz{
32*a2c7e082SMax Reitz	_cleanup_test_img
33*a2c7e082SMax Reitz}
34*a2c7e082SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
35*a2c7e082SMax Reitz
36*a2c7e082SMax Reitz# get standard environment and filters
37*a2c7e082SMax Reitz. ./common.rc
38*a2c7e082SMax Reitz. ./common.filter
39*a2c7e082SMax Reitz
40*a2c7e082SMax Reitz_supported_fmt raw
41*a2c7e082SMax Reitz_supported_proto file
42*a2c7e082SMax Reitz_supported_os Linux
43*a2c7e082SMax Reitz
44*a2c7e082SMax Reitz# in kB
45*a2c7e082SMax ReitzCREATION_SIZE=128
46*a2c7e082SMax ReitzGROWTH_SIZE=256
47*a2c7e082SMax Reitz
48*a2c7e082SMax Reitzecho '=== Testing image growth ==='
49*a2c7e082SMax Reitz
50*a2c7e082SMax Reitzfor create_mode in off falloc full; do
51*a2c7e082SMax Reitz    for growth_mode in off falloc full; do
52*a2c7e082SMax Reitz        echo
53*a2c7e082SMax Reitz        echo "--- create_mode=$create_mode growth_mode=$growth_mode ---"
54*a2c7e082SMax Reitz
55*a2c7e082SMax Reitz        IMGOPTS="preallocation=$create_mode" _make_test_img ${CREATION_SIZE}K
56*a2c7e082SMax Reitz        $QEMU_IMG resize -f "$IMGFMT" --preallocation=$growth_mode "$TEST_IMG" +${GROWTH_SIZE}K
57*a2c7e082SMax Reitz
58*a2c7e082SMax Reitz        expected_size=0
59*a2c7e082SMax Reitz        if [ $create_mode != off ]; then
60*a2c7e082SMax Reitz            expected_size=$CREATION_SIZE
61*a2c7e082SMax Reitz        fi
62*a2c7e082SMax Reitz        if [ $growth_mode != off ]; then
63*a2c7e082SMax Reitz            expected_size=$((expected_size + $GROWTH_SIZE))
64*a2c7e082SMax Reitz        fi
65*a2c7e082SMax Reitz
66*a2c7e082SMax Reitz        actual_size=$($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep 'disk size')
67*a2c7e082SMax Reitz        actual_size=$(echo "$actual_size" | sed -e 's/^[^0-9]*\([0-9]\+\).*$/\1/')
68*a2c7e082SMax Reitz
69*a2c7e082SMax Reitz        # The actual size may exceed the expected size, depending on the file
70*a2c7e082SMax Reitz        # system. Therefore we just test that the actual size is at least what
71*a2c7e082SMax Reitz        # we expect.
72*a2c7e082SMax Reitz        if [ $actual_size -lt $expected_size ]; then
73*a2c7e082SMax Reitz            echo "ERROR: Image should have at least ${expected_size}K, but has ${actual_size}K"
74*a2c7e082SMax Reitz        fi
75*a2c7e082SMax Reitz    done
76*a2c7e082SMax Reitzdone
77*a2c7e082SMax Reitz
78*a2c7e082SMax Reitzecho
79*a2c7e082SMax Reitzecho '=== Testing image shrinking ==='
80*a2c7e082SMax Reitz
81*a2c7e082SMax Reitz# None of this should work except for "off", because other modes cannot be used
82*a2c7e082SMax Reitz# for shrinking
83*a2c7e082SMax Reitzfor growth_mode in falloc full off; do
84*a2c7e082SMax Reitz    echo
85*a2c7e082SMax Reitz    echo "--- growth_mode=$growth_mode ---"
86*a2c7e082SMax Reitz    $QEMU_IMG resize -f "$IMGFMT" --preallocation=$growth_mode "$TEST_IMG" -${GROWTH_SIZE}K
87*a2c7e082SMax Reitzdone
88*a2c7e082SMax Reitz
89*a2c7e082SMax Reitz# success, all done
90*a2c7e082SMax Reitzecho '*** done'
91*a2c7e082SMax Reitzrm -f $seq.full
92*a2c7e082SMax Reitzstatus=0
93