xref: /openbmc/qemu/tests/qemu-iotests/028 (revision 8dff69b9)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Hajnoczistatus=1	# failure is the default!
318268b767SStefan Hajnoczi
328268b767SStefan Hajnoczi_cleanup()
338268b767SStefan Hajnoczi{
34ecfa1854SJeff Cody    _cleanup_qemu
35f91ecbd7SMax Reitz    _rm_test_img "${TEST_IMG}.copy"
368268b767SStefan Hajnoczi    _cleanup_test_img
378268b767SStefan Hajnoczi}
388268b767SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
398268b767SStefan Hajnoczi
408268b767SStefan Hajnoczi# get standard environment, filters and checks
418268b767SStefan Hajnoczi. ./common.rc
428268b767SStefan Hajnoczi. ./common.filter
438268b767SStefan Hajnoczi. ./common.pattern
44d40593ddSKevin Wolf. ./common.qemu
458268b767SStefan Hajnoczi
468268b767SStefan Hajnoczi# Any format supporting backing files except vmdk and qcow which do not support
478268b767SStefan Hajnoczi# smaller backing files.
48f5a4bbd9SStefan Hajnoczi_supported_fmt qcow2 qed
491f7bf7d0SPeter Lieven_supported_proto file
508268b767SStefan Hajnoczi_supported_os Linux
518268b767SStefan Hajnoczi
528268b767SStefan Hajnoczi# Choose a size that is not necessarily a cluster size multiple for image
538268b767SStefan Hajnoczi# formats that use clusters.  This will ensure that the base image doesn't end
548268b767SStefan Hajnoczi# precisely on a cluster boundary (the easy case).
558268b767SStefan Hajnocziimage_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 ))
568268b767SStefan Hajnoczi
578268b767SStefan Hajnoczi# The base image is smaller than the image file
588268b767SStefan Hajnoczibase_size=$(( image_size - 1024 * 1024 * 1024 ))
598268b767SStefan Hajnoczi
608268b767SStefan Hajnoczioffset=$(( base_size - 32 * 1024 ))
618268b767SStefan Hajnoczi
6249557d65SFam ZhengTEST_IMG_SAVE="$TEST_IMG"
6349557d65SFam ZhengTEST_IMG="$TEST_IMG.base"
6449557d65SFam Zheng
658268b767SStefan Hajnoczi_make_test_img $base_size
668268b767SStefan Hajnoczi
678268b767SStefan Hajnocziecho "Filling base image"
688268b767SStefan Hajnocziecho
698268b767SStefan Hajnoczi
708268b767SStefan Hajnoczi# Fill end of base image with a pattern, skipping every other sector
71dd0c35d6SStefan Hajnocziio writev $offset 512 1024 32
728268b767SStefan Hajnoczi
738268b767SStefan Hajnoczi_check_test_img
748268b767SStefan Hajnoczi
758268b767SStefan Hajnocziecho "Creating test image with backing file"
768268b767SStefan Hajnocziecho
778268b767SStefan Hajnoczi
7849557d65SFam ZhengTEST_IMG="$TEST_IMG_SAVE"
79fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" $image_size
808268b767SStefan Hajnoczi
818268b767SStefan Hajnocziecho "Filling test image"
828268b767SStefan Hajnocziecho
838268b767SStefan Hajnoczi
848268b767SStefan Hajnoczi# Write every other sector around where the base image ends
85dd0c35d6SStefan Hajnocziio writev $(( offset + 512 )) 512 1024 64
868268b767SStefan Hajnoczi
878268b767SStefan Hajnoczi_check_test_img
888268b767SStefan Hajnoczi
898268b767SStefan Hajnocziecho "Reading"
908268b767SStefan Hajnocziecho
918268b767SStefan Hajnoczi
928268b767SStefan Hajnoczi# Base image sectors
93dd0c35d6SStefan Hajnocziio readv $(( offset )) 512 1024 32
948268b767SStefan Hajnoczi
958268b767SStefan Hajnoczi# Image sectors
96dd0c35d6SStefan Hajnocziio readv $(( offset + 512 )) 512 1024 64
978268b767SStefan Hajnoczi
988268b767SStefan Hajnoczi# Zero sectors beyond end of base image
99dd0c35d6SStefan Hajnocziio_zero readv $(( offset + 32 * 1024 )) 512 1024 32
1008268b767SStefan Hajnoczi
1018268b767SStefan Hajnoczi_check_test_img
1028268b767SStefan Hajnoczi
1036ce2d77aSKevin Wolf# Rebase it on top of its base image
104fef9c191SJeff Cody$QEMU_IMG rebase -b "$TEST_IMG.base" "$TEST_IMG"
1056ce2d77aSKevin Wolf
106d40593ddSKevin Wolfecho
107d40593ddSKevin Wolfecho block-backup
108d40593ddSKevin Wolfecho
109d40593ddSKevin Wolf
110d40593ddSKevin Wolfqemu_comm_method="monitor"
111*8dff69b9SAarushi Mehta_launch_qemu -drive file="${TEST_IMG}",cache=${CACHEMODE},aio=${AIOMODE},id=disk
112d40593ddSKevin Wolfh=$QEMU_HANDLE
113fbd1c378SAndrey Shinkevichif [ "${VALGRIND_QEMU}" == "y" ]; then
114fbd1c378SAndrey Shinkevich    QEMU_COMM_TIMEOUT=7
115fbd1c378SAndrey Shinkevichelse
116d40593ddSKevin Wolf    QEMU_COMM_TIMEOUT=1
117fbd1c378SAndrey Shinkevichfi
118d40593ddSKevin Wolf
1198283c5c3SStefan Hajnoczi# Silence output since it contains the disk image path and QEMU's readline
120a174da36SEric Blake# character echoing makes it very hard to filter the output. Plus, there
121a174da36SEric Blake# is no telling how many times the command will repeat before succeeding.
12248c8d3ceSMax Reitz# (Note that creating the image results in a "Formatting..." message over
12348c8d3ceSMax Reitz# stdout, which is the same channel the monitor uses.  We cannot reliably
12448c8d3ceSMax Reitz# wait for it because the monitor output may interact with it in such a
12548c8d3ceSMax Reitz# way that _timed_wait_for cannot read it.  However, once the block job is
12648c8d3ceSMax Reitz# done, we know that the "Formatting..." message must have appeared
12748c8d3ceSMax Reitz# already, so the output is still deterministic.)
12848c8d3ceSMax Reitzsilent=y _send_qemu_cmd $h "drive_backup disk ${TEST_IMG}.copy" "(qemu)"
12948c8d3ceSMax Reitzsilent=y qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs"
130a174da36SEric Blake_send_qemu_cmd $h "info block-jobs" "No active jobs"
131d40593ddSKevin Wolf_send_qemu_cmd $h 'quit' ""
132d40593ddSKevin Wolf
133d40593ddSKevin Wolf# Base image sectors
134d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32
135d40593ddSKevin Wolf
136d40593ddSKevin Wolf# Image sectors
137d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64
138d40593ddSKevin Wolf
139d40593ddSKevin Wolf# Zero sectors beyond end of base image
140d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32
141d40593ddSKevin Wolf
142d40593ddSKevin Wolf
1436ce2d77aSKevin Wolf_check_test_img
1446ce2d77aSKevin Wolf
1458268b767SStefan Hajnoczi# success, all done
1468268b767SStefan Hajnocziecho "*** done"
1478268b767SStefan Hajnoczirm -f $seq.full
1488268b767SStefan Hajnoczistatus=0
149