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 32f91ecbd7SMax 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 433be2024aSMax Reitz# External data files do not work with compat=0.10, and because there 443be2024aSMax Reitz# is an explicit case for external data files here, we cannot allow 453be2024aSMax Reitz# the user to specify whether to use one 463be2024aSMax Reitz_unsupported_imgopts 'compat=0.10' data_file 4797f94cb4SKevin Wolf 4897f94cb4SKevin Wolffor mode in off metadata falloc full; do 4997f94cb4SKevin Wolf 5097f94cb4SKevin Wolf echo 5197f94cb4SKevin Wolf echo "=== preallocation=$mode ===" 5297f94cb4SKevin Wolf echo 5397f94cb4SKevin Wolf 54*ffa244c8SKevin Wolf _make_test_img -o "preallocation=$mode,extent_size_hint=0" 64M 5597f94cb4SKevin Wolf 5697f94cb4SKevin Wolf printf "File size: " 5797f94cb4SKevin Wolf du -b $TEST_IMG | cut -f1 5897f94cb4SKevin Wolf 5997f94cb4SKevin Wolf # Can't use precise numbers here because they differ between filesystems 6097f94cb4SKevin Wolf printf "Disk usage: " 6197f94cb4SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 6297f94cb4SKevin Wolf 6397f94cb4SKevin Wolfdone 6497f94cb4SKevin Wolf 65c35896c5SKevin Wolffor mode in off metadata falloc full; do 66c35896c5SKevin Wolf 67c35896c5SKevin Wolf echo 68c35896c5SKevin Wolf echo "=== External data file: preallocation=$mode ===" 69c35896c5SKevin Wolf echo 70c35896c5SKevin Wolf 71*ffa244c8SKevin Wolf _make_test_img \ 72*ffa244c8SKevin Wolf -o "data_file=$TEST_IMG.data,preallocation=$mode,extent_size_hint=0" 64M 73c35896c5SKevin Wolf 74c35896c5SKevin Wolf echo -n "qcow2 file size: " 75c35896c5SKevin Wolf du -b $TEST_IMG | cut -f1 76c35896c5SKevin Wolf echo -n "data file size: " 77c35896c5SKevin Wolf du -b $TEST_IMG.data | cut -f1 78c35896c5SKevin Wolf 79c35896c5SKevin Wolf # Can't use precise numbers here because they differ between filesystems 80c35896c5SKevin Wolf echo -n "qcow2 disk usage: " 81c35896c5SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 82c35896c5SKevin Wolf echo -n "data disk usage: " 83*ffa244c8SKevin Wolf [ $(du -B1 $TEST_IMG.data | cut -f1) -lt 2097152 ] && echo "low" || echo "high" 84c35896c5SKevin Wolf 85c35896c5SKevin Wolfdone 86c35896c5SKevin Wolf 8797f94cb4SKevin Wolf# success, all done 8897f94cb4SKevin Wolfecho "*** done" 8997f94cb4SKevin Wolfrm -f $seq.full 9097f94cb4SKevin Wolfstatus=0 91