xref: /openbmc/qemu/tests/qemu-iotests/024 (revision 28036a7f)
1908eaf68SStefan Hajnoczi#!/bin/bash
2939e1640SKevin Wolf#
3939e1640SKevin Wolf# Rebasing COW images
4939e1640SKevin Wolf#
5939e1640SKevin Wolf# Copyright (C) 2009 Red Hat, Inc.
6939e1640SKevin Wolf#
7939e1640SKevin Wolf# This program is free software; you can redistribute it and/or modify
8939e1640SKevin Wolf# it under the terms of the GNU General Public License as published by
9939e1640SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10939e1640SKevin Wolf# (at your option) any later version.
11939e1640SKevin Wolf#
12939e1640SKevin Wolf# This program is distributed in the hope that it will be useful,
13939e1640SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14939e1640SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15939e1640SKevin Wolf# GNU General Public License for more details.
16939e1640SKevin Wolf#
17939e1640SKevin Wolf# You should have received a copy of the GNU General Public License
18939e1640SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19939e1640SKevin Wolf#
20939e1640SKevin Wolf
21939e1640SKevin Wolf# creator
22939e1640SKevin Wolfowner=kwolf@redhat.com
23939e1640SKevin Wolf
24939e1640SKevin Wolfseq=`basename $0`
25939e1640SKevin Wolfecho "QA output created by $seq"
26939e1640SKevin Wolf
27939e1640SKevin Wolfhere=`pwd`
28939e1640SKevin Wolfstatus=1	# failure is the default!
29939e1640SKevin Wolf
30939e1640SKevin Wolf_cleanup()
31939e1640SKevin Wolf{
32939e1640SKevin Wolf    _cleanup_test_img
33fef9c191SJeff Cody    rm -f "$TEST_DIR/t.$IMGFMT.base_old"
34fef9c191SJeff Cody    rm -f "$TEST_DIR/t.$IMGFMT.base_new"
35*28036a7fSMax Reitz
36*28036a7fSMax Reitz    rm -f "$TEST_DIR/subdir/t.$IMGFMT"
37*28036a7fSMax Reitz    rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_old"
38*28036a7fSMax Reitz    rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_new"
39*28036a7fSMax Reitz    rmdir "$TEST_DIR/subdir" 2> /dev/null
40939e1640SKevin Wolf}
41939e1640SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
42939e1640SKevin Wolf
43939e1640SKevin Wolf# get standard environment, filters and checks
44939e1640SKevin Wolf. ./common.rc
45939e1640SKevin Wolf. ./common.filter
46939e1640SKevin Wolf. ./common.pattern
47939e1640SKevin Wolf
48f5a4bbd9SStefan Hajnoczi# Currently only qcow2 and qed support rebasing
49f5a4bbd9SStefan Hajnoczi_supported_fmt qcow2 qed
501f7bf7d0SPeter Lieven_supported_proto file
51939e1640SKevin Wolf_supported_os Linux
52939e1640SKevin Wolf
53939e1640SKevin WolfCLUSTER_SIZE=65536
54939e1640SKevin Wolf
55939e1640SKevin Wolf# Cluster allocations to be tested:
56939e1640SKevin Wolf#
57939e1640SKevin Wolf# Backing (old) 11  --  11  --  11  --  11  --
58939e1640SKevin Wolf# Backing (new) 22  22  --  --  22  22  --  --
59939e1640SKevin Wolf# COW image     33  33  33  33  --  --  --  --
60d586bc63SKevin Wolf#
61d586bc63SKevin Wolf# The pattern is written twice to have both an alloc -> non-alloc and a
62d586bc63SKevin Wolf# non-alloc -> alloc transition in the COW image.
63939e1640SKevin Wolf
64939e1640SKevin Wolfecho "Creating backing file"
65939e1640SKevin Wolfecho
66939e1640SKevin Wolf
67f19f1189SFam ZhengTEST_IMG_SAVE="$TEST_IMG"
68f19f1189SFam ZhengTEST_IMG="$TEST_IMG.base_old"
69f19f1189SFam Zheng
70939e1640SKevin Wolf_make_test_img 1G
71dd0c35d6SStefan Hajnocziio_pattern writev 0 $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 8 0x11
72f19f1189SFam Zheng
73f19f1189SFam ZhengTEST_IMG="$TEST_IMG_SAVE.base_new"
74939e1640SKevin Wolf
75939e1640SKevin Wolfecho "Creating new backing file"
76939e1640SKevin Wolfecho
77939e1640SKevin Wolf
78939e1640SKevin Wolf_make_test_img 1G
79dd0c35d6SStefan Hajnocziio_pattern writev 0 $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 4 0x22
80f19f1189SFam Zheng
81f19f1189SFam Zheng
82f19f1189SFam ZhengTEST_IMG="$TEST_IMG_SAVE"
83939e1640SKevin Wolf
84939e1640SKevin Wolfecho "Creating COW image"
85939e1640SKevin Wolfecho
86939e1640SKevin Wolf
87fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base_old" 1G
88939e1640SKevin Wolfio_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33
89d586bc63SKevin Wolfio_pattern writev $((8 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 0 1 0x33
90939e1640SKevin Wolf
91939e1640SKevin Wolfecho "Read before the rebase to make sure everything is set up correctly"
92939e1640SKevin Wolfecho
93939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
94939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
95939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
96939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
97939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
98939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
99939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
100939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
101d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
102d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
103d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
104d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
105d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
106d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
107d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
108d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
109939e1640SKevin Wolf
110939e1640SKevin Wolfecho
111939e1640SKevin Wolfecho Rebase and test again
112939e1640SKevin Wolfecho
113fef9c191SJeff Cody$QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG"
114939e1640SKevin Wolfio_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
115939e1640SKevin Wolfio_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
116939e1640SKevin Wolfio_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
117939e1640SKevin Wolfio_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
118939e1640SKevin Wolfio_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
119939e1640SKevin Wolfio_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
120939e1640SKevin Wolfio_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
121939e1640SKevin Wolfio_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
122d586bc63SKevin Wolfio_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
123d586bc63SKevin Wolfio_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
124d586bc63SKevin Wolfio_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
125d586bc63SKevin Wolfio_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
126d586bc63SKevin Wolfio_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
127d586bc63SKevin Wolfio_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
128d586bc63SKevin Wolfio_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
129d586bc63SKevin Wolfio_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
130939e1640SKevin Wolf
131*28036a7fSMax Reitzecho
132*28036a7fSMax Reitzecho "=== Test rebase in a subdirectory of the working directory ==="
133*28036a7fSMax Reitzecho
134*28036a7fSMax Reitz
135*28036a7fSMax Reitz# Clean up the old images beforehand so they do not interfere with
136*28036a7fSMax Reitz# this test
137*28036a7fSMax Reitz_cleanup
138*28036a7fSMax Reitz
139*28036a7fSMax Reitzmkdir "$TEST_DIR/subdir"
140*28036a7fSMax Reitz
141*28036a7fSMax Reitz# Relative to the overlay
142*28036a7fSMax ReitzBASE_OLD_OREL="t.$IMGFMT.base_old"
143*28036a7fSMax ReitzBASE_NEW_OREL="t.$IMGFMT.base_new"
144*28036a7fSMax Reitz
145*28036a7fSMax Reitz# Relative to $TEST_DIR (which is going to be our working directory)
146*28036a7fSMax ReitzOVERLAY_WREL="subdir/t.$IMGFMT"
147*28036a7fSMax Reitz
148*28036a7fSMax ReitzBASE_OLD="$TEST_DIR/subdir/$BASE_OLD_OREL"
149*28036a7fSMax ReitzBASE_NEW="$TEST_DIR/subdir/$BASE_NEW_OREL"
150*28036a7fSMax ReitzOVERLAY="$TEST_DIR/$OVERLAY_WREL"
151*28036a7fSMax Reitz
152*28036a7fSMax Reitz# Test done here:
153*28036a7fSMax Reitz#
154*28036a7fSMax Reitz# Backing (old): 11 11 -- 11
155*28036a7fSMax Reitz# Backing (new): -- 22 22 11
156*28036a7fSMax Reitz# Overlay:       -- -- -- --
157*28036a7fSMax Reitz#
158*28036a7fSMax Reitz# Rebasing works, we have verified that above.  Here, we just want to
159*28036a7fSMax Reitz# see that rebasing is done for the correct target backing file.
160*28036a7fSMax Reitz
161*28036a7fSMax ReitzTEST_IMG=$BASE_OLD _make_test_img 1M
162*28036a7fSMax ReitzTEST_IMG=$BASE_NEW _make_test_img 1M
163*28036a7fSMax ReitzTEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD_OREL" 1M
164*28036a7fSMax Reitz
165*28036a7fSMax Reitzecho
166*28036a7fSMax Reitz
167*28036a7fSMax Reitz$QEMU_IO "$BASE_OLD" \
168*28036a7fSMax Reitz    -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
169*28036a7fSMax Reitz    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
170*28036a7fSMax Reitz    | _filter_qemu_io
171*28036a7fSMax Reitz
172*28036a7fSMax Reitz$QEMU_IO "$BASE_NEW" \
173*28036a7fSMax Reitz    -c "write -P 0x22 $((1 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
174*28036a7fSMax Reitz    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
175*28036a7fSMax Reitz    | _filter_qemu_io
176*28036a7fSMax Reitz
177*28036a7fSMax Reitzecho
178*28036a7fSMax Reitz
179*28036a7fSMax Reitzpushd "$TEST_DIR" >/dev/null
180*28036a7fSMax Reitz$QEMU_IMG rebase -f "$IMGFMT" -b "$BASE_NEW_OREL" "$OVERLAY_WREL"
181*28036a7fSMax Reitzpopd >/dev/null
182*28036a7fSMax Reitz
183*28036a7fSMax Reitz# Verify the backing path is correct
184*28036a7fSMax ReitzTEST_IMG=$OVERLAY _img_info | grep '^backing file'
185*28036a7fSMax Reitz
186*28036a7fSMax Reitzecho
187*28036a7fSMax Reitz
188*28036a7fSMax Reitz# Verify the data is correct
189*28036a7fSMax Reitz$QEMU_IO "$OVERLAY" \
190*28036a7fSMax Reitz    -c "read -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
191*28036a7fSMax Reitz    -c "read -P 0x11 $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
192*28036a7fSMax Reitz    -c "read -P 0x00 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
193*28036a7fSMax Reitz    -c "read -P 0x11 $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
194*28036a7fSMax Reitz    | _filter_qemu_io
195*28036a7fSMax Reitz
196*28036a7fSMax Reitzecho
197*28036a7fSMax Reitz
198*28036a7fSMax Reitz# Verify that cluster #3 is not allocated (because it is the same in
199*28036a7fSMax Reitz# $BASE_OLD and $BASE_NEW)
200*28036a7fSMax Reitz$QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map
201*28036a7fSMax Reitz
202939e1640SKevin Wolf
203939e1640SKevin Wolf# success, all done
204939e1640SKevin Wolfecho "*** done"
205939e1640SKevin Wolfrm -f $seq.full
206939e1640SKevin Wolfstatus=0
207