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