1#!/bin/bash 2# 3# Test that backing files can be smaller than the image 4# 5# Copyright (C) 2010 IBM, Corp. 6# 7# Based on 017: 8# Copyright (C) 2009 Red Hat, Inc. 9# 10# This program is free software; you can redistribute it and/or modify 11# it under the terms of the GNU General Public License as published by 12# the Free Software Foundation; either version 2 of the License, or 13# (at your option) any later version. 14# 15# This program is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU General Public License for more details. 19# 20# You should have received a copy of the GNU General Public License 21# along with this program. If not, see <http://www.gnu.org/licenses/>. 22# 23 24# creator 25owner=stefanha@linux.vnet.ibm.com 26 27seq=`basename $0` 28echo "QA output created by $seq" 29 30here=`pwd` 31tmp=/tmp/$$ 32status=1 # failure is the default! 33 34_cleanup() 35{ 36 rm -f "${TEST_IMG}.copy" 37 _cleanup_test_img 38} 39trap "_cleanup; exit \$status" 0 1 2 3 15 40 41# get standard environment, filters and checks 42. ./common.rc 43. ./common.filter 44. ./common.pattern 45. ./common.qemu 46 47# Any format supporting backing files except vmdk and qcow which do not support 48# smaller backing files. 49_supported_fmt qcow2 qed 50_supported_proto file 51_supported_os Linux 52 53# Choose a size that is not necessarily a cluster size multiple for image 54# formats that use clusters. This will ensure that the base image doesn't end 55# precisely on a cluster boundary (the easy case). 56image_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 )) 57 58# The base image is smaller than the image file 59base_size=$(( image_size - 1024 * 1024 * 1024 )) 60 61offset=$(( base_size - 32 * 1024 )) 62 63_make_test_img $base_size 64 65echo "Filling base image" 66echo 67 68# Fill end of base image with a pattern, skipping every other sector 69io writev $offset 512 1024 32 70 71_check_test_img 72 73echo "Creating test image with backing file" 74echo 75 76mv "$TEST_IMG" "$TEST_IMG.base" 77_make_test_img -b "$TEST_IMG.base" $image_size 78 79echo "Filling test image" 80echo 81 82# Write every other sector around where the base image ends 83io writev $(( offset + 512 )) 512 1024 64 84 85_check_test_img 86 87echo "Reading" 88echo 89 90# Base image sectors 91io readv $(( offset )) 512 1024 32 92 93# Image sectors 94io readv $(( offset + 512 )) 512 1024 64 95 96# Zero sectors beyond end of base image 97io_zero readv $(( offset + 32 * 1024 )) 512 1024 32 98 99_check_test_img 100 101# Rebase it on top of its base image 102$QEMU_IMG rebase -b "$TEST_IMG.base" "$TEST_IMG" 103 104echo 105echo block-backup 106echo 107 108qemu_comm_method="monitor" 109_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},id=disk 110h=$QEMU_HANDLE 111QEMU_COMM_TIMEOUT=1 112 113# Silence output since it contains the disk image path and QEMU's readline 114# character echoing makes it very hard to filter the output 115_send_qemu_cmd $h "drive_backup disk ${TEST_IMG}.copy" "(qemu)" >/dev/null 116qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs" 117_send_qemu_cmd $h 'quit' "" 118 119# Base image sectors 120TEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32 121 122# Image sectors 123TEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64 124 125# Zero sectors beyond end of base image 126TEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32 127 128 129_check_test_img 130 131# success, all done 132echo "*** done" 133rm -f $seq.full 134status=0 135