197f94cb4SKevin Wolf#!/bin/bash 297f94cb4SKevin Wolf# 397f94cb4SKevin Wolf# Test qcow2 preallocation 497f94cb4SKevin Wolf# 597f94cb4SKevin Wolf# Copyright (C) 2019 Red Hat, Inc. 697f94cb4SKevin Wolf# 797f94cb4SKevin Wolf# This program is free software; you can redistribute it and/or modify 897f94cb4SKevin Wolf# it under the terms of the GNU General Public License as published by 997f94cb4SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1097f94cb4SKevin Wolf# (at your option) any later version. 1197f94cb4SKevin Wolf# 1297f94cb4SKevin Wolf# This program is distributed in the hope that it will be useful, 1397f94cb4SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1497f94cb4SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1597f94cb4SKevin Wolf# GNU General Public License for more details. 1697f94cb4SKevin Wolf# 1797f94cb4SKevin Wolf# You should have received a copy of the GNU General Public License 1897f94cb4SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 1997f94cb4SKevin Wolf# 2097f94cb4SKevin Wolf 2197f94cb4SKevin Wolf# creator 2297f94cb4SKevin Wolfowner=kwolf@redhat.com 2397f94cb4SKevin Wolf 2497f94cb4SKevin Wolfseq=$(basename $0) 2597f94cb4SKevin Wolfecho "QA output created by $seq" 2697f94cb4SKevin Wolf 2797f94cb4SKevin Wolfstatus=1 # failure is the default! 2897f94cb4SKevin Wolf 2997f94cb4SKevin Wolf_cleanup() 3097f94cb4SKevin Wolf{ 3197f94cb4SKevin Wolf _cleanup_test_img 32*c35896c5SKevin Wolf rm -f $TEST_IMG.data 3397f94cb4SKevin Wolf} 3497f94cb4SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3597f94cb4SKevin Wolf 3697f94cb4SKevin Wolf# get standard environment, filters and checks 3797f94cb4SKevin Wolf. ./common.rc 3897f94cb4SKevin Wolf. ./common.filter 3997f94cb4SKevin Wolf 4097f94cb4SKevin Wolf_supported_fmt qcow2 4197f94cb4SKevin Wolf_supported_proto file 4297f94cb4SKevin Wolf_supported_os Linux 4397f94cb4SKevin Wolf 4497f94cb4SKevin Wolffor mode in off metadata falloc full; do 4597f94cb4SKevin Wolf 4697f94cb4SKevin Wolf echo 4797f94cb4SKevin Wolf echo "=== preallocation=$mode ===" 4897f94cb4SKevin Wolf echo 4997f94cb4SKevin Wolf 5097f94cb4SKevin Wolf IMGOPTS="preallocation=$mode" _make_test_img 64M 5197f94cb4SKevin Wolf 5297f94cb4SKevin Wolf printf "File size: " 5397f94cb4SKevin Wolf du -b $TEST_IMG | cut -f1 5497f94cb4SKevin Wolf 5597f94cb4SKevin Wolf # Can't use precise numbers here because they differ between filesystems 5697f94cb4SKevin Wolf printf "Disk usage: " 5797f94cb4SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 5897f94cb4SKevin Wolf 5997f94cb4SKevin Wolfdone 6097f94cb4SKevin Wolf 61*c35896c5SKevin Wolffor mode in off metadata falloc full; do 62*c35896c5SKevin Wolf 63*c35896c5SKevin Wolf echo 64*c35896c5SKevin Wolf echo "=== External data file: preallocation=$mode ===" 65*c35896c5SKevin Wolf echo 66*c35896c5SKevin Wolf 67*c35896c5SKevin Wolf IMGOPTS="data_file=$TEST_IMG.data,preallocation=$mode" _make_test_img 64M 68*c35896c5SKevin Wolf 69*c35896c5SKevin Wolf echo -n "qcow2 file size: " 70*c35896c5SKevin Wolf du -b $TEST_IMG | cut -f1 71*c35896c5SKevin Wolf echo -n "data file size: " 72*c35896c5SKevin Wolf du -b $TEST_IMG.data | cut -f1 73*c35896c5SKevin Wolf 74*c35896c5SKevin Wolf # Can't use precise numbers here because they differ between filesystems 75*c35896c5SKevin Wolf echo -n "qcow2 disk usage: " 76*c35896c5SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 77*c35896c5SKevin Wolf echo -n "data disk usage: " 78*c35896c5SKevin Wolf [ $(du -B1 $TEST_IMG.data | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 79*c35896c5SKevin Wolf 80*c35896c5SKevin Wolfdone 81*c35896c5SKevin Wolf 8297f94cb4SKevin Wolf# success, all done 8397f94cb4SKevin Wolfecho "*** done" 8497f94cb4SKevin Wolfrm -f $seq.full 8597f94cb4SKevin Wolfstatus=0 86