xref: /openbmc/qemu/tests/qemu-iotests/313 (revision 812b31d3)
1#!/usr/bin/env bash
2# group: rw auto quick
3#
4# Test for the regression fixed in commit c8bf9a9169
5#
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>
9#
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.
14#
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.
19#
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/>.
22#
23
24# creator
25owner=berto@igalia.com
26
27seq=`basename $0`
28echo "QA output created by $seq"
29
30status=1    # failure is the default!
31
32_cleanup()
33{
34    _cleanup_test_img
35}
36trap "_cleanup; exit \$status" 0 1 2 3 15
37
38# get standard environment, filters and checks
39. ./common.rc
40. ./common.filter
41
42_supported_fmt qcow2
43_supported_proto file
44_supported_os Linux
45_unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file
46
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)
49cluster_size=4096
50refcount_bits=64 # Make it equal to the L2 entry size for convenience
51options="cluster_size=${cluster_size},refcount_bits=${refcount_bits}"
52
53# Number of refcount entries per refcount blocks
54ref_entries=$(( ${cluster_size} * 8 / ${refcount_bits} ))
55
56# Number of data clusters needed to fill a refcount block
57# Equals ${ref_entries} minus two (one L2 table and one refcount block)
58data_clusters_per_refblock=$(( ${ref_entries} - 2 ))
59
60# Number of entries in the refcount cache
61ref_blocks=4
62
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
66total_data_clusters=$(( ${data_clusters_per_refblock} * ${ref_blocks} + 1 - 3 ))
67
68# Total size to write in bytes
69total_size=$(( ${total_data_clusters} * ${cluster_size} ))
70
71echo
72echo '### Create the image'
73echo
74TEST_IMG_FILE=$TEST_IMG.base _make_test_img -o $options $total_size | _filter_img_create_size
75
76echo
77echo '### Write data to allocate more refcount blocks than the cache can hold'
78echo
79$QEMU_IO -c "write -P 1 0 $total_size" $TEST_IMG.base | _filter_qemu_io
80
81echo
82echo '### Create an overlay'
83echo
84_make_test_img -F $IMGFMT -b $TEST_IMG.base -o $options | _filter_img_create_size
85
86echo
87echo '### Fill the overlay with zeroes'
88echo
89$QEMU_IO -c "write -z 0 $total_size" $TEST_IMG | _filter_qemu_io
90
91echo
92echo '### Commit changes to the base image'
93echo
94$QEMU_IMG commit $TEST_IMG
95
96echo
97echo '### Check the base image'
98echo
99$QEMU_IMG check $TEST_IMG.base
100
101# success, all done
102echo "*** done"
103rm -f $seq.full
104status=0
105