4 # Test cases for qcow2 refcount table growth
6 # Copyright (C) 2015 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/>.
23 owner
=mreitz@redhat.com
26 echo "QA output created by $seq"
28 status
=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
41 _supported_proto
file fuse
43 # Refcount structures are used much differently with external data
45 _unsupported_imgopts data_file
48 echo '=== New refcount structures may not conflict with existing structures ==='
54 # Preallocation speeds up the write operation, but preallocating everything will
55 # destroy the purpose of the write; so preallocate one KB less than what would
56 # cause a reftable growth...
57 _make_test_img
-o 'preallocation=metadata,cluster_size=1k' 64512K
58 # ...and make the image the desired size afterwards.
59 $QEMU_IMG resize
"$TEST_IMG" 65M
61 # The first write results in a growth of the refcount table during an allocation
62 # which has precisely the required size so that the new refcount block allocated
63 # in alloc_refcount_block() is right after cluster_index; this did lead to a
64 # different refcount block being written to disk (a zeroed cluster) than what is
65 # cached (a refblock with one entry having a refcount of 1), and the second
66 # write would then result in that cached cluster being marked dirty and then
67 # in it being written to disk.
68 # This should not happen, the new refcount structures may not conflict with
70 # (Note that for some reason, 'write 63M 1K' does not trigger the problem)
71 $QEMU_IO -c 'write 62M 1025K' -c 'write 64M 1M' "$TEST_IMG" | _filter_qemu_io
80 _make_test_img
-o 'preallocation=metadata,cluster_size=1k' 64513K
81 # This results in an L1 table growth which in turn results in some clusters at
82 # the start of the image becoming free
83 $QEMU_IMG resize
"$TEST_IMG" 65M
85 # This write results in a refcount table growth; but the refblock allocated
86 # immediately before that (new_block) takes cluster index 4 (which is now free)
87 # and is thus not self-describing (in contrast to test 1, where new_block was
88 # self-describing). The refcount table growth algorithm then used to place the
89 # new refcount structures at cluster index 65536 (which is the same as the
90 # cluster_index parameter in this case), allocating a new refcount block for
91 # that cluster while new_block already existed, leaking new_block.
92 # Therefore, the new refcount structures may not be put at cluster_index
93 # (because new_block already describes that cluster, and the new structures try
94 # to be self-describing).
95 $QEMU_IO -c 'write 63M 130K' "$TEST_IMG" | _filter_qemu_io
100 echo '=== Allocating a new refcount block must not leave holes in the image ==='
103 _make_test_img
-o 'cluster_size=512,refcount_bits=16' 1M
105 # This results in an image with 256 used clusters: the qcow2 header,
106 # the refcount table, one refcount block, the L1 table, four L2 tables
107 # and 248 data clusters
108 $QEMU_IO -c 'write 0 124k' "$TEST_IMG" | _filter_qemu_io
110 # 256 clusters of 512 bytes each give us a 128K image
111 stat
-c "size=%s (expected 131072)" $TEST_IMG
113 # All 256 entries of the refcount block are used, so writing a new
114 # data cluster also allocates a new refcount block
115 $QEMU_IO -c 'write 124k 512' "$TEST_IMG" | _filter_qemu_io
117 # Two more clusters, the image size should be 129K now
118 stat
-c "size=%s (expected 132096)" $TEST_IMG