1#!/usr/bin/env 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 30status=1 # failure is the default! 31 32_cleanup() 33{ 34 _cleanup_qemu 35 _rm_test_img "${TEST_IMG}.copy" 36 _cleanup_test_img 37} 38trap "_cleanup; exit \$status" 0 1 2 3 15 39 40# get standard environment, filters and checks 41. ./common.rc 42. ./common.filter 43. ./common.pattern 44. ./common.qemu 45 46# Any format supporting backing files except vmdk and qcow which do not support 47# smaller backing files. 48_supported_fmt qcow2 qed 49_supported_proto file fuse 50_supported_os Linux 51 52# Choose a size that is not necessarily a cluster size multiple for image 53# formats that use clusters. This will ensure that the base image doesn't end 54# precisely on a cluster boundary (the easy case). 55image_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 )) 56 57# The base image is smaller than the image file 58base_size=$(( image_size - 1024 * 1024 * 1024 )) 59 60offset=$(( base_size - 32 * 1024 )) 61 62TEST_IMG_SAVE="$TEST_IMG" 63TEST_IMG="$TEST_IMG.base" 64 65_make_test_img $base_size 66 67echo "Filling base image" 68echo 69 70# Fill end of base image with a pattern, skipping every other sector 71io writev $offset 512 1024 32 72 73_check_test_img 74 75echo "Creating test image with backing file" 76echo 77 78TEST_IMG="$TEST_IMG_SAVE" 79_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size 80 81echo "Filling test image" 82echo 83 84# Write every other sector around where the base image ends 85io writev $(( offset + 512 )) 512 1024 64 86 87_check_test_img 88 89echo "Reading" 90echo 91 92# Base image sectors 93io readv $(( offset )) 512 1024 32 94 95# Image sectors 96io readv $(( offset + 512 )) 512 1024 64 97 98# Zero sectors beyond end of base image 99io_zero readv $(( offset + 32 * 1024 )) 512 1024 32 100 101_check_test_img 102 103# Rebase it on top of its base image 104$QEMU_IMG rebase -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG" 105 106echo 107echo block-backup 108echo 109 110qemu_comm_method="monitor" 111_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=${AIOMODE},id=disk 112h=$QEMU_HANDLE 113if [ "${VALGRIND_QEMU}" == "y" ]; then 114 QEMU_COMM_TIMEOUT=7 115else 116 QEMU_COMM_TIMEOUT=1 117fi 118 119TEST_IMG="$TEST_IMG.copy" _make_test_img $image_size 120_send_qemu_cmd $h "drive_backup -n disk ${TEST_IMG}.copy" "(qemu)" \ 121 | _filter_imgfmt 122 123silent=y qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs" 124_send_qemu_cmd $h "info block-jobs" "No active jobs" 125_send_qemu_cmd $h 'quit' "" 126 127# Base image sectors 128TEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32 129 130# Image sectors 131TEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64 132 133# Zero sectors beyond end of base image 134TEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32 135 136 137_check_test_img 138 139echo 140echo '=== Reading across backing EOF in one operation ===' 141echo 142 143# Use a cluster boundary as the base end here 144base_size=$((3 * 1024 * 1024 * 1024)) 145 146TEST_IMG="$TEST_IMG.base" _make_test_img $base_size 147_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size 148 149# Write 16 times 42 at the end of the base image 150$QEMU_IO -c "write -P 42 $((base_size - 16)) 16" "$TEST_IMG.base" \ 151 | _filter_qemu_io 152 153# Read 32 bytes across the base EOF from the top; 154# should be 16 times 0x2a, then 16 times 0x00 155$QEMU_IO -c "read -v $((base_size - 16)) 32" "$TEST_IMG" \ 156 | _filter_qemu_io 157 158# success, all done 159echo "*** done" 160rm -f $seq.full 161status=0 162