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