xref: /openbmc/qemu/tests/qemu-iotests/024 (revision 9dd003a9)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
2*9dd003a9SVladimir Sementsov-Ogievskiy# group: rw backing auto quick
3939e1640SKevin Wolf#
4939e1640SKevin Wolf# Rebasing COW images
5939e1640SKevin Wolf#
6939e1640SKevin Wolf# Copyright (C) 2009 Red Hat, Inc.
7939e1640SKevin Wolf#
8939e1640SKevin Wolf# This program is free software; you can redistribute it and/or modify
9939e1640SKevin Wolf# it under the terms of the GNU General Public License as published by
10939e1640SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
11939e1640SKevin Wolf# (at your option) any later version.
12939e1640SKevin Wolf#
13939e1640SKevin Wolf# This program is distributed in the hope that it will be useful,
14939e1640SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
15939e1640SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16939e1640SKevin Wolf# GNU General Public License for more details.
17939e1640SKevin Wolf#
18939e1640SKevin Wolf# You should have received a copy of the GNU General Public License
19939e1640SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20939e1640SKevin Wolf#
21939e1640SKevin Wolf
22939e1640SKevin Wolf# creator
23939e1640SKevin Wolfowner=kwolf@redhat.com
24939e1640SKevin Wolf
25939e1640SKevin Wolfseq=`basename $0`
26939e1640SKevin Wolfecho "QA output created by $seq"
27939e1640SKevin Wolf
28939e1640SKevin Wolfstatus=1	# failure is the default!
29939e1640SKevin Wolf
30939e1640SKevin Wolf_cleanup()
31939e1640SKevin Wolf{
32939e1640SKevin Wolf    _cleanup_test_img
33f91ecbd7SMax Reitz    _rm_test_img "$TEST_DIR/t.$IMGFMT.base_old"
34f91ecbd7SMax Reitz    _rm_test_img "$TEST_DIR/t.$IMGFMT.base_new"
3528036a7fSMax Reitz
36f91ecbd7SMax Reitz    _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT"
37f91ecbd7SMax Reitz    _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.base_old"
38f91ecbd7SMax Reitz    _rm_test_img "$TEST_DIR/subdir/t.$IMGFMT.base_new"
3928036a7fSMax 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
87b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base_old" -F $IMGFMT 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
113b66ff2c2SEric Blake$QEMU_IMG rebase -b "$TEST_IMG.base_new" -F $IMGFMT "$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
13128036a7fSMax Reitzecho
13228036a7fSMax Reitzecho "=== Test rebase in a subdirectory of the working directory ==="
13328036a7fSMax Reitzecho
13428036a7fSMax Reitz
13528036a7fSMax Reitz# Clean up the old images beforehand so they do not interfere with
13628036a7fSMax Reitz# this test
13728036a7fSMax Reitz_cleanup
13828036a7fSMax Reitz
13928036a7fSMax Reitzmkdir "$TEST_DIR/subdir"
14028036a7fSMax Reitz
14128036a7fSMax Reitz# Relative to the overlay
14228036a7fSMax ReitzBASE_OLD_OREL="t.$IMGFMT.base_old"
14328036a7fSMax ReitzBASE_NEW_OREL="t.$IMGFMT.base_new"
14428036a7fSMax Reitz
14528036a7fSMax Reitz# Relative to $TEST_DIR (which is going to be our working directory)
14628036a7fSMax ReitzOVERLAY_WREL="subdir/t.$IMGFMT"
14728036a7fSMax Reitz
14828036a7fSMax ReitzBASE_OLD="$TEST_DIR/subdir/$BASE_OLD_OREL"
14928036a7fSMax ReitzBASE_NEW="$TEST_DIR/subdir/$BASE_NEW_OREL"
15028036a7fSMax ReitzOVERLAY="$TEST_DIR/$OVERLAY_WREL"
15128036a7fSMax Reitz
15228036a7fSMax Reitz# Test done here:
15328036a7fSMax Reitz#
15428036a7fSMax Reitz# Backing (old): 11 11 -- 11
15528036a7fSMax Reitz# Backing (new): -- 22 22 11
15628036a7fSMax Reitz# Overlay:       -- -- -- --
15728036a7fSMax Reitz#
15828036a7fSMax Reitz# Rebasing works, we have verified that above.  Here, we just want to
15928036a7fSMax Reitz# see that rebasing is done for the correct target backing file.
16028036a7fSMax Reitz
16128036a7fSMax ReitzTEST_IMG=$BASE_OLD _make_test_img 1M
16228036a7fSMax ReitzTEST_IMG=$BASE_NEW _make_test_img 1M
163b66ff2c2SEric BlakeTEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD_OREL" -F $IMGFMT 1M
16428036a7fSMax Reitz
16528036a7fSMax Reitzecho
16628036a7fSMax Reitz
16728036a7fSMax Reitz$QEMU_IO "$BASE_OLD" \
16828036a7fSMax Reitz    -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
16928036a7fSMax Reitz    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
17028036a7fSMax Reitz    | _filter_qemu_io
17128036a7fSMax Reitz
17228036a7fSMax Reitz$QEMU_IO "$BASE_NEW" \
17328036a7fSMax Reitz    -c "write -P 0x22 $((1 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \
17428036a7fSMax Reitz    -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \
17528036a7fSMax Reitz    | _filter_qemu_io
17628036a7fSMax Reitz
17728036a7fSMax Reitzecho
17828036a7fSMax Reitz
17928036a7fSMax Reitzpushd "$TEST_DIR" >/dev/null
180b66ff2c2SEric Blake$QEMU_IMG rebase -f "$IMGFMT" -b "$BASE_NEW_OREL" -F $IMGFMT "$OVERLAY_WREL"
18128036a7fSMax Reitzpopd >/dev/null
18228036a7fSMax Reitz
18328036a7fSMax Reitz# Verify the backing path is correct
184b66ff2c2SEric BlakeTEST_IMG=$OVERLAY _img_info | grep '^backing file:'
18528036a7fSMax Reitz
18628036a7fSMax Reitzecho
18728036a7fSMax Reitz
18828036a7fSMax Reitz# Verify the data is correct
18928036a7fSMax Reitz$QEMU_IO "$OVERLAY" \
19028036a7fSMax Reitz    -c "read -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
19128036a7fSMax Reitz    -c "read -P 0x11 $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
19228036a7fSMax Reitz    -c "read -P 0x00 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
19328036a7fSMax Reitz    -c "read -P 0x11 $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE" \
19428036a7fSMax Reitz    | _filter_qemu_io
19528036a7fSMax Reitz
19628036a7fSMax Reitzecho
19728036a7fSMax Reitz
19828036a7fSMax Reitz# Verify that cluster #3 is not allocated (because it is the same in
19928036a7fSMax Reitz# $BASE_OLD and $BASE_NEW)
20028036a7fSMax Reitz$QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map
20128036a7fSMax Reitz
202939e1640SKevin Wolf
203939e1640SKevin Wolf# success, all done
204939e1640SKevin Wolfecho "*** done"
205939e1640SKevin Wolfrm -f $seq.full
206939e1640SKevin Wolfstatus=0
207