1*b7cd2c11SMax Reitz#!/usr/bin/env bash 2*b7cd2c11SMax Reitz# 3*b7cd2c11SMax Reitz# Test compressed write to a qcow2 image at an offset above 4 GB 4*b7cd2c11SMax Reitz# 5*b7cd2c11SMax Reitz# Copyright (C) 2019 Red Hat, Inc. 6*b7cd2c11SMax Reitz# 7*b7cd2c11SMax Reitz# This program is free software; you can redistribute it and/or modify 8*b7cd2c11SMax Reitz# it under the terms of the GNU General Public License as published by 9*b7cd2c11SMax Reitz# the Free Software Foundation; either version 2 of the License, or 10*b7cd2c11SMax Reitz# (at your option) any later version. 11*b7cd2c11SMax Reitz# 12*b7cd2c11SMax Reitz# This program is distributed in the hope that it will be useful, 13*b7cd2c11SMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14*b7cd2c11SMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*b7cd2c11SMax Reitz# GNU General Public License for more details. 16*b7cd2c11SMax Reitz# 17*b7cd2c11SMax Reitz# You should have received a copy of the GNU General Public License 18*b7cd2c11SMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19*b7cd2c11SMax Reitz# 20*b7cd2c11SMax Reitz 21*b7cd2c11SMax Reitzseq=$(basename "$0") 22*b7cd2c11SMax Reitzecho "QA output created by $seq" 23*b7cd2c11SMax Reitz 24*b7cd2c11SMax Reitzstatus=1 # failure is the default! 25*b7cd2c11SMax Reitz 26*b7cd2c11SMax Reitz_cleanup() 27*b7cd2c11SMax Reitz{ 28*b7cd2c11SMax Reitz _cleanup_test_img 29*b7cd2c11SMax Reitz} 30*b7cd2c11SMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 31*b7cd2c11SMax Reitz 32*b7cd2c11SMax Reitz# get standard environment, filters and checks 33*b7cd2c11SMax Reitz. ./common.rc 34*b7cd2c11SMax Reitz. ./common.filter 35*b7cd2c11SMax Reitz 36*b7cd2c11SMax Reitz# This is a qcow2 regression test 37*b7cd2c11SMax Reitz_supported_fmt qcow2 38*b7cd2c11SMax Reitz_supported_proto file 39*b7cd2c11SMax Reitz 40*b7cd2c11SMax Reitz# External data files do not support compression; 41*b7cd2c11SMax Reitz# We need an exact cluster size (2M) and refcount width (2) so we can 42*b7cd2c11SMax Reitz# get this test quickly over with; and this in turn require 43*b7cd2c11SMax Reitz# compat=1.1 44*b7cd2c11SMax Reitz_unsupported_imgopts data_file cluster_size refcount_bits 'compat=0.10' 45*b7cd2c11SMax Reitz 46*b7cd2c11SMax Reitz# The idea is: Create an empty file, mark the first 4 GB as used, then 47*b7cd2c11SMax Reitz# do a compressed write that thus must be put beyond 4 GB. 48*b7cd2c11SMax Reitz# (This used to fail because the compressed sector mask was just a 49*b7cd2c11SMax Reitz# 32 bit mask, so qemu-img check will count a cluster before 4 GB as 50*b7cd2c11SMax Reitz# referenced twice.) 51*b7cd2c11SMax Reitz 52*b7cd2c11SMax Reitz# We would like to use refcount_bits=1 here, but then qemu-img check 53*b7cd2c11SMax Reitz# will throw an error when trying to count a cluster as referenced 54*b7cd2c11SMax Reitz# twice. 55*b7cd2c11SMax Reitz_make_test_img -o cluster_size=2M,refcount_bits=2 64M 56*b7cd2c11SMax Reitz 57*b7cd2c11SMax Reitzreft_offs=$(peek_file_be "$TEST_IMG" 48 8) 58*b7cd2c11SMax Reitzrefb_offs=$(peek_file_be "$TEST_IMG" $reft_offs 8) 59*b7cd2c11SMax Reitz 60*b7cd2c11SMax Reitz# We want to cover 4 GB, those are 2048 clusters, equivalent to 61*b7cd2c11SMax Reitz# 4096 bit = 512 B. 62*b7cd2c11SMax Reitztruncate -s 4G "$TEST_IMG" 63*b7cd2c11SMax Reitzfor ((in_refb_offs = 0; in_refb_offs < 512; in_refb_offs += 8)); do 64*b7cd2c11SMax Reitz poke_file "$TEST_IMG" $((refb_offs + in_refb_offs)) \ 65*b7cd2c11SMax Reitz '\x55\x55\x55\x55\x55\x55\x55\x55' 66*b7cd2c11SMax Reitzdone 67*b7cd2c11SMax Reitz 68*b7cd2c11SMax Reitz$QEMU_IO -c 'write -c -P 42 0 2M' "$TEST_IMG" | _filter_qemu_io 69*b7cd2c11SMax Reitz 70*b7cd2c11SMax Reitzecho 71*b7cd2c11SMax Reitzecho '--- Check ---' 72*b7cd2c11SMax Reitz 73*b7cd2c11SMax Reitz# This should only print the leaked clusters in the first 4 GB 74*b7cd2c11SMax Reitz_check_test_img | grep -v '^Leaked cluster ' 75*b7cd2c11SMax Reitz 76*b7cd2c11SMax Reitz# success, all done 77*b7cd2c11SMax Reitzecho "*** done" 78*b7cd2c11SMax Reitzrm -f $seq.full 79*b7cd2c11SMax Reitzstatus=0 80