111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto quick 3596f4f96SStefan Hajnoczi# 4596f4f96SStefan Hajnoczi# Resizing images 5596f4f96SStefan Hajnoczi# 6596f4f96SStefan Hajnoczi# Copyright (C) 2010 IBM, Corp. 7596f4f96SStefan Hajnoczi# 8596f4f96SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 9596f4f96SStefan Hajnoczi# it under the terms of the GNU General Public License as published by 10596f4f96SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 11596f4f96SStefan Hajnoczi# (at your option) any later version. 12596f4f96SStefan Hajnoczi# 13596f4f96SStefan Hajnoczi# This program is distributed in the hope that it will be useful, 14596f4f96SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 15596f4f96SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16596f4f96SStefan Hajnoczi# GNU General Public License for more details. 17596f4f96SStefan Hajnoczi# 18596f4f96SStefan Hajnoczi# You should have received a copy of the GNU General Public License 19596f4f96SStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 20596f4f96SStefan Hajnoczi# 21596f4f96SStefan Hajnoczi 22596f4f96SStefan Hajnoczi# creator 23*42a5009dSJohn Snowowner=stefanha@redhat.com 24596f4f96SStefan Hajnoczi 25596f4f96SStefan Hajnocziseq=`basename $0` 26596f4f96SStefan Hajnocziecho "QA output created by $seq" 27596f4f96SStefan Hajnoczi 28596f4f96SStefan Hajnoczistatus=1 # failure is the default! 29596f4f96SStefan Hajnoczi 30596f4f96SStefan Hajnoczi_cleanup() 31596f4f96SStefan Hajnoczi{ 32596f4f96SStefan Hajnoczi _cleanup_test_img 33596f4f96SStefan Hajnoczi} 34596f4f96SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15 35596f4f96SStefan Hajnoczi 36596f4f96SStefan Hajnoczi# get standard environment, filters and checks 37596f4f96SStefan Hajnoczi. ./common.rc 38596f4f96SStefan Hajnoczi. ./common.filter 39596f4f96SStefan Hajnoczi. ./common.pattern 40596f4f96SStefan Hajnoczi 41633c175fSKevin Wolf_supported_fmt raw qcow2 qed luks 4209ec8517SMarkus Armbruster_supported_proto file rbd nfs fuse 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