111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2097b500cSMax Reitz# 3097b500cSMax Reitz# General test case for qcow2's image check 4097b500cSMax Reitz# 5097b500cSMax Reitz# Copyright (C) 2015 Red Hat, Inc. 6097b500cSMax Reitz# 7097b500cSMax Reitz# This program is free software; you can redistribute it and/or modify 8097b500cSMax Reitz# it under the terms of the GNU General Public License as published by 9097b500cSMax Reitz# the Free Software Foundation; either version 2 of the License, or 10097b500cSMax Reitz# (at your option) any later version. 11097b500cSMax Reitz# 12097b500cSMax Reitz# This program is distributed in the hope that it will be useful, 13097b500cSMax Reitz# but WITHOUT ANY WARRANTY; without even the implied warranty of 14097b500cSMax Reitz# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15097b500cSMax Reitz# GNU General Public License for more details. 16097b500cSMax Reitz# 17097b500cSMax Reitz# You should have received a copy of the GNU General Public License 18097b500cSMax Reitz# along with this program. If not, see <http://www.gnu.org/licenses/>. 19097b500cSMax Reitz# 20097b500cSMax Reitz 21097b500cSMax Reitz# creator 22097b500cSMax Reitzowner=mreitz@redhat.com 23097b500cSMax Reitz 24097b500cSMax Reitzseq="$(basename $0)" 25097b500cSMax Reitzecho "QA output created by $seq" 26097b500cSMax Reitz 27097b500cSMax Reitzstatus=1 # failure is the default! 28097b500cSMax Reitz 29097b500cSMax Reitz_cleanup() 30097b500cSMax Reitz{ 31097b500cSMax Reitz _cleanup_test_img 32097b500cSMax Reitz} 33097b500cSMax Reitztrap "_cleanup; exit \$status" 0 1 2 3 15 34097b500cSMax Reitz 35097b500cSMax Reitz# get standard environment, filters and checks 36097b500cSMax Reitz. ./common.rc 37097b500cSMax Reitz. ./common.filter 38097b500cSMax Reitz 39e696f335SMax Reitz# This tests qcow2-specific low-level functionality 40097b500cSMax Reitz_supported_fmt qcow2 41097b500cSMax Reitz_supported_proto file 42097b500cSMax Reitz_supported_os Linux 43*3be2024aSMax Reitz# With an external data file, data clusters are not refcounted 44*3be2024aSMax Reitz# (and so qemu-img check does not check their refcount) 45*3be2024aSMax Reitz_unsupported_imgopts data_file 46097b500cSMax Reitz 47097b500cSMax Reitzecho 48097b500cSMax Reitzecho '=== Check on an image with a multiple of 2^32 clusters ===' 49097b500cSMax Reitzecho 50097b500cSMax Reitz 51407fb56aSMax Reitz_make_test_img -o "cluster_size=512" 512 52097b500cSMax Reitz 53097b500cSMax Reitz# Allocate L2 table 54097b500cSMax Reitz$QEMU_IO -c 'write 0 512' "$TEST_IMG" | _filter_qemu_io 55097b500cSMax Reitz 56097b500cSMax Reitz# Put the data cluster at a multiple of 2 TB, resulting in the image apparently 57097b500cSMax Reitz# having a multiple of 2^32 clusters 58097b500cSMax Reitz# (To be more specific: It is at 32 PB) 59a5fff8d4SVladimir Sementsov-Ogievskiypoke_file "$TEST_IMG" $((2048 + 8)) "\x00\x80\x00\x00\x00\x00\x00\x00" 60097b500cSMax Reitz 61097b500cSMax Reitz# An offset of 32 PB results in qemu-img check having to allocate an in-memory 62a5fff8d4SVladimir Sementsov-Ogievskiy# refcount table of 128 TB (16 bit refcounts, 512 byte clusters), if qemu-img 63a5fff8d4SVladimir Sementsov-Ogievskiy# don't check that referenced data cluster is far beyond the end of file. 64a5fff8d4SVladimir Sementsov-Ogievskiy# But starting from 4.0, qemu-img does this check, and instead of "Cannot 65a5fff8d4SVladimir Sementsov-Ogievskiy# allocate memory", we have an error showing that l2 entry is invalid. 66097b500cSMax Reitz_check_test_img 67097b500cSMax Reitz 68097b500cSMax Reitz# success, all done 69097b500cSMax Reitzecho "*** done" 70097b500cSMax Reitzrm -f $seq.full 71097b500cSMax Reitzstatus=0 72