s390x: do not include ram_addr.h
[qemu/ar7.git] / tests / qemu-iotests / 121
blob0912c3f0cb0a29f56b8d6072ca9f927ee26ca48b
1 #!/bin/bash
3 # Test cases for qcow2 refcount table growth
5 # Copyright (C) 2015 Red Hat, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # creator
22 owner=mreitz@redhat.com
24 seq="$(basename $0)"
25 echo "QA output created by $seq"
27 here="$PWD"
28 tmp=/tmp/$$
29 status=1 # failure is the default!
31 _cleanup()
33 _cleanup_test_img
35 trap "_cleanup; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
41 _supported_fmt qcow2
42 _supported_proto file
43 _supported_os Linux
45 echo
46 echo '=== New refcount structures may not conflict with existing structures ==='
48 echo
49 echo '--- Test 1 ---'
50 echo
52 # Preallocation speeds up the write operation, but preallocating everything will
53 # destroy the purpose of the write; so preallocate one KB less than what would
54 # cause a reftable growth...
55 IMGOPTS='preallocation=metadata,cluster_size=1k' _make_test_img 64512K
56 # ...and make the image the desired size afterwards.
57 $QEMU_IMG resize "$TEST_IMG" 65M
59 # The first write results in a growth of the refcount table during an allocation
60 # which has precisely the required size so that the new refcount block allocated
61 # in alloc_refcount_block() is right after cluster_index; this did lead to a
62 # different refcount block being written to disk (a zeroed cluster) than what is
63 # cached (a refblock with one entry having a refcount of 1), and the second
64 # write would then result in that cached cluster being marked dirty and then
65 # in it being written to disk.
66 # This should not happen, the new refcount structures may not conflict with
67 # new_block.
68 # (Note that for some reason, 'write 63M 1K' does not trigger the problem)
69 $QEMU_IO -c 'write 62M 1025K' -c 'write 64M 1M' "$TEST_IMG" | _filter_qemu_io
71 _check_test_img
74 echo
75 echo '--- Test 2 ---'
76 echo
78 IMGOPTS='preallocation=metadata,cluster_size=1k' _make_test_img 64513K
79 # This results in an L1 table growth which in turn results in some clusters at
80 # the start of the image becoming free
81 $QEMU_IMG resize "$TEST_IMG" 65M
83 # This write results in a refcount table growth; but the refblock allocated
84 # immediately before that (new_block) takes cluster index 4 (which is now free)
85 # and is thus not self-describing (in contrast to test 1, where new_block was
86 # self-describing). The refcount table growth algorithm then used to place the
87 # new refcount structures at cluster index 65536 (which is the same as the
88 # cluster_index parameter in this case), allocating a new refcount block for
89 # that cluster while new_block already existed, leaking new_block.
90 # Therefore, the new refcount structures may not be put at cluster_index
91 # (because new_block already describes that cluster, and the new structures try
92 # to be self-describing).
93 $QEMU_IO -c 'write 63M 130K' "$TEST_IMG" | _filter_qemu_io
95 _check_test_img
98 # success, all done
99 echo
100 echo '*** done'
101 rm -f $seq.full
102 status=0