xref: /openbmc/qemu/tests/qemu-iotests/028 (revision 620a628d)
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"
79b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $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
104b66ff2c2SEric Blake$QEMU_IMG rebase -b "$TEST_IMG.base" -F $IMGFMT "$TEST_IMG"
1056ce2d77aSKevin Wolf
106d40593ddSKevin Wolfecho
107d40593ddSKevin Wolfecho block-backup
108d40593ddSKevin Wolfecho
109d40593ddSKevin Wolf
110d40593ddSKevin Wolfqemu_comm_method="monitor"
1118dff69b9SAarushi 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
119*620a628dSMax ReitzTEST_IMG="$TEST_IMG.copy" _make_test_img $image_size
120*620a628dSMax Reitz_send_qemu_cmd $h "drive_backup -n disk ${TEST_IMG}.copy" "(qemu)" \
121*620a628dSMax Reitz    | _filter_imgfmt
122*620a628dSMax Reitz
12348c8d3ceSMax Reitzsilent=y qemu_cmd_repeat=20 _send_qemu_cmd $h "info block-jobs" "No active jobs"
124a174da36SEric Blake_send_qemu_cmd $h "info block-jobs" "No active jobs"
125d40593ddSKevin Wolf_send_qemu_cmd $h 'quit' ""
126d40593ddSKevin Wolf
127d40593ddSKevin Wolf# Base image sectors
128d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset )) 512 1024 32
129d40593ddSKevin Wolf
130d40593ddSKevin Wolf# Image sectors
131d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io readv $(( offset + 512 )) 512 1024 64
132d40593ddSKevin Wolf
133d40593ddSKevin Wolf# Zero sectors beyond end of base image
134d40593ddSKevin WolfTEST_IMG="${TEST_IMG}.copy" io_zero readv $(( offset + 32 * 1024 )) 512 1024 32
135d40593ddSKevin Wolf
136d40593ddSKevin Wolf
1376ce2d77aSKevin Wolf_check_test_img
1386ce2d77aSKevin Wolf
139ae159450SMax Reitzecho
140ae159450SMax Reitzecho '=== Reading across backing EOF in one operation ==='
141ae159450SMax Reitzecho
142ae159450SMax Reitz
143ae159450SMax Reitz# Use a cluster boundary as the base end here
144ae159450SMax Reitzbase_size=$((3 * 1024 * 1024 * 1024))
145ae159450SMax Reitz
146ae159450SMax ReitzTEST_IMG="$TEST_IMG.base" _make_test_img $base_size
147ae159450SMax Reitz_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $image_size
148ae159450SMax Reitz
149ae159450SMax Reitz# Write 16 times 42 at the end of the base image
150ae159450SMax Reitz$QEMU_IO -c "write -P 42 $((base_size - 16)) 16" "$TEST_IMG.base" \
151ae159450SMax Reitz    | _filter_qemu_io
152ae159450SMax Reitz
153ae159450SMax Reitz# Read 32 bytes across the base EOF from the top;
154ae159450SMax Reitz# should be 16 times 0x2a, then 16 times 0x00
155ae159450SMax Reitz$QEMU_IO -c "read -v $((base_size - 16)) 32" "$TEST_IMG" \
156ae159450SMax Reitz    | _filter_qemu_io
157ae159450SMax Reitz
1588268b767SStefan Hajnoczi# success, all done
1598268b767SStefan Hajnocziecho "*** done"
1608268b767SStefan Hajnoczirm -f $seq.full
1618268b767SStefan Hajnoczistatus=0
162