111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2b81b74bfSEric Blake# 3b81b74bfSEric Blake# qemu-img measure sub-command tests on huge qcow2 files 4b81b74bfSEric Blake# 55d72c68bSEric Blake# Copyright (C) 2017-2020 Red Hat, Inc. 6b81b74bfSEric Blake# 7b81b74bfSEric Blake# This program is free software; you can redistribute it and/or modify 8b81b74bfSEric Blake# it under the terms of the GNU General Public License as published by 9b81b74bfSEric Blake# the Free Software Foundation; either version 2 of the License, or 10b81b74bfSEric Blake# (at your option) any later version. 11b81b74bfSEric Blake# 12b81b74bfSEric Blake# This program is distributed in the hope that it will be useful, 13b81b74bfSEric Blake# but WITHOUT ANY WARRANTY; without even the implied warranty of 14b81b74bfSEric Blake# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15b81b74bfSEric Blake# GNU General Public License for more details. 16b81b74bfSEric Blake# 17b81b74bfSEric Blake# You should have received a copy of the GNU General Public License 18b81b74bfSEric Blake# along with this program. If not, see <http://www.gnu.org/licenses/>. 19b81b74bfSEric Blake# 20b81b74bfSEric Blake 21b81b74bfSEric Blake# creator 22b81b74bfSEric Blakeowner=eblake@redhat.com 23b81b74bfSEric Blake 24b81b74bfSEric Blakeseq=`basename $0` 25b81b74bfSEric Blakeecho "QA output created by $seq" 26b81b74bfSEric Blake 27b81b74bfSEric Blakestatus=1 # failure is the default! 28b81b74bfSEric Blake 29b81b74bfSEric Blake_cleanup() 30b81b74bfSEric Blake{ 31b81b74bfSEric Blake _cleanup_test_img 32f91ecbd7SMax Reitz _rm_test_img "$TEST_IMG.converted" 33b81b74bfSEric Blake} 34b81b74bfSEric Blaketrap "_cleanup; exit \$status" 0 1 2 3 15 35b81b74bfSEric Blake 36b81b74bfSEric Blake# get standard environment, filters and checks 37b81b74bfSEric Blake. ./common.rc 38b81b74bfSEric Blake. ./common.filter 39b81b74bfSEric Blake. ./common.pattern 40b81b74bfSEric Blake 41b81b74bfSEric Blake# See 178 for more extensive tests across more formats 42b81b74bfSEric Blake_supported_fmt qcow2 43b81b74bfSEric Blake_supported_proto file 44*2e3becf9SMax Reitz# compat=0.10 does not support bitmaps 45*2e3becf9SMax Reitz_unsupported_imgopts 'compat=0.10' 46b81b74bfSEric Blake 475d72c68bSEric Blakeecho "== Huge file without bitmaps ==" 48b81b74bfSEric Blakeecho 49b81b74bfSEric Blake 50407fb56aSMax Reitz_make_test_img -o 'cluster_size=2M' 2T 51b81b74bfSEric Blake 52b81b74bfSEric Blake$QEMU_IMG measure -O raw -f qcow2 "$TEST_IMG" 53b81b74bfSEric Blake$QEMU_IMG measure -O qcow2 -o cluster_size=64k -f qcow2 "$TEST_IMG" 54b81b74bfSEric Blake$QEMU_IMG measure -O qcow2 -o cluster_size=2M -f qcow2 "$TEST_IMG" 55b81b74bfSEric Blake 565d72c68bSEric Blakeecho 575d72c68bSEric Blakeecho "== Huge file with bitmaps ==" 585d72c68bSEric Blakeecho 595d72c68bSEric Blake 605d72c68bSEric Blake$QEMU_IMG bitmap --add --granularity 512 -f qcow2 "$TEST_IMG" b1 615d72c68bSEric Blake$QEMU_IMG bitmap --add -g 2M -f qcow2 "$TEST_IMG" b2 625d72c68bSEric Blake 635d72c68bSEric Blake# No bitmap without a source 645d72c68bSEric Blake$QEMU_IMG measure -O qcow2 --size 10M 655d72c68bSEric Blake# No bitmap output, since raw does not support it 665d72c68bSEric Blake$QEMU_IMG measure -O raw -f qcow2 "$TEST_IMG" 675d72c68bSEric Blake# No bitmap output, since no bitmaps on raw source. Munge required size, as 685d72c68bSEric Blake# some filesystems store the qcow2 file with less sparseness than others 695d72c68bSEric Blake$QEMU_IMG measure -O qcow2 -f raw "$TEST_IMG" | 705d72c68bSEric Blake sed '/^required size:/ s/[0-9][0-9]*/SIZE/' 715d72c68bSEric Blake# No bitmap output, since v2 does not support it 725d72c68bSEric Blake$QEMU_IMG measure -O qcow2 -o compat=0.10 -f qcow2 "$TEST_IMG" 735d72c68bSEric Blake 745d72c68bSEric Blake# Compute expected output: bitmap clusters + bitmap tables + bitmaps directory 755d72c68bSEric Blakeecho 765d72c68bSEric Blakeval2T=$((2*1024*1024*1024*1024)) 775d72c68bSEric Blakecluster=$((64*1024)) 785d72c68bSEric Blakeb1clusters=$(( (val2T/512/8 + cluster - 1) / cluster )) 795d72c68bSEric Blakeb2clusters=$(( (val2T/2/1024/1024/8 + cluster - 1) / cluster )) 805d72c68bSEric Blakeecho expected bitmap $((b1clusters * cluster + 815d72c68bSEric Blake (b1clusters * 8 + cluster - 1) / cluster * cluster + 825d72c68bSEric Blake b2clusters * cluster + 835d72c68bSEric Blake (b2clusters * 8 + cluster - 1) / cluster * cluster + 845d72c68bSEric Blake cluster)) 855d72c68bSEric Blake$QEMU_IMG measure -O qcow2 -o cluster_size=64k -f qcow2 "$TEST_IMG" 865d72c68bSEric Blake 875d72c68bSEric Blake# Compute expected output: bitmap clusters + bitmap tables + bitmaps directory 885d72c68bSEric Blakeecho 895d72c68bSEric Blakecluster=$((2*1024*1024)) 905d72c68bSEric Blakeb1clusters=$(( (val2T/512/8 + cluster - 1) / cluster )) 915d72c68bSEric Blakeb2clusters=$(( (val2T/2/1024/1024/8 + cluster - 1) / cluster )) 925d72c68bSEric Blakeecho expected bitmap $((b1clusters * cluster + 935d72c68bSEric Blake (b1clusters * 8 + cluster - 1) / cluster * cluster + 945d72c68bSEric Blake b2clusters * cluster + 955d72c68bSEric Blake (b2clusters * 8 + cluster - 1) / cluster * cluster + 965d72c68bSEric Blake cluster)) 975d72c68bSEric Blake$QEMU_IMG measure --output=json -O qcow2 -o cluster_size=2M -f qcow2 "$TEST_IMG" 985d72c68bSEric Blake 99b81b74bfSEric Blake# success, all done 100b81b74bfSEric Blakeecho "*** done" 101b81b74bfSEric Blakerm -f $seq.full 102b81b74bfSEric Blakestatus=0 103