xref: /openbmc/qemu/tests/qemu-iotests/270 (revision 9dd003a99842d1d82c336e45c5cce656149de382)
1a1406a92SMax Reitz#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw backing quick
3a1406a92SMax Reitz#
4a1406a92SMax Reitz# Test large write to a qcow2 image
5a1406a92SMax Reitz#
6a1406a92SMax Reitz# Copyright (C) 2019 Red Hat, Inc.
7a1406a92SMax Reitz#
8a1406a92SMax Reitz# This program is free software; you can redistribute it and/or modify
9a1406a92SMax Reitz# it under the terms of the GNU General Public License as published by
10a1406a92SMax Reitz# the Free Software Foundation; either version 2 of the License, or
11a1406a92SMax Reitz# (at your option) any later version.
12a1406a92SMax Reitz#
13a1406a92SMax Reitz# This program is distributed in the hope that it will be useful,
14a1406a92SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of
15a1406a92SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16a1406a92SMax Reitz# GNU General Public License for more details.
17a1406a92SMax Reitz#
18a1406a92SMax Reitz# You should have received a copy of the GNU General Public License
19a1406a92SMax Reitz# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20a1406a92SMax Reitz#
21a1406a92SMax Reitz
22a1406a92SMax Reitzseq=$(basename "$0")
23a1406a92SMax Reitzecho "QA output created by $seq"
24a1406a92SMax Reitz
25a1406a92SMax Reitzstatus=1	# failure is the default!
26a1406a92SMax Reitz
27a1406a92SMax Reitz_cleanup()
28a1406a92SMax Reitz{
29a1406a92SMax Reitz    _cleanup_test_img
30a1406a92SMax Reitz}
31a1406a92SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15
32a1406a92SMax Reitz
33a1406a92SMax Reitz# get standard environment, filters and checks
34a1406a92SMax Reitz. ./common.rc
35a1406a92SMax Reitz. ./common.filter
36a1406a92SMax Reitz
37a1406a92SMax Reitz# This is a qcow2 regression test
38a1406a92SMax Reitz_supported_fmt qcow2
39a1406a92SMax Reitz_supported_proto file
40a1406a92SMax Reitz_supported_os Linux
41a1406a92SMax Reitz
42a1406a92SMax Reitz# We use our own external data file and our own cluster size, and we
43a1406a92SMax Reitz# require v3 images
44a1406a92SMax Reitz_unsupported_imgopts data_file cluster_size 'compat=0.10'
45a1406a92SMax Reitz
46a1406a92SMax Reitz
47a1406a92SMax Reitz# We need a backing file so that handle_alloc_space() will not do
48a1406a92SMax Reitz# anything.  (If it were to do anything, it would simply fail its
49a1406a92SMax Reitz# write-zeroes request because the request range is too large.)
50a1406a92SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img 4G
51a1406a92SMax Reitz$QEMU_IO -c 'write 0 512' "$TEST_IMG.base" | _filter_qemu_io
52a1406a92SMax Reitz
53a1406a92SMax Reitz# (Use .orig because _cleanup_test_img will remove that file)
54a1406a92SMax Reitz# We need a large cluster size, see below for why (above the $QEMU_IO
55a1406a92SMax Reitz# invocation)
56a1406a92SMax Reitz_make_test_img -o cluster_size=2M,data_file="$TEST_IMG.orig" \
57b66ff2c2SEric Blake    -b "$TEST_IMG.base" -F $IMGFMT 4G
58a1406a92SMax Reitz
59a1406a92SMax Reitz# We want a null-co as the data file, because it allows us to quickly
60a1406a92SMax Reitz# "write" 2G of data without using any space.
61a1406a92SMax Reitz# (qemu-img create does not like it, though, because null-co does not
62a1406a92SMax Reitz# support image creation.)
63a1406a92SMax Reitz$QEMU_IMG amend -o data_file="json:{'driver':'null-co',,'size':'4294967296'}" \
64a1406a92SMax Reitz    "$TEST_IMG"
65a1406a92SMax Reitz
66a1406a92SMax Reitz# This gives us a range of:
67a1406a92SMax Reitz#   2^31 - 512 + 768 - 1 = 2^31 + 255 > 2^31
68a1406a92SMax Reitz# until the beginning of the end COW block.  (The total allocation
69a1406a92SMax Reitz# size depends on the cluster size, but all that is important is that
70a1406a92SMax Reitz# it exceeds INT_MAX.)
71a1406a92SMax Reitz#
72a1406a92SMax Reitz# 2^31 - 512 is the maximum request size.  We want this to result in a
73a1406a92SMax Reitz# single allocation, and because the qcow2 driver splits allocations
74a1406a92SMax Reitz# on L2 boundaries, we need large L2 tables; hence the cluster size of
75a1406a92SMax Reitz# 2 MB.  (Anything from 256 kB should work, though, because then one L2
76a1406a92SMax Reitz# table covers 8 GB.)
77a1406a92SMax Reitz$QEMU_IO -c "write 768 $((2 ** 31 - 512))" "$TEST_IMG" | _filter_qemu_io
78a1406a92SMax Reitz
79a1406a92SMax Reitz_check_test_img
80a1406a92SMax Reitz
81a1406a92SMax Reitz# success, all done
82a1406a92SMax Reitzecho "*** done"
83a1406a92SMax Reitzrm -f $seq.full
84a1406a92SMax Reitzstatus=0
85