xref: /openbmc/qemu/tests/qemu-iotests/270 (revision 64ed6f92)
1#!/usr/bin/env bash
2#
3# Test large write to a qcow2 image
4#
5# Copyright (C) 2019 Red Hat, Inc.
6#
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.
11#
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.
16#
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/>.
19#
20
21seq=$(basename "$0")
22echo "QA output created by $seq"
23
24status=1	# failure is the default!
25
26_cleanup()
27{
28    _cleanup_test_img
29}
30trap "_cleanup; exit \$status" 0 1 2 3 15
31
32# get standard environment, filters and checks
33. ./common.rc
34. ./common.filter
35
36# This is a qcow2 regression test
37_supported_fmt qcow2
38_supported_proto file
39_supported_os Linux
40
41# We use our own external data file and our own cluster size, and we
42# require v3 images
43_unsupported_imgopts data_file cluster_size 'compat=0.10'
44
45
46# We need a backing file so that handle_alloc_space() will not do
47# anything.  (If it were to do anything, it would simply fail its
48# write-zeroes request because the request range is too large.)
49TEST_IMG="$TEST_IMG.base" _make_test_img 4G
50$QEMU_IO -c 'write 0 512' "$TEST_IMG.base" | _filter_qemu_io
51
52# (Use .orig because _cleanup_test_img will remove that file)
53# We need a large cluster size, see below for why (above the $QEMU_IO
54# invocation)
55_make_test_img -o cluster_size=2M,data_file="$TEST_IMG.orig" \
56    -b "$TEST_IMG.base" -F $IMGFMT 4G
57
58# We want a null-co as the data file, because it allows us to quickly
59# "write" 2G of data without using any space.
60# (qemu-img create does not like it, though, because null-co does not
61# support image creation.)
62$QEMU_IMG amend -o data_file="json:{'driver':'null-co',,'size':'4294967296'}" \
63    "$TEST_IMG"
64
65# This gives us a range of:
66#   2^31 - 512 + 768 - 1 = 2^31 + 255 > 2^31
67# until the beginning of the end COW block.  (The total allocation
68# size depends on the cluster size, but all that is important is that
69# it exceeds INT_MAX.)
70#
71# 2^31 - 512 is the maximum request size.  We want this to result in a
72# single allocation, and because the qcow2 driver splits allocations
73# on L2 boundaries, we need large L2 tables; hence the cluster size of
74# 2 MB.  (Anything from 256 kB should work, though, because then one L2
75# table covers 8 GB.)
76$QEMU_IO -c "write 768 $((2 ** 31 - 512))" "$TEST_IMG" | _filter_qemu_io
77
78_check_test_img
79
80# success, all done
81echo "*** done"
82rm -f $seq.full
83status=0
84