]>
Commit | Line | Data |
---|---|---|
908eaf68 | 1 | #!/bin/bash |
939e1640 KW |
2 | # |
3 | # Rebasing COW images | |
4 | # | |
5 | # Copyright (C) 2009 Red Hat, Inc. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | # | |
20 | ||
21 | # creator | |
22 | [email protected] | |
23 | ||
24 | seq=`basename $0` | |
25 | echo "QA output created by $seq" | |
26 | ||
939e1640 KW |
27 | status=1 # failure is the default! |
28 | ||
29 | _cleanup() | |
30 | { | |
28036a7f HR |
31 | _cleanup_test_img |
32 | rm -f "$TEST_DIR/t.$IMGFMT.base_old" | |
33 | rm -f "$TEST_DIR/t.$IMGFMT.base_new" | |
34 | ||
35 | rm -f "$TEST_DIR/subdir/t.$IMGFMT" | |
36 | rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_old" | |
37 | rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_new" | |
38 | rmdir "$TEST_DIR/subdir" 2> /dev/null | |
939e1640 KW |
39 | } |
40 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
41 | ||
42 | # get standard environment, filters and checks | |
43 | . ./common.rc | |
44 | . ./common.filter | |
45 | . ./common.pattern | |
46 | ||
f5a4bbd9 SH |
47 | # Currently only qcow2 and qed support rebasing |
48 | _supported_fmt qcow2 qed | |
1f7bf7d0 | 49 | _supported_proto file |
939e1640 KW |
50 | _supported_os Linux |
51 | ||
52 | CLUSTER_SIZE=65536 | |
53 | ||
54 | # Cluster allocations to be tested: | |
55 | # | |
56 | # Backing (old) 11 -- 11 -- 11 -- 11 -- | |
57 | # Backing (new) 22 22 -- -- 22 22 -- -- | |
58 | # COW image 33 33 33 33 -- -- -- -- | |
d586bc63 KW |
59 | # |
60 | # The pattern is written twice to have both an alloc -> non-alloc and a | |
61 | # non-alloc -> alloc transition in the COW image. | |
939e1640 KW |
62 | |
63 | echo "Creating backing file" | |
64 | echo | |
65 | ||
f19f1189 FZ |
66 | TEST_IMG_SAVE="$TEST_IMG" |
67 | TEST_IMG="$TEST_IMG.base_old" | |
68 | ||
939e1640 | 69 | _make_test_img 1G |
dd0c35d6 | 70 | io_pattern writev 0 $CLUSTER_SIZE $((2 * CLUSTER_SIZE)) 8 0x11 |
f19f1189 FZ |
71 | |
72 | TEST_IMG="$TEST_IMG_SAVE.base_new" | |
939e1640 KW |
73 | |
74 | echo "Creating new backing file" | |
75 | echo | |
76 | ||
77 | _make_test_img 1G | |
dd0c35d6 | 78 | io_pattern writev 0 $((2 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 4 0x22 |
f19f1189 FZ |
79 | |
80 | ||
81 | TEST_IMG="$TEST_IMG_SAVE" | |
939e1640 KW |
82 | |
83 | echo "Creating COW image" | |
84 | echo | |
85 | ||
fef9c191 | 86 | _make_test_img -b "$TEST_IMG.base_old" 1G |
939e1640 | 87 | io_pattern writev 0 $((4 * CLUSTER_SIZE)) 0 1 0x33 |
d586bc63 | 88 | io_pattern writev $((8 * CLUSTER_SIZE)) $((4 * CLUSTER_SIZE)) 0 1 0x33 |
939e1640 KW |
89 | |
90 | echo "Read before the rebase to make sure everything is set up correctly" | |
91 | echo | |
92 | io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
93 | io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
94 | io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
95 | io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
96 | io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
97 | io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
98 | io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
99 | io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
d586bc63 KW |
100 | io_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 |
101 | io_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
102 | io_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
103 | io_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
104 | io_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
105 | io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
106 | io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
107 | io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
939e1640 KW |
108 | |
109 | echo | |
110 | echo Rebase and test again | |
111 | echo | |
fef9c191 | 112 | $QEMU_IMG rebase -b "$TEST_IMG.base_new" "$TEST_IMG" |
939e1640 KW |
113 | io_pattern readv $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 |
114 | io_pattern readv $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
115 | io_pattern readv $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
116 | io_pattern readv $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
117 | io_pattern readv $((4 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
118 | io_pattern readv $((5 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
119 | io_pattern readv $((6 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
120 | io_pattern readv $((7 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
d586bc63 KW |
121 | io_pattern readv $((8 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 |
122 | io_pattern readv $((9 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
123 | io_pattern readv $((10 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
124 | io_pattern readv $((11 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x33 | |
125 | io_pattern readv $((12 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
126 | io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
127 | io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 | |
128 | io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 | |
939e1640 | 129 | |
28036a7f HR |
130 | echo |
131 | echo "=== Test rebase in a subdirectory of the working directory ===" | |
132 | echo | |
133 | ||
134 | # Clean up the old images beforehand so they do not interfere with | |
135 | # this test | |
136 | _cleanup | |
137 | ||
138 | mkdir "$TEST_DIR/subdir" | |
139 | ||
140 | # Relative to the overlay | |
141 | BASE_OLD_OREL="t.$IMGFMT.base_old" | |
142 | BASE_NEW_OREL="t.$IMGFMT.base_new" | |
143 | ||
144 | # Relative to $TEST_DIR (which is going to be our working directory) | |
145 | OVERLAY_WREL="subdir/t.$IMGFMT" | |
146 | ||
147 | BASE_OLD="$TEST_DIR/subdir/$BASE_OLD_OREL" | |
148 | BASE_NEW="$TEST_DIR/subdir/$BASE_NEW_OREL" | |
149 | OVERLAY="$TEST_DIR/$OVERLAY_WREL" | |
150 | ||
151 | # Test done here: | |
152 | # | |
153 | # Backing (old): 11 11 -- 11 | |
154 | # Backing (new): -- 22 22 11 | |
155 | # Overlay: -- -- -- -- | |
156 | # | |
157 | # Rebasing works, we have verified that above. Here, we just want to | |
158 | # see that rebasing is done for the correct target backing file. | |
159 | ||
160 | TEST_IMG=$BASE_OLD _make_test_img 1M | |
161 | TEST_IMG=$BASE_NEW _make_test_img 1M | |
162 | TEST_IMG=$OVERLAY _make_test_img -b "$BASE_OLD_OREL" 1M | |
163 | ||
164 | echo | |
165 | ||
166 | $QEMU_IO "$BASE_OLD" \ | |
167 | -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ | |
168 | -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \ | |
169 | | _filter_qemu_io | |
170 | ||
171 | $QEMU_IO "$BASE_NEW" \ | |
172 | -c "write -P 0x22 $((1 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ | |
173 | -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \ | |
174 | | _filter_qemu_io | |
175 | ||
176 | echo | |
177 | ||
178 | pushd "$TEST_DIR" >/dev/null | |
179 | $QEMU_IMG rebase -f "$IMGFMT" -b "$BASE_NEW_OREL" "$OVERLAY_WREL" | |
180 | popd >/dev/null | |
181 | ||
182 | # Verify the backing path is correct | |
183 | TEST_IMG=$OVERLAY _img_info | grep '^backing file' | |
184 | ||
185 | echo | |
186 | ||
187 | # Verify the data is correct | |
188 | $QEMU_IO "$OVERLAY" \ | |
189 | -c "read -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ | |
190 | -c "read -P 0x11 $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ | |
191 | -c "read -P 0x00 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ | |
192 | -c "read -P 0x11 $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ | |
193 | | _filter_qemu_io | |
194 | ||
195 | echo | |
196 | ||
197 | # Verify that cluster #3 is not allocated (because it is the same in | |
198 | # $BASE_OLD and $BASE_NEW) | |
199 | $QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map | |
200 | ||
939e1640 KW |
201 | |
202 | # success, all done | |
203 | echo "*** done" | |
204 | rm -f $seq.full | |
205 | status=0 |