xref: /openbmc/qemu/tests/qemu-iotests/190 (revision 5d72c68b49769c927e90b78af6d90f6a384b26ac)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2b81b74bfSEric Blake#
3b81b74bfSEric Blake# qemu-img measure sub-command tests on huge qcow2 files
4b81b74bfSEric Blake#
5*5d72c68bSEric 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
44b81b74bfSEric Blake
45*5d72c68bSEric Blakeecho "== Huge file without bitmaps =="
46b81b74bfSEric Blakeecho
47b81b74bfSEric Blake
48407fb56aSMax Reitz_make_test_img -o 'cluster_size=2M' 2T
49b81b74bfSEric Blake
50b81b74bfSEric Blake$QEMU_IMG measure -O raw -f qcow2 "$TEST_IMG"
51b81b74bfSEric Blake$QEMU_IMG measure -O qcow2 -o cluster_size=64k -f qcow2 "$TEST_IMG"
52b81b74bfSEric Blake$QEMU_IMG measure -O qcow2 -o cluster_size=2M -f qcow2 "$TEST_IMG"
53b81b74bfSEric Blake
54*5d72c68bSEric Blakeecho
55*5d72c68bSEric Blakeecho "== Huge file with bitmaps =="
56*5d72c68bSEric Blakeecho
57*5d72c68bSEric Blake
58*5d72c68bSEric Blake$QEMU_IMG bitmap --add --granularity 512 -f qcow2 "$TEST_IMG" b1
59*5d72c68bSEric Blake$QEMU_IMG bitmap --add -g 2M -f qcow2 "$TEST_IMG" b2
60*5d72c68bSEric Blake
61*5d72c68bSEric Blake# No bitmap without a source
62*5d72c68bSEric Blake$QEMU_IMG measure -O qcow2 --size 10M
63*5d72c68bSEric Blake# No bitmap output, since raw does not support it
64*5d72c68bSEric Blake$QEMU_IMG measure -O raw -f qcow2 "$TEST_IMG"
65*5d72c68bSEric Blake# No bitmap output, since no bitmaps on raw source. Munge required size, as
66*5d72c68bSEric Blake# some filesystems store the qcow2 file with less sparseness than others
67*5d72c68bSEric Blake$QEMU_IMG measure -O qcow2 -f raw "$TEST_IMG" |
68*5d72c68bSEric Blake    sed '/^required size:/ s/[0-9][0-9]*/SIZE/'
69*5d72c68bSEric Blake# No bitmap output, since v2 does not support it
70*5d72c68bSEric Blake$QEMU_IMG measure -O qcow2 -o compat=0.10 -f qcow2 "$TEST_IMG"
71*5d72c68bSEric Blake
72*5d72c68bSEric Blake# Compute expected output: bitmap clusters + bitmap tables + bitmaps directory
73*5d72c68bSEric Blakeecho
74*5d72c68bSEric Blakeval2T=$((2*1024*1024*1024*1024))
75*5d72c68bSEric Blakecluster=$((64*1024))
76*5d72c68bSEric Blakeb1clusters=$(( (val2T/512/8 + cluster - 1) / cluster ))
77*5d72c68bSEric Blakeb2clusters=$(( (val2T/2/1024/1024/8 + cluster - 1) / cluster ))
78*5d72c68bSEric Blakeecho expected bitmap $((b1clusters * cluster +
79*5d72c68bSEric Blake                        (b1clusters * 8 + cluster - 1) / cluster * cluster +
80*5d72c68bSEric Blake                        b2clusters * cluster +
81*5d72c68bSEric Blake                        (b2clusters * 8 + cluster - 1) / cluster * cluster +
82*5d72c68bSEric Blake                        cluster))
83*5d72c68bSEric Blake$QEMU_IMG measure -O qcow2 -o cluster_size=64k -f qcow2 "$TEST_IMG"
84*5d72c68bSEric Blake
85*5d72c68bSEric Blake# Compute expected output: bitmap clusters + bitmap tables + bitmaps directory
86*5d72c68bSEric Blakeecho
87*5d72c68bSEric Blakecluster=$((2*1024*1024))
88*5d72c68bSEric Blakeb1clusters=$(( (val2T/512/8 + cluster - 1) / cluster ))
89*5d72c68bSEric Blakeb2clusters=$(( (val2T/2/1024/1024/8 + cluster - 1) / cluster ))
90*5d72c68bSEric Blakeecho expected bitmap $((b1clusters * cluster +
91*5d72c68bSEric Blake                        (b1clusters * 8 + cluster - 1) / cluster * cluster +
92*5d72c68bSEric Blake                        b2clusters * cluster +
93*5d72c68bSEric Blake                        (b2clusters * 8 + cluster - 1) / cluster * cluster +
94*5d72c68bSEric Blake                        cluster))
95*5d72c68bSEric Blake$QEMU_IMG measure --output=json -O qcow2 -o cluster_size=2M -f qcow2 "$TEST_IMG"
96*5d72c68bSEric Blake
97b81b74bfSEric Blake# success, all done
98b81b74bfSEric Blakeecho "*** done"
99b81b74bfSEric Blakerm -f $seq.full
100b81b74bfSEric Blakestatus=0
101