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