docs/devel/qapi-code-gen: Normalize version refs x.y.0 to just x.y
[qemu/kevin.git] / tests / qemu-iotests / 024
blob285f17e79f0c44d147c0a321a69658b6c5d35a7f
1 #!/usr/bin/env bash
2 # group: rw backing auto quick
4 # Rebasing COW images
6 # Copyright (C) 2009 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=kwolf@redhat.com
25 seq=`basename $0`
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
33 _rm_test_img "$TEST_DIR/t.$IMGFMT.base_old"
34 _rm_test_img "$TEST_DIR/t.$IMGFMT.base_new"
36 _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT"
37 _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.base_old"
38 _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.base_new"
39 rmdir "$TEST_DIR/subdir" 2> /dev/null
41 trap "_cleanup; exit \$status" 0 1 2 3 15
43 # get standard environment, filters and checks
44 . ./common.rc
45 . ./common.filter
46 . ./common.pattern
48 # Currently only qcow2 and qed support rebasing
49 _supported_fmt qcow2 qed
50 _supported_proto file
51 _supported_os Linux
53 CLUSTER_SIZE=65536
55 # Cluster allocations to be tested:
57 # Backing (old) 11 -- 11 -- 11 -- 11 --
58 # Backing (new) 22 22 -- -- 22 22 -- --
59 # COW image 33 33 33 33 -- -- -- --
61 # The pattern is written twice to have both an alloc -> non-alloc and a
62 # non-alloc -> alloc transition in the COW image.
64 echo "Creating backing file"
65 echo
67 TEST_IMG_SAVE="$TEST_IMG"
68 TEST_IMG="$TEST_IMG.base_old"
70 _make_test_img 1G
71 io_pattern writev 0 $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 8 0x11
73 TEST_IMG="$TEST_IMG_SAVE.base_new"
75 echo "Creating new backing file"
76 echo
78 _make_test_img 1G
79 io_pattern writev 0 $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 4 0x22
82 TEST_IMG="$TEST_IMG_SAVE"
84 echo "Creating COW image"
85 echo
87 _make_test_img -b "$TEST_IMG.base_old" -F $IMGFMT 1G
88 io_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33
89 io_pattern writev $((8 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 0 1 0x33
91 echo "Read before the rebase to make sure everything is set up correctly"
92 echo
93 io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
94 io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
95 io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
96 io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
97 io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
98 io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
99 io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
100 io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
101 io_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
102 io_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
103 io_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
104 io_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
105 io_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
106 io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
107 io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
108 io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
110 echo
111 echo Rebase and test again
112 echo
113 $QEMU_IMG rebase -b "$TEST_IMG.base_new" -F $IMGFMT "$TEST_IMG"
114 io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
115 io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
116 io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
117 io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
118 io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
119 io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
120 io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
121 io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
122 io_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
123 io_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
124 io_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
125 io_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33
126 io_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
127 io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
128 io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11
129 io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00
131 echo
132 echo "=== Test rebase in a subdirectory of the working directory ==="
133 echo
135 # Clean up the old images beforehand so they do not interfere with
136 # this test
137 _cleanup
139 mkdir "$TEST_DIR/subdir"
141 # Relative to the overlay
142 BASE_OLD_OREL="t.$IMGFMT.base_old"
143 BASE_NEW_OREL="t.$IMGFMT.base_new"
145 # Relative to $TEST_DIR (which is going to be our working directory)
146 OVERLAY_WREL="subdir/t.$IMGFMT"
148 BASE_OLD="$TEST_DIR/subdir/$BASE_OLD_OREL"
149 BASE_NEW="$TEST_DIR/subdir/$BASE_NEW_OREL"
150 OVERLAY="$TEST_DIR/$OVERLAY_WREL"
152 # Test done here:
154 # Backing (old): 11 11 -- 11
155 # Backing (new): -- 22 22 11
156 # Overlay: -- -- -- --
158 # Rebasing works, we have verified that above. Here, we just want to
159 # see that rebasing is done for the correct target backing file.
161 TEST_IMG=$BASE_OLD _make_test_img 1M
162 TEST_IMG=$BASE_NEW _make_test_img 1M
163 TEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD_OREL" -F $IMGFMT 1M
165 echo
167 $QEMU_IO "$BASE_OLD" \
168 -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
169 -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
170 | _filter_qemu_io
172 $QEMU_IO "$BASE_NEW" \
173 -c "write -P 0x22 $((1 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
174 -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
175 | _filter_qemu_io
177 echo
179 pushd "$TEST_DIR" >/dev/null
180 $QEMU_IMG rebase -f "$IMGFMT" -b "$BASE_NEW_OREL" -F $IMGFMT "$OVERLAY_WREL"
181 popd >/dev/null
183 # Verify the backing path is correct
184 TEST_IMG=$OVERLAY _img_info | grep '^backing file:'
186 echo
188 # Verify the data is correct
189 $QEMU_IO "$OVERLAY" \
190 -c "read -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
191 -c "read -P 0x11 $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
192 -c "read -P 0x00 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
193 -c "read -P 0x11 $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
194 | _filter_qemu_io
196 echo
198 # Verify that cluster #3 is not allocated (because it is the same in
199 # $BASE_OLD and $BASE_NEW)
200 $QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map
202 # Check that rebase within the chain is working when
203 # overlay_size > old_backing_size
205 # base_new <-- base_old <-- overlay
207 # Backing (new): 11 11 11 11 11
208 # Backing (old): 22 22 22 22
209 # Overlay: -- -- -- -- --
211 # As a result, overlay should contain data identical to base_old, with the
212 # last cluster remaining unallocated.
214 echo
215 echo "=== Test rebase within one backing chain ==="
216 echo
218 echo "Creating backing chain"
219 echo
221 TEST_IMG=$BASE_NEW _make_test_img $(( CLUSTER_SIZE * 5 ))
222 TEST_IMG=$BASE_OLD _make_test_img -b "$BASE_NEW" -F $IMGFMT \
223 $(( CLUSTER_SIZE * 4 ))
224 TEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD" -F $IMGFMT \
225 $(( CLUSTER_SIZE * 5 ))
227 echo
228 echo "Fill backing files with data"
229 echo
231 $QEMU_IO "$BASE_NEW" -c "write -P 0x11 0 $(( CLUSTER_SIZE * 5 ))" \
232 | _filter_qemu_io
233 $QEMU_IO "$BASE_OLD" -c "write -P 0x22 0 $(( CLUSTER_SIZE * 4 ))" \
234 | _filter_qemu_io
236 echo
237 echo "Check the last cluster is zeroed in overlay before the rebase"
238 echo
239 $QEMU_IO "$OVERLAY" -c "read -P 0x00 $(( CLUSTER_SIZE * 4 )) $CLUSTER_SIZE" \
240 | _filter_qemu_io
242 echo
243 echo "Rebase onto another image in the same chain"
244 echo
246 $QEMU_IMG rebase -b "$BASE_NEW" -F $IMGFMT "$OVERLAY"
248 echo "Verify that data is read the same before and after rebase"
249 echo
251 # Verify the first 4 clusters are still read the same as in the old base
252 $QEMU_IO "$OVERLAY" -c "read -P 0x22 0 $(( CLUSTER_SIZE * 4 ))" \
253 | _filter_qemu_io
254 # Verify the last cluster still reads as zeroes
255 $QEMU_IO "$OVERLAY" -c "read -P 0x00 $(( CLUSTER_SIZE * 4 )) $CLUSTER_SIZE" \
256 | _filter_qemu_io
258 echo
260 # Check that rebase within the chain is working when
261 # overlay cluster size > backings cluster size
262 # (here overlay cluster size == 2 * backings cluster size)
264 # base_new <-- base_old <-- overlay
266 # Backing (new): -- -- -- -- -- --
267 # Backing (old): -- 11 -- -- 22 --
268 # Overlay: |-- --|-- --|-- --|
270 # We should end up having 1st and 3rd cluster allocated, and their halves
271 # being read as zeroes.
273 echo
274 echo "=== Test rebase with different cluster sizes ==="
275 echo
277 echo "Creating backing chain"
278 echo
280 TEST_IMG=$BASE_NEW _make_test_img $(( CLUSTER_SIZE * 6 ))
281 TEST_IMG=$BASE_OLD _make_test_img -b "$BASE_NEW" -F $IMGFMT \
282 $(( CLUSTER_SIZE * 6 ))
283 CLUSTER_SIZE=$(( CLUSTER_SIZE * 2 )) TEST_IMG=$OVERLAY \
284 _make_test_img -b "$BASE_OLD" -F $IMGFMT $(( CLUSTER_SIZE * 6 ))
286 TEST_IMG=$OVERLAY _img_info
288 echo
289 echo "Fill backing files with data"
290 echo
292 $QEMU_IO "$BASE_OLD" -c "write -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" \
293 -c "write -P 0x22 $(( CLUSTER_SIZE * 4 )) $CLUSTER_SIZE" \
294 | _filter_qemu_io
296 echo
297 echo "Rebase onto another image in the same chain"
298 echo
300 $QEMU_IMG rebase -b "$BASE_NEW" -F $IMGFMT "$OVERLAY"
302 echo "Verify that data is read the same before and after rebase"
303 echo
305 $QEMU_IO "$OVERLAY" -c "read -P 0x00 0 $CLUSTER_SIZE" \
306 -c "read -P 0x11 $CLUSTER_SIZE $CLUSTER_SIZE" \
307 -c "read -P 0x00 $(( CLUSTER_SIZE * 2 )) $(( CLUSTER_SIZE * 2 ))" \
308 -c "read -P 0x22 $(( CLUSTER_SIZE * 4 )) $CLUSTER_SIZE" \
309 -c "read -P 0x00 $(( CLUSTER_SIZE * 5 )) $CLUSTER_SIZE" \
310 | _filter_qemu_io
312 echo
313 echo "Verify that untouched cluster remains unallocated"
314 echo
316 $QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map
318 echo
320 # success, all done
321 echo "*** done"
322 rm -f $seq.full
323 status=0