1e4d7019eSAlberto Garcia#!/usr/bin/env bash 2e4d7019eSAlberto Garcia# 3e4d7019eSAlberto Garcia# Test resizing a qcow2 image with a backing file 4e4d7019eSAlberto Garcia# 5e4d7019eSAlberto Garcia# Copyright (C) 2020 Igalia, S.L. 6e4d7019eSAlberto Garcia# Author: Alberto Garcia <berto@igalia.com> 7e4d7019eSAlberto Garcia# 8e4d7019eSAlberto Garcia# This program is free software; you can redistribute it and/or modify 9e4d7019eSAlberto Garcia# it under the terms of the GNU General Public License as published by 10e4d7019eSAlberto Garcia# the Free Software Foundation; either version 2 of the License, or 11e4d7019eSAlberto Garcia# (at your option) any later version. 12e4d7019eSAlberto Garcia# 13e4d7019eSAlberto Garcia# This program is distributed in the hope that it will be useful, 14e4d7019eSAlberto Garcia# but WITHOUT ANY WARRANTY; without even the implied warranty of 15e4d7019eSAlberto Garcia# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16e4d7019eSAlberto Garcia# GNU General Public License for more details. 17e4d7019eSAlberto Garcia# 18e4d7019eSAlberto Garcia# You should have received a copy of the GNU General Public License 19e4d7019eSAlberto Garcia# along with this program. If not, see <http://www.gnu.org/licenses/>. 20e4d7019eSAlberto Garcia# 21e4d7019eSAlberto Garcia 22e4d7019eSAlberto Garcia# creator 23e4d7019eSAlberto Garciaowner=berto@igalia.com 24e4d7019eSAlberto Garcia 25e4d7019eSAlberto Garciaseq=`basename $0` 26e4d7019eSAlberto Garciaecho "QA output created by $seq" 27e4d7019eSAlberto Garcia 28e4d7019eSAlberto Garciastatus=1 # failure is the default! 29e4d7019eSAlberto Garcia 30e4d7019eSAlberto Garcia_cleanup() 31e4d7019eSAlberto Garcia{ 32e4d7019eSAlberto Garcia _cleanup_test_img 33e4d7019eSAlberto Garcia} 34e4d7019eSAlberto Garciatrap "_cleanup; exit \$status" 0 1 2 3 15 35e4d7019eSAlberto Garcia 36e4d7019eSAlberto Garcia# get standard environment, filters and checks 37e4d7019eSAlberto Garcia. ./common.rc 38e4d7019eSAlberto Garcia. ./common.filter 39e4d7019eSAlberto Garcia 40e4d7019eSAlberto Garcia_supported_fmt qcow2 41*57284d2aSMax Reitz_supported_proto file fuse 42e4d7019eSAlberto Garcia_supported_os Linux 43e6de31bcSMax Reitz# We need qemu-img map to show the file where the data is allocated, 44e6de31bcSMax Reitz# but with an external data file, it will show that instead of the 45e6de31bcSMax Reitz# file we want to check. So just skip this test for external data 46e6de31bcSMax Reitz# files. 47e6de31bcSMax Reitz_unsupported_imgopts data_file 48e4d7019eSAlberto Garcia 49e4d7019eSAlberto Garciaecho '### Create the backing image' 50e4d7019eSAlberto GarciaBACKING_IMG="$TEST_IMG.base" 51e4d7019eSAlberto GarciaTEST_IMG="$BACKING_IMG" _make_test_img 1M 52e4d7019eSAlberto Garcia 53e4d7019eSAlberto Garciaecho '### Fill the backing image with data (0x11)' 54e4d7019eSAlberto Garcia$QEMU_IO -c 'write -P 0x11 0 1M' "$BACKING_IMG" | _filter_qemu_io 55e4d7019eSAlberto Garcia 56e4d7019eSAlberto Garciaecho '### Create the top image' 57e4d7019eSAlberto Garcia_make_test_img -F "$IMGFMT" -b "$BACKING_IMG" 58e4d7019eSAlberto Garcia 59e4d7019eSAlberto Garciaecho '### Fill the top image with data (0x22)' 60e4d7019eSAlberto Garcia$QEMU_IO -c 'write -P 0x22 0 1M' "$TEST_IMG" | _filter_qemu_io 61e4d7019eSAlberto Garcia 62e4d7019eSAlberto Garcia# Both offsets are part of the same cluster. 63e4d7019eSAlberto Garciaecho '### Shrink the image to 520k' 64e4d7019eSAlberto Garcia$QEMU_IMG resize --shrink "$TEST_IMG" 520k 65e4d7019eSAlberto Garciaecho '### Grow the image to 567k' 66e4d7019eSAlberto Garcia$QEMU_IMG resize "$TEST_IMG" 567k 67e4d7019eSAlberto Garcia 68e4d7019eSAlberto Garciaecho '### Check that the tail of the image reads as zeroes' 69e4d7019eSAlberto Garcia$QEMU_IO -c 'read -P 0x22 0 520k' "$TEST_IMG" | _filter_qemu_io 70e4d7019eSAlberto Garcia$QEMU_IO -c 'read -P 0x00 520k 47k' "$TEST_IMG" | _filter_qemu_io 71e4d7019eSAlberto Garcia 72e4d7019eSAlberto Garciaecho '### Show output of qemu-img map' 73e4d7019eSAlberto Garcia$QEMU_IMG map "$TEST_IMG" | _filter_testdir 74e4d7019eSAlberto Garcia 75e4d7019eSAlberto Garcia# success, all done 76e4d7019eSAlberto Garciaecho "*** done" 77e4d7019eSAlberto Garciarm -f $seq.full 78e4d7019eSAlberto Garciastatus=0 79