Merge remote-tracking branch 'remotes/kraxel/tags/ui-20210311-pull-request' into...
[qemu/ar7.git] / tests / qemu-iotests / 115
blob26dd37dd6d150dd1c3fa4c3892e53ea7d97ddc20
1 #!/usr/bin/env bash
2 # group: rw
4 # Test case for non-self-referential qcow2 refcount blocks
6 # Copyright (C) 2014 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=mreitz@redhat.com
25 seq="$(basename $0)"
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
40 _supported_fmt qcow2
41 _supported_proto file fuse
42 # This test relies on refcounts being 64 bits wide (which does not work with
43 # compat=0.10)
44 _unsupported_imgopts 'refcount_bits=\([^6]\|.\([^4]\|$\)\)' 'compat=0.10'
46 echo
47 echo '=== Testing large refcount and L1 table ==='
48 echo
50 # Create an image with an L1 table and a refcount table that each span twice the
51 # number of clusters which can be described by a single refblock; therefore, at
52 # least two refblocks cannot count their own refcounts because all the clusters
53 # they describe are part of the L1 table or refcount table.
55 # One refblock can describe (with cluster_size=512 and refcount_bits=64)
56 # 512/8 = 64 clusters, therefore the L1 table should cover 128 clusters, which
57 # equals 128 * (512/8) = 8192 entries (actually, 8192 - 512/8 = 8129 would
58 # suffice, but it does not really matter). 8192 L2 tables can in turn describe
59 # 8192 * 512/8 = 524,288 clusters which cover a space of 256 MB.
61 # Since with refcount_bits=64 every refcount block entry is 64 bits wide (just
62 # like the L2 table entries), the same calculation applies to the refcount table
63 # as well; the difference is that while for the L1 table the guest disk size is
64 # concerned, for the refcount table it is the image length that has to be at
65 # least 256 MB. We can achieve that by using preallocation=metadata for an image
66 # which has a guest disk size of 256 MB.
68 _make_test_img -o "refcount_bits=64,cluster_size=512,preallocation=metadata" 256M
70 # We know for sure that the L1 and refcount tables do not overlap with any other
71 # structure because the metadata overlap checks would have caught that case.
73 # Because qemu refuses to open qcow2 files whose L1 table does not cover the
74 # whole guest disk size, it is definitely large enough. On the other hand, to
75 # test whether the refcount table is large enough, we simply have to verify that
76 # indeed all the clusters are allocated, which is done by qemu-img check.
78 # The final thing we need to test is whether the tables are actually covered by
79 # refcount blocks; since all clusters of the tables are referenced, we can use
80 # qemu-img check for that purpose, too.
82 $QEMU_IMG check "$TEST_IMG" | \
83 sed -e 's/^.* = \([0-9]\+\.[0-9]\+% allocated\).*\(clusters\)$/\1 \2/' \
84 -e '/^Image end offset/d'
86 # (Note that we cannot use _check_test_img because that function filters out the
87 # allocation status)
89 # success, all done
90 echo '*** done'
91 rm -f $seq.full
92 status=0