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