18268b767SStefan Hajnoczi#!/bin/bash 28268b767SStefan Hajnoczi# 38268b767SStefan Hajnoczi# Test that backing files can be smaller than the image 48268b767SStefan Hajnoczi# 58268b767SStefan Hajnoczi# Copyright (C) 2010 IBM, Corp. 68268b767SStefan Hajnoczi# 78268b767SStefan Hajnoczi# Based on 017: 88268b767SStefan Hajnoczi# Copyright (C) 2009 Red Hat, Inc. 98268b767SStefan Hajnoczi# 108268b767SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify 118268b767SStefan Hajnoczi# it under the terms of the GNU General Public License as published by 128268b767SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or 138268b767SStefan Hajnoczi# (at your option) any later version. 148268b767SStefan Hajnoczi# 158268b767SStefan Hajnoczi# This program is distributed in the hope that it will be useful, 168268b767SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of 178268b767SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 188268b767SStefan Hajnoczi# GNU General Public License for more details. 198268b767SStefan Hajnoczi# 208268b767SStefan Hajnoczi# You should have received a copy of the GNU General Public License 218268b767SStefan Hajnoczi# along with this program. If not, see <http://www.gnu.org/licenses/>. 228268b767SStefan Hajnoczi# 238268b767SStefan Hajnoczi 248268b767SStefan Hajnoczi# creator 258268b767SStefan Hajnocziowner=stefanha@linux.vnet.ibm.com 268268b767SStefan Hajnoczi 278268b767SStefan Hajnocziseq=`basename $0` 288268b767SStefan Hajnocziecho "QA output created by $seq" 298268b767SStefan Hajnoczi 308268b767SStefan Hajnoczihere=`pwd` 318268b767SStefan Hajnoczitmp=/tmp/$$ 328268b767SStefan Hajnoczistatus=1 # failure is the default! 338268b767SStefan Hajnoczi 348268b767SStefan Hajnoczi_cleanup() 358268b767SStefan Hajnoczi{ 36d40593ddSKevin Wolf rm -f "${TEST_IMG}.copy" 378268b767SStefan Hajnoczi _cleanup_test_img 388268b767SStefan Hajnoczi} 398268b767SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15 408268b767SStefan Hajnoczi 418268b767SStefan Hajnoczi# get standard environment, filters and checks 428268b767SStefan Hajnoczi. ./common.rc 438268b767SStefan Hajnoczi. ./common.filter 448268b767SStefan Hajnoczi. ./common.pattern 45d40593ddSKevin Wolf. ./common.qemu 468268b767SStefan Hajnoczi 478268b767SStefan Hajnoczi# Any format supporting backing files except vmdk and qcow which do not support 488268b767SStefan Hajnoczi# smaller backing files. 49f5a4bbd9SStefan Hajnoczi_supported_fmt qcow2 qed 501f7bf7d0SPeter Lieven_supported_proto file 518268b767SStefan Hajnoczi_supported_os Linux 528268b767SStefan Hajnoczi 538268b767SStefan Hajnoczi# Choose a size that is not necessarily a cluster size multiple for image 548268b767SStefan Hajnoczi# formats that use clusters. This will ensure that the base image doesn't end 558268b767SStefan Hajnoczi# precisely on a cluster boundary (the easy case). 568268b767SStefan Hajnocziimage_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 )) 578268b767SStefan Hajnoczi 588268b767SStefan Hajnoczi# The base image is smaller than the image file 598268b767SStefan Hajnoczibase_size=$(( image_size - 1024 * 1024 * 1024 )) 608268b767SStefan Hajnoczi 618268b767SStefan Hajnoczioffset=$(( base_size - 32 * 1024 )) 628268b767SStefan Hajnoczi 638268b767SStefan Hajnoczi_make_test_img $base_size 648268b767SStefan Hajnoczi 658268b767SStefan Hajnocziecho "Filling base image" 668268b767SStefan Hajnocziecho 678268b767SStefan Hajnoczi 688268b767SStefan Hajnoczi# Fill end of base image with a pattern, skipping every other sector 69dd0c35d6SStefan Hajnocziio writev $offset 512 1024 32 708268b767SStefan Hajnoczi 718268b767SStefan Hajnoczi_check_test_img 728268b767SStefan Hajnoczi 738268b767SStefan Hajnocziecho "Creating test image with backing file" 748268b767SStefan Hajnocziecho 758268b767SStefan Hajnoczi 76fef9c191SJeff Codymv "$TEST_IMG" "$TEST_IMG.base" 77fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" $image_size 788268b767SStefan Hajnoczi 798268b767SStefan Hajnocziecho "Filling test image" 808268b767SStefan Hajnocziecho 818268b767SStefan Hajnoczi 828268b767SStefan Hajnoczi# Write every other sector around where the base image ends 83dd0c35d6SStefan Hajnocziio writev $(( offset + 512 )) 512 1024 64 848268b767SStefan Hajnoczi 858268b767SStefan Hajnoczi_check_test_img 868268b767SStefan Hajnoczi 878268b767SStefan Hajnocziecho "Reading" 888268b767SStefan Hajnocziecho 898268b767SStefan Hajnoczi 908268b767SStefan Hajnoczi# Base image sectors 91dd0c35d6SStefan Hajnocziio readv $(( offset )) 512 1024 32 928268b767SStefan Hajnoczi 938268b767SStefan Hajnoczi# Image sectors 94dd0c35d6SStefan Hajnocziio readv $(( offset + 512 )) 512 1024 64 958268b767SStefan Hajnoczi 968268b767SStefan Hajnoczi# Zero sectors beyond end of base image 97dd0c35d6SStefan Hajnocziio_zero readv $(( offset + 32 * 1024 )) 512 1024 32 988268b767SStefan Hajnoczi 998268b767SStefan Hajnoczi_check_test_img 1008268b767SStefan Hajnoczi 1016ce2d77aSKevin Wolf# Rebase it on top of its base image 102fef9c191SJeff Cody$QEMU_IMG rebase -b "$TEST_IMG.base" "$TEST_IMG" 1036ce2d77aSKevin Wolf 104d40593ddSKevin Wolfecho 105d40593ddSKevin Wolfecho block-backup 106d40593ddSKevin Wolfecho 107d40593ddSKevin Wolf 108d40593ddSKevin Wolfqemu_comm_method="monitor" 109d40593ddSKevin Wolf_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},id=disk 110d40593ddSKevin Wolfh=$QEMU_HANDLE 111d40593ddSKevin WolfQEMU_COMM_TIMEOUT=1 112d40593ddSKevin Wolf 113*8283c5c3SStefan Hajnoczi# Silence output since it contains the disk image path and QEMU's readline 114*8283c5c3SStefan Hajnoczi# character echoing makes it very hard to filter the output 115*8283c5c3SStefan Hajnoczi_send_qemu_cmd $h "drive_backup disk ${TEST_IMG}.copy" "(qemu)" >/dev/null 116d40593ddSKevin Wolfqemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs" 117d40593ddSKevin Wolf_send_qemu_cmd $h 'quit' "" 118d40593ddSKevin Wolf 119d40593ddSKevin Wolf# Base image sectors 120d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32 121d40593ddSKevin Wolf 122d40593ddSKevin Wolf# Image sectors 123d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64 124d40593ddSKevin Wolf 125d40593ddSKevin Wolf# Zero sectors beyond end of base image 126d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32 127d40593ddSKevin Wolf 128d40593ddSKevin Wolf 1296ce2d77aSKevin Wolf_check_test_img 1306ce2d77aSKevin Wolf 1318268b767SStefan Hajnoczi# success, all done 1328268b767SStefan Hajnocziecho "*** done" 1338268b767SStefan Hajnoczirm -f $seq.full 1348268b767SStefan Hajnoczistatus=0 135