xref: /openbmc/qemu/tests/qemu-iotests/028 (revision 8268b767)
1*8268b767SStefan Hajnoczi#!/bin/bash
2*8268b767SStefan Hajnoczi#
3*8268b767SStefan Hajnoczi# Test that backing files can be smaller than the image
4*8268b767SStefan Hajnoczi#
5*8268b767SStefan Hajnoczi# Copyright (C) 2010 IBM, Corp.
6*8268b767SStefan Hajnoczi#
7*8268b767SStefan Hajnoczi# Based on 017:
8*8268b767SStefan Hajnoczi# Copyright (C) 2009 Red Hat, Inc.
9*8268b767SStefan Hajnoczi#
10*8268b767SStefan Hajnoczi# This program is free software; you can redistribute it and/or modify
11*8268b767SStefan Hajnoczi# it under the terms of the GNU General Public License as published by
12*8268b767SStefan Hajnoczi# the Free Software Foundation; either version 2 of the License, or
13*8268b767SStefan Hajnoczi# (at your option) any later version.
14*8268b767SStefan Hajnoczi#
15*8268b767SStefan Hajnoczi# This program is distributed in the hope that it will be useful,
16*8268b767SStefan Hajnoczi# but WITHOUT ANY WARRANTY; without even the implied warranty of
17*8268b767SStefan Hajnoczi# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*8268b767SStefan Hajnoczi# GNU General Public License for more details.
19*8268b767SStefan Hajnoczi#
20*8268b767SStefan Hajnoczi# You should have received a copy of the GNU General Public License
21*8268b767SStefan Hajnoczi# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22*8268b767SStefan Hajnoczi#
23*8268b767SStefan Hajnoczi
24*8268b767SStefan Hajnoczi# creator
25*8268b767SStefan Hajnocziowner=stefanha@linux.vnet.ibm.com
26*8268b767SStefan Hajnoczi
27*8268b767SStefan Hajnocziseq=`basename $0`
28*8268b767SStefan Hajnocziecho "QA output created by $seq"
29*8268b767SStefan Hajnoczi
30*8268b767SStefan Hajnoczihere=`pwd`
31*8268b767SStefan Hajnoczitmp=/tmp/$$
32*8268b767SStefan Hajnoczistatus=1	# failure is the default!
33*8268b767SStefan Hajnoczi
34*8268b767SStefan Hajnoczi_cleanup()
35*8268b767SStefan Hajnoczi{
36*8268b767SStefan Hajnoczi	_cleanup_test_img
37*8268b767SStefan Hajnoczi}
38*8268b767SStefan Hajnoczitrap "_cleanup; exit \$status" 0 1 2 3 15
39*8268b767SStefan Hajnoczi
40*8268b767SStefan Hajnoczi# get standard environment, filters and checks
41*8268b767SStefan Hajnoczi. ./common.rc
42*8268b767SStefan Hajnoczi. ./common.filter
43*8268b767SStefan Hajnoczi. ./common.pattern
44*8268b767SStefan Hajnoczi
45*8268b767SStefan Hajnoczi# Any format supporting backing files except vmdk and qcow which do not support
46*8268b767SStefan Hajnoczi# smaller backing files.
47*8268b767SStefan Hajnoczi_supported_fmt qcow2
48*8268b767SStefan Hajnoczi_supported_os Linux
49*8268b767SStefan Hajnoczi
50*8268b767SStefan Hajnoczi# Choose a size that is not necessarily a cluster size multiple for image
51*8268b767SStefan Hajnoczi# formats that use clusters.  This will ensure that the base image doesn't end
52*8268b767SStefan Hajnoczi# precisely on a cluster boundary (the easy case).
53*8268b767SStefan Hajnocziimage_size=$(( 4 * 1024 * 1024 * 1024 + 3 * 512 ))
54*8268b767SStefan Hajnoczi
55*8268b767SStefan Hajnoczi# The base image is smaller than the image file
56*8268b767SStefan Hajnoczibase_size=$(( image_size - 1024 * 1024 * 1024 ))
57*8268b767SStefan Hajnoczi
58*8268b767SStefan Hajnoczioffset=$(( base_size - 32 * 1024 ))
59*8268b767SStefan Hajnoczi
60*8268b767SStefan Hajnoczi_make_test_img $base_size
61*8268b767SStefan Hajnoczi
62*8268b767SStefan Hajnocziecho "Filling base image"
63*8268b767SStefan Hajnocziecho
64*8268b767SStefan Hajnoczi
65*8268b767SStefan Hajnoczi# Fill end of base image with a pattern, skipping every other sector
66*8268b767SStefan Hajnocziio writev $offset 512 1024 31
67*8268b767SStefan Hajnoczi
68*8268b767SStefan Hajnoczi_check_test_img
69*8268b767SStefan Hajnoczi
70*8268b767SStefan Hajnocziecho "Creating test image with backing file"
71*8268b767SStefan Hajnocziecho
72*8268b767SStefan Hajnoczi
73*8268b767SStefan Hajnoczimv $TEST_IMG $TEST_IMG.base
74*8268b767SStefan Hajnoczi_make_test_img -b $TEST_IMG.base $image_size
75*8268b767SStefan Hajnoczi
76*8268b767SStefan Hajnocziecho "Filling test image"
77*8268b767SStefan Hajnocziecho
78*8268b767SStefan Hajnoczi
79*8268b767SStefan Hajnoczi# Write every other sector around where the base image ends
80*8268b767SStefan Hajnocziio writev $(( offset + 512 )) 512 1024 63
81*8268b767SStefan Hajnoczi
82*8268b767SStefan Hajnoczi_check_test_img
83*8268b767SStefan Hajnoczi
84*8268b767SStefan Hajnocziecho "Reading"
85*8268b767SStefan Hajnocziecho
86*8268b767SStefan Hajnoczi
87*8268b767SStefan Hajnoczi# Base image sectors
88*8268b767SStefan Hajnocziio readv $(( offset )) 512 1024 31
89*8268b767SStefan Hajnoczi
90*8268b767SStefan Hajnoczi# Image sectors
91*8268b767SStefan Hajnocziio readv $(( offset + 512 )) 512 1024 63
92*8268b767SStefan Hajnoczi
93*8268b767SStefan Hajnoczi# Zero sectors beyond end of base image
94*8268b767SStefan Hajnocziio_zero readv $(( offset + 32 * 1024 )) 512 1024 31
95*8268b767SStefan Hajnoczi
96*8268b767SStefan Hajnoczi_check_test_img
97*8268b767SStefan Hajnoczi
98*8268b767SStefan Hajnoczi# success, all done
99*8268b767SStefan Hajnocziecho "*** done"
100*8268b767SStefan Hajnoczirm -f $seq.full
101*8268b767SStefan Hajnoczistatus=0
102