xref: /openbmc/qemu/tests/qemu-iotests/028 (revision 49557d65)
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
63*49557d65SFam ZhengTEST_IMG_SAVE="$TEST_IMG"
64*49557d65SFam ZhengTEST_IMG="$TEST_IMG.base"
65*49557d65SFam Zheng
668268b767SStefan Hajnoczi_make_test_img $base_size
678268b767SStefan Hajnoczi
688268b767SStefan Hajnocziecho "Filling base image"
698268b767SStefan Hajnocziecho
708268b767SStefan Hajnoczi
718268b767SStefan Hajnoczi# Fill end of base image with a pattern, skipping every other sector
72dd0c35d6SStefan Hajnocziio writev $offset 512 1024 32
738268b767SStefan Hajnoczi
748268b767SStefan Hajnoczi_check_test_img
758268b767SStefan Hajnoczi
768268b767SStefan Hajnocziecho "Creating test image with backing file"
778268b767SStefan Hajnocziecho
788268b767SStefan Hajnoczi
79*49557d65SFam ZhengTEST_IMG="$TEST_IMG_SAVE"
80fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" $image_size
818268b767SStefan Hajnoczi
828268b767SStefan Hajnocziecho "Filling test image"
838268b767SStefan Hajnocziecho
848268b767SStefan Hajnoczi
858268b767SStefan Hajnoczi# Write every other sector around where the base image ends
86dd0c35d6SStefan Hajnocziio writev $(( offset + 512 )) 512 1024 64
878268b767SStefan Hajnoczi
888268b767SStefan Hajnoczi_check_test_img
898268b767SStefan Hajnoczi
908268b767SStefan Hajnocziecho "Reading"
918268b767SStefan Hajnocziecho
928268b767SStefan Hajnoczi
938268b767SStefan Hajnoczi# Base image sectors
94dd0c35d6SStefan Hajnocziio readv $(( offset )) 512 1024 32
958268b767SStefan Hajnoczi
968268b767SStefan Hajnoczi# Image sectors
97dd0c35d6SStefan Hajnocziio readv $(( offset + 512 )) 512 1024 64
988268b767SStefan Hajnoczi
998268b767SStefan Hajnoczi# Zero sectors beyond end of base image
100dd0c35d6SStefan Hajnocziio_zero readv $(( offset + 32 * 1024 )) 512 1024 32
1018268b767SStefan Hajnoczi
1028268b767SStefan Hajnoczi_check_test_img
1038268b767SStefan Hajnoczi
1046ce2d77aSKevin Wolf# Rebase it on top of its base image
105fef9c191SJeff Cody$QEMU_IMG rebase -b "$TEST_IMG.base" "$TEST_IMG"
1066ce2d77aSKevin Wolf
107d40593ddSKevin Wolfecho
108d40593ddSKevin Wolfecho block-backup
109d40593ddSKevin Wolfecho
110d40593ddSKevin Wolf
111d40593ddSKevin Wolfqemu_comm_method="monitor"
112d40593ddSKevin Wolf_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},id=disk
113d40593ddSKevin Wolfh=$QEMU_HANDLE
114d40593ddSKevin WolfQEMU_COMM_TIMEOUT=1
115d40593ddSKevin Wolf
1168283c5c3SStefan Hajnoczi# Silence output since it contains the disk image path and QEMU's readline
1178283c5c3SStefan Hajnoczi# character echoing makes it very hard to filter the output
1188283c5c3SStefan Hajnoczi_send_qemu_cmd $h "drive_backup disk ${TEST_IMG}.copy" "(qemu)" >/dev/null
1196ffb4cb6SKevin Wolf_send_qemu_cmd $h "" "Formatting" | _filter_img_create
120d40593ddSKevin Wolfqemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs"
121d40593ddSKevin Wolf_send_qemu_cmd $h 'quit' ""
122d40593ddSKevin Wolf
123d40593ddSKevin Wolf# Base image sectors
124d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32
125d40593ddSKevin Wolf
126d40593ddSKevin Wolf# Image sectors
127d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64
128d40593ddSKevin Wolf
129d40593ddSKevin Wolf# Zero sectors beyond end of base image
130d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32
131d40593ddSKevin Wolf
132d40593ddSKevin Wolf
1336ce2d77aSKevin Wolf_check_test_img
1346ce2d77aSKevin Wolf
1358268b767SStefan Hajnoczi# success, all done
1368268b767SStefan Hajnocziecho "*** done"
1378268b767SStefan Hajnoczirm -f $seq.full
1388268b767SStefan Hajnoczistatus=0
139