1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 2596f4f96SStefan Hajnoczi# 3596f4f96SStefan Hajnoczi# Resizing images 4596f4f96SStefan Hajnoczi# 5596f4f96SStefan Hajnoczi# Copyright (C) 2010 IBM, Corp. 6596f4f96SStefan Hajnoczi# 7596f4f96SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 8596f4f96SStefan Hajnoczi# it under the terms of the GNU General Public License as published by 9596f4f96SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 10596f4f96SStefan Hajnoczi# (at your option) any later version. 11596f4f96SStefan Hajnoczi# 12596f4f96SStefan Hajnoczi# This program is distributed in the hope that it will be useful, 13596f4f96SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 14596f4f96SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15596f4f96SStefan Hajnoczi# GNU General Public License for more details. 16596f4f96SStefan Hajnoczi# 17596f4f96SStefan Hajnoczi# You should have received a copy of the GNU General Public License 18596f4f96SStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 19596f4f96SStefan Hajnoczi# 20596f4f96SStefan Hajnoczi 21596f4f96SStefan Hajnoczi# creator 22596f4f96SStefan Hajnocziowner=stefanha@linux.vnet.ibm.com 23596f4f96SStefan Hajnoczi 24596f4f96SStefan Hajnocziseq=`basename $0` 25596f4f96SStefan Hajnocziecho "QA output created by $seq" 26596f4f96SStefan Hajnoczi 27596f4f96SStefan Hajnoczistatus=1 # failure is the default! 28596f4f96SStefan Hajnoczi 29596f4f96SStefan Hajnoczi_cleanup() 30596f4f96SStefan Hajnoczi{ 31596f4f96SStefan Hajnoczi _cleanup_test_img 32596f4f96SStefan Hajnoczi} 33596f4f96SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15 34596f4f96SStefan Hajnoczi 35596f4f96SStefan Hajnoczi# get standard environment, filters and checks 36596f4f96SStefan Hajnoczi. ./common.rc 37596f4f96SStefan Hajnoczi. ./common.filter 38596f4f96SStefan Hajnoczi. ./common.pattern 39596f4f96SStefan Hajnoczi 40633c175fSKevin Wolf_supported_fmt raw qcow2 qed luks 41e32ccbc6SEric Blake_supported_proto file sheepdog rbd nfs 42596f4f96SStefan Hajnoczi_supported_os Linux 43596f4f96SStefan Hajnoczi 44596f4f96SStefan Hajnocziecho "=== Creating image" 45596f4f96SStefan Hajnocziecho 46596f4f96SStefan Hajnoczismall_size=$((128 * 1024 * 1024)) 47596f4f96SStefan Hajnoczibig_size=$((384 * 1024 * 1024)) 48596f4f96SStefan Hajnoczi_make_test_img $small_size 49596f4f96SStefan Hajnoczi 50596f4f96SStefan Hajnocziecho 51596f4f96SStefan Hajnocziecho "=== Writing whole image" 52596f4f96SStefan Hajnocziio_pattern write 0 $small_size 0 1 0xc5 53596f4f96SStefan Hajnoczi_check_test_img 54596f4f96SStefan Hajnoczi 55596f4f96SStefan Hajnocziecho 56596f4f96SStefan Hajnocziecho "=== Resizing image" 570d83c98bSFam Zheng$QEMU_IO "$TEST_IMG" <<EOF | _filter_qemu_io 58596f4f96SStefan Hajnoczilength 59596f4f96SStefan Hajnoczitruncate $big_size 60596f4f96SStefan Hajnoczilength 61596f4f96SStefan HajnocziEOF 62596f4f96SStefan Hajnoczi_check_test_img 63596f4f96SStefan Hajnoczi 64633c175fSKevin Wolf# bdrv_truncate() doesn't zero the new space, so we need to do that explicitly. 65633c175fSKevin Wolf# We still want to test automatic zeroing for other formats even though 66633c175fSKevin Wolf# bdrv_truncate() doesn't guarantee it. 67633c175fSKevin Wolfif [ "$IMGFMT" == "luks" ]; then 68633c175fSKevin Wolf $QEMU_IO -c "write -z $small_size $((big_size - small_size))" "$TEST_IMG" > /dev/null 69633c175fSKevin Wolffi 70633c175fSKevin Wolf 71596f4f96SStefan Hajnocziecho 72596f4f96SStefan Hajnocziecho "=== Verifying image size after reopen" 73fef9c191SJeff Cody$QEMU_IO -c "length" "$TEST_IMG" 74596f4f96SStefan Hajnoczi 75596f4f96SStefan Hajnocziecho 76596f4f96SStefan Hajnocziecho "=== Verifying resized image" 77596f4f96SStefan Hajnocziio_pattern read 0 $small_size 0 1 0xc5 78596f4f96SStefan Hajnocziio_pattern read $small_size $(($big_size - $small_size)) 0 1 0 79596f4f96SStefan Hajnoczi 80596f4f96SStefan Hajnoczi# success, all done 81596f4f96SStefan Hajnocziecho "*** done" 82596f4f96SStefan Hajnoczirm -f $seq.full 83596f4f96SStefan Hajnoczistatus=0 84