4 # Test for the regression fixed in commit c8bf9a9169
6 # Copyright (C) 2020 Igalia, S.L.
7 # Author: Alberto Garcia <berto@igalia.com>
8 # Based on a test case by Maxim Levitsky <mlevitsk@redhat.com>
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 owner=berto@igalia.com
28 echo "QA output created by $seq"
30 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # get standard environment, filters and checks
45 _unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file
47 # The cluster size must be at least the granularity of the mirror job (4KB)
48 # Note that larger cluster sizes will produce very large images (several GBs)
50 refcount_bits=64 # Make it equal to the L2 entry size for convenience
51 options="cluster_size=${cluster_size},refcount_bits=${refcount_bits}"
53 # Number of refcount entries per refcount blocks
54 ref_entries=$(( ${cluster_size} * 8 / ${refcount_bits} ))
56 # Number of data clusters needed to fill a refcount block
57 # Equals ${ref_entries} minus two (one L2 table and one refcount block)
58 data_clusters_per_refblock=$(( ${ref_entries} - 2 ))
60 # Number of entries in the refcount cache
63 # Write enough data clusters to fill the refcount cache and allocate
64 # one more refcount block.
65 # Subtract 3 clusters from the total: qcow2 header, refcount table, L1 table
66 total_data_clusters=$(( ${data_clusters_per_refblock} * ${ref_blocks} + 1 - 3 ))
68 # Total size to write in bytes
69 total_size=$(( ${total_data_clusters} * ${cluster_size} ))
72 echo '### Create the image'
74 TEST_IMG_FILE=$TEST_IMG.base _make_test_img -o $options $total_size | _filter_img_create_size
77 echo '### Write data to allocate more refcount blocks than the cache can hold'
79 $QEMU_IO -c "write -P 1 0 $total_size" $TEST_IMG.base | _filter_qemu_io
82 echo '### Create an overlay'
84 _make_test_img -F $IMGFMT -b $TEST_IMG.base -o $options | _filter_img_create_size
87 echo '### Fill the overlay with zeroes'
89 $QEMU_IO -c "write -z 0 $total_size" $TEST_IMG | _filter_qemu_io
92 echo '### Commit changes to the base image'
94 $QEMU_IMG commit $TEST_IMG
97 echo '### Check the base image'
99 $QEMU_IMG check $TEST_IMG.base