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