1a1406a92SMax Reitz#!/usr/bin/env bash 29dd003a9SVladimir 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.) 63*7e111066SKevin Wolftest_img_with_null_data="json:{ 64*7e111066SKevin Wolf 'driver': '$IMGFMT', 65*7e111066SKevin Wolf 'file': { 66*7e111066SKevin Wolf 'filename': '$TEST_IMG' 67*7e111066SKevin Wolf }, 68*7e111066SKevin Wolf 'data-file': { 69*7e111066SKevin Wolf 'driver': 'null-co', 70*7e111066SKevin Wolf 'size':'4294967296' 71*7e111066SKevin Wolf } 72*7e111066SKevin Wolf}" 73a1406a92SMax Reitz 74a1406a92SMax Reitz# This gives us a range of: 75a1406a92SMax Reitz# 2^31 - 512 + 768 - 1 = 2^31 + 255 > 2^31 76a1406a92SMax Reitz# until the beginning of the end COW block. (The total allocation 77a1406a92SMax Reitz# size depends on the cluster size, but all that is important is that 78a1406a92SMax Reitz# it exceeds INT_MAX.) 79a1406a92SMax Reitz# 80a1406a92SMax Reitz# 2^31 - 512 is the maximum request size. We want this to result in a 81a1406a92SMax Reitz# single allocation, and because the qcow2 driver splits allocations 82a1406a92SMax Reitz# on L2 boundaries, we need large L2 tables; hence the cluster size of 83a1406a92SMax Reitz# 2 MB. (Anything from 256 kB should work, though, because then one L2 84a1406a92SMax Reitz# table covers 8 GB.) 85*7e111066SKevin Wolf$QEMU_IO -c "write 768 $((2 ** 31 - 512))" "$test_img_with_null_data" | _filter_qemu_io 86a1406a92SMax Reitz 87a1406a92SMax Reitz_check_test_img 88a1406a92SMax Reitz 89a1406a92SMax Reitz# success, all done 90a1406a92SMax Reitzecho "*** done" 91a1406a92SMax Reitzrm -f $seq.full 92a1406a92SMax Reitzstatus=0 93