1f3d07ce8SThomas Huth#!/usr/bin/env bash 2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw quick 397f94cb4SKevin Wolf# 497f94cb4SKevin Wolf# Test qcow2 preallocation 597f94cb4SKevin Wolf# 697f94cb4SKevin Wolf# Copyright (C) 2019 Red Hat, Inc. 797f94cb4SKevin Wolf# 897f94cb4SKevin Wolf# This program is free software; you can redistribute it and/or modify 997f94cb4SKevin Wolf# it under the terms of the GNU General Public License as published by 1097f94cb4SKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1197f94cb4SKevin Wolf# (at your option) any later version. 1297f94cb4SKevin Wolf# 1397f94cb4SKevin Wolf# This program is distributed in the hope that it will be useful, 1497f94cb4SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1597f94cb4SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1697f94cb4SKevin Wolf# GNU General Public License for more details. 1797f94cb4SKevin Wolf# 1897f94cb4SKevin Wolf# You should have received a copy of the GNU General Public License 1997f94cb4SKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 2097f94cb4SKevin Wolf# 2197f94cb4SKevin Wolf 2297f94cb4SKevin Wolf# creator 2397f94cb4SKevin Wolfowner=kwolf@redhat.com 2497f94cb4SKevin Wolf 2597f94cb4SKevin Wolfseq=$(basename $0) 2697f94cb4SKevin Wolfecho "QA output created by $seq" 2797f94cb4SKevin Wolf 2897f94cb4SKevin Wolfstatus=1 # failure is the default! 2997f94cb4SKevin Wolf 3097f94cb4SKevin Wolf_cleanup() 3197f94cb4SKevin Wolf{ 3297f94cb4SKevin Wolf _cleanup_test_img 33f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.data" 3497f94cb4SKevin Wolf} 3597f94cb4SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3697f94cb4SKevin Wolf 3797f94cb4SKevin Wolf# get standard environment, filters and checks 3897f94cb4SKevin Wolf. ./common.rc 3997f94cb4SKevin Wolf. ./common.filter 4097f94cb4SKevin Wolf 4197f94cb4SKevin Wolf_supported_fmt qcow2 4297f94cb4SKevin Wolf_supported_proto file 4397f94cb4SKevin Wolf_supported_os Linux 443be2024aSMax Reitz# External data files do not work with compat=0.10, and because there 453be2024aSMax Reitz# is an explicit case for external data files here, we cannot allow 463be2024aSMax Reitz# the user to specify whether to use one 473be2024aSMax Reitz_unsupported_imgopts 'compat=0.10' data_file 4897f94cb4SKevin Wolf 4997f94cb4SKevin Wolffor mode in off metadata falloc full; do 5097f94cb4SKevin Wolf 5197f94cb4SKevin Wolf echo 5297f94cb4SKevin Wolf echo "=== preallocation=$mode ===" 5397f94cb4SKevin Wolf echo 5497f94cb4SKevin Wolf 55ffa244c8SKevin Wolf _make_test_img -o "preallocation=$mode,extent_size_hint=0" 64M 5697f94cb4SKevin Wolf 5797f94cb4SKevin Wolf printf "File size: " 5897f94cb4SKevin Wolf du -b $TEST_IMG | cut -f1 5997f94cb4SKevin Wolf 6097f94cb4SKevin Wolf # Can't use precise numbers here because they differ between filesystems 6197f94cb4SKevin Wolf printf "Disk usage: " 6297f94cb4SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 6397f94cb4SKevin Wolf 6497f94cb4SKevin Wolfdone 6597f94cb4SKevin Wolf 66c35896c5SKevin Wolffor mode in off metadata falloc full; do 67c35896c5SKevin Wolf 68c35896c5SKevin Wolf echo 69c35896c5SKevin Wolf echo "=== External data file: preallocation=$mode ===" 70c35896c5SKevin Wolf echo 71c35896c5SKevin Wolf 72ffa244c8SKevin Wolf _make_test_img \ 73ffa244c8SKevin Wolf -o "data_file=$TEST_IMG.data,preallocation=$mode,extent_size_hint=0" 64M 74c35896c5SKevin Wolf 75c35896c5SKevin Wolf echo -n "qcow2 file size: " 76c35896c5SKevin Wolf du -b $TEST_IMG | cut -f1 77c35896c5SKevin Wolf echo -n "data file size: " 78c35896c5SKevin Wolf du -b $TEST_IMG.data | cut -f1 79c35896c5SKevin Wolf 80c35896c5SKevin Wolf # Can't use precise numbers here because they differ between filesystems 81c35896c5SKevin Wolf echo -n "qcow2 disk usage: " 82c35896c5SKevin Wolf [ $(du -B1 $TEST_IMG | cut -f1) -lt 1048576 ] && echo "low" || echo "high" 83c35896c5SKevin Wolf echo -n "data disk usage: " 84ffa244c8SKevin Wolf [ $(du -B1 $TEST_IMG.data | cut -f1) -lt 2097152 ] && echo "low" || echo "high" 85c35896c5SKevin Wolf 86c35896c5SKevin Wolfdone 87c35896c5SKevin Wolf 8897f94cb4SKevin Wolf# success, all done 8997f94cb4SKevin Wolfecho "*** done" 9097f94cb4SKevin Wolfrm -f $seq.full 9197f94cb4SKevin Wolfstatus=0 92