xref: /openbmc/qemu/tests/qemu-iotests/313 (revision 5101d00d)
1*0f46147eSAlberto Garcia#!/usr/bin/env bash
2*0f46147eSAlberto Garcia# group: rw auto quick
3*0f46147eSAlberto Garcia#
4*0f46147eSAlberto Garcia# Test for the regression fixed in commit c8bf9a9169
5*0f46147eSAlberto Garcia#
6*0f46147eSAlberto Garcia# Copyright (C) 2020 Igalia, S.L.
7*0f46147eSAlberto Garcia# Author: Alberto Garcia <berto@igalia.com>
8*0f46147eSAlberto Garcia# Based on a test case by Maxim Levitsky <mlevitsk@redhat.com>
9*0f46147eSAlberto Garcia#
10*0f46147eSAlberto Garcia# This program is free software; you can redistribute it and/or modify
11*0f46147eSAlberto Garcia# it under the terms of the GNU General Public License as published by
12*0f46147eSAlberto Garcia# the Free Software Foundation; either version 2 of the License, or
13*0f46147eSAlberto Garcia# (at your option) any later version.
14*0f46147eSAlberto Garcia#
15*0f46147eSAlberto Garcia# This program is distributed in the hope that it will be useful,
16*0f46147eSAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*0f46147eSAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*0f46147eSAlberto Garcia# GNU General Public License for more details.
19*0f46147eSAlberto Garcia#
20*0f46147eSAlberto Garcia# You should have received a copy of the GNU General Public License
21*0f46147eSAlberto Garcia# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22*0f46147eSAlberto Garcia#
23*0f46147eSAlberto Garcia
24*0f46147eSAlberto Garcia# creator
25*0f46147eSAlberto Garciaowner=berto@igalia.com
26*0f46147eSAlberto Garcia
27*0f46147eSAlberto Garciaseq=`basename $0`
28*0f46147eSAlberto Garciaecho "QA output created by $seq"
29*0f46147eSAlberto Garcia
30*0f46147eSAlberto Garciastatus=1    # failure is the default!
31*0f46147eSAlberto Garcia
32*0f46147eSAlberto Garcia_cleanup()
33*0f46147eSAlberto Garcia{
34*0f46147eSAlberto Garcia    _cleanup_test_img
35*0f46147eSAlberto Garcia}
36*0f46147eSAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15
37*0f46147eSAlberto Garcia
38*0f46147eSAlberto Garcia# get standard environment, filters and checks
39*0f46147eSAlberto Garcia. ./common.rc
40*0f46147eSAlberto Garcia. ./common.filter
41*0f46147eSAlberto Garcia
42*0f46147eSAlberto Garcia_supported_fmt qcow2
43*0f46147eSAlberto Garcia_supported_proto file
44*0f46147eSAlberto Garcia_supported_os Linux
45*0f46147eSAlberto Garcia_unsupported_imgopts cluster_size refcount_bits extended_l2 compat=0.10 data_file
46*0f46147eSAlberto Garcia
47*0f46147eSAlberto Garcia# The cluster size must be at least the granularity of the mirror job (4KB)
48*0f46147eSAlberto Garcia# Note that larger cluster sizes will produce very large images (several GBs)
49*0f46147eSAlberto Garciacluster_size=4096
50*0f46147eSAlberto Garciarefcount_bits=64 # Make it equal to the L2 entry size for convenience
51*0f46147eSAlberto Garciaoptions="cluster_size=${cluster_size},refcount_bits=${refcount_bits}"
52*0f46147eSAlberto Garcia
53*0f46147eSAlberto Garcia# Number of refcount entries per refcount blocks
54*0f46147eSAlberto Garciaref_entries=$(( ${cluster_size} * 8 / ${refcount_bits} ))
55*0f46147eSAlberto Garcia
56*0f46147eSAlberto Garcia# Number of data clusters needed to fill a refcount block
57*0f46147eSAlberto Garcia# Equals ${ref_entries} minus two (one L2 table and one refcount block)
58*0f46147eSAlberto Garciadata_clusters_per_refblock=$(( ${ref_entries} - 2 ))
59*0f46147eSAlberto Garcia
60*0f46147eSAlberto Garcia# Number of entries in the refcount cache
61*0f46147eSAlberto Garciaref_blocks=4
62*0f46147eSAlberto Garcia
63*0f46147eSAlberto Garcia# Write enough data clusters to fill the refcount cache and allocate
64*0f46147eSAlberto Garcia# one more refcount block.
65*0f46147eSAlberto Garcia# Subtract 3 clusters from the total: qcow2 header, refcount table, L1 table
66*0f46147eSAlberto Garciatotal_data_clusters=$(( ${data_clusters_per_refblock} * ${ref_blocks} + 1 - 3 ))
67*0f46147eSAlberto Garcia
68*0f46147eSAlberto Garcia# Total size to write in bytes
69*0f46147eSAlberto Garciatotal_size=$(( ${total_data_clusters} * ${cluster_size} ))
70*0f46147eSAlberto Garcia
71*0f46147eSAlberto Garciaecho
72*0f46147eSAlberto Garciaecho '### Create the image'
73*0f46147eSAlberto Garciaecho
74*0f46147eSAlberto GarciaTEST_IMG_FILE=$TEST_IMG.base _make_test_img -o $options $total_size | _filter_img_create_size
75*0f46147eSAlberto Garcia
76*0f46147eSAlberto Garciaecho
77*0f46147eSAlberto Garciaecho '### Write data to allocate more refcount blocks than the cache can hold'
78*0f46147eSAlberto Garciaecho
79*0f46147eSAlberto Garcia$QEMU_IO -c "write -P 1 0 $total_size" $TEST_IMG.base | _filter_qemu_io
80*0f46147eSAlberto Garcia
81*0f46147eSAlberto Garciaecho
82*0f46147eSAlberto Garciaecho '### Create an overlay'
83*0f46147eSAlberto Garciaecho
84*0f46147eSAlberto Garcia_make_test_img -F $IMGFMT -b $TEST_IMG.base -o $options | _filter_img_create_size
85*0f46147eSAlberto Garcia
86*0f46147eSAlberto Garciaecho
87*0f46147eSAlberto Garciaecho '### Fill the overlay with zeroes'
88*0f46147eSAlberto Garciaecho
89*0f46147eSAlberto Garcia$QEMU_IO -c "write -z 0 $total_size" $TEST_IMG | _filter_qemu_io
90*0f46147eSAlberto Garcia
91*0f46147eSAlberto Garciaecho
92*0f46147eSAlberto Garciaecho '### Commit changes to the base image'
93*0f46147eSAlberto Garciaecho
94*0f46147eSAlberto Garcia$QEMU_IMG commit $TEST_IMG
95*0f46147eSAlberto Garcia
96*0f46147eSAlberto Garciaecho
97*0f46147eSAlberto Garciaecho '### Check the base image'
98*0f46147eSAlberto Garciaecho
99*0f46147eSAlberto Garcia$QEMU_IMG check $TEST_IMG.base
100*0f46147eSAlberto Garcia
101*0f46147eSAlberto Garcia# success, all done
102*0f46147eSAlberto Garciaecho "*** done"
103*0f46147eSAlberto Garciarm -f $seq.full
104*0f46147eSAlberto Garciastatus=0
105