1f3d07ce8SThomas Huth#!/usr/bin/env 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*f91ecbd7SMax Reitz _rm_test_img "$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 43407fb56aSMax Reitz# External data files do not work with compat=0.10 44407fb56aSMax Reitz_unsupported_imgopts 'compat=0.10' 4597f94cb4SKevin Wolf 4697f94cb4SKevin Wolffor mode in off metadata falloc full; do 4797f94cb4SKevin Wolf 4897f94cb4SKevin Wolf echo 4997f94cb4SKevin Wolf echo "=== preallocation=$mode ===" 5097f94cb4SKevin Wolf echo 5197f94cb4SKevin Wolf 52407fb56aSMax Reitz _make_test_img -o "preallocation=$mode" 64M 5397f94cb4SKevin Wolf 5497f94cb4SKevin Wolf printf "File size: " 5597f94cb4SKevin Wolf du -b $TEST_IMG | cut -f1 5697f94cb4SKevin Wolf 5797f94cb4SKevin Wolf # Can't use precise numbers here because they differ between filesystems 5897f94cb4SKevin Wolf printf "Disk usage: " 5997f94cb4SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 6097f94cb4SKevin Wolf 6197f94cb4SKevin Wolfdone 6297f94cb4SKevin Wolf 63c35896c5SKevin Wolffor mode in off metadata falloc full; do 64c35896c5SKevin Wolf 65c35896c5SKevin Wolf echo 66c35896c5SKevin Wolf echo "=== External data file: preallocation=$mode ===" 67c35896c5SKevin Wolf echo 68c35896c5SKevin Wolf 69407fb56aSMax Reitz _make_test_img -o "data_file=$TEST_IMG.data,preallocation=$mode" 64M 70c35896c5SKevin Wolf 71c35896c5SKevin Wolf echo -n "qcow2 file size: " 72c35896c5SKevin Wolf du -b $TEST_IMG | cut -f1 73c35896c5SKevin Wolf echo -n "data file size: " 74c35896c5SKevin Wolf du -b $TEST_IMG.data | cut -f1 75c35896c5SKevin Wolf 76c35896c5SKevin Wolf # Can't use precise numbers here because they differ between filesystems 77c35896c5SKevin Wolf echo -n "qcow2 disk usage: " 78c35896c5SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 79c35896c5SKevin Wolf echo -n "data disk usage: " 80c35896c5SKevin Wolf [ $(du -B1 $TEST_IMG.data | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 81c35896c5SKevin Wolf 82c35896c5SKevin Wolfdone 83c35896c5SKevin Wolf 8497f94cb4SKevin Wolf# success, all done 8597f94cb4SKevin Wolfecho "*** done" 8697f94cb4SKevin Wolfrm -f $seq.full 8797f94cb4SKevin Wolfstatus=0 88