]>
Commit | Line | Data |
---|---|---|
91d4093d KW |
1 | #!/bin/bash |
2 | # | |
3 | # Test concurrent cluster allocations | |
4 | # | |
5 | # Copyright (C) 2012 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 | ||
27 | here=`pwd` | |
28 | tmp=/tmp/$$ | |
29 | status=1 # failure is the default! | |
30 | ||
31 | _cleanup() | |
32 | { | |
33 | _cleanup_test_img | |
34 | } | |
35 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
36 | ||
37 | # get standard environment, filters and checks | |
38 | . ./common.rc | |
39 | . ./common.filter | |
40 | ||
41 | _supported_fmt qcow2 | |
1f7bf7d0 | 42 | _supported_proto file |
91d4093d KW |
43 | _supported_os Linux |
44 | ||
45 | CLUSTER_SIZE=64k | |
46 | size=128M | |
47 | ||
48 | echo | |
49 | echo "== creating backing file for COW tests ==" | |
50 | ||
51 | _make_test_img $size | |
52 | ||
53 | function backing_io() | |
54 | { | |
55 | local offset=$1 | |
56 | local sectors=$2 | |
57 | local op=$3 | |
58 | local pattern=0 | |
59 | local cur_sec=0 | |
60 | ||
61 | for i in $(seq 0 $((sectors - 1))); do | |
62 | cur_sec=$((offset / 65536 + i)) | |
63 | pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 )) | |
64 | ||
65 | echo "$op -P $pattern $((cur_sec * 64))k 64k" | |
66 | done | |
67 | } | |
68 | ||
fef9c191 | 69 | backing_io 0 32 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |
91d4093d | 70 | |
fef9c191 | 71 | mv "$TEST_IMG" "$TEST_IMG.base" |
91d4093d | 72 | |
fef9c191 | 73 | _make_test_img -b "$TEST_IMG.base" 6G |
91d4093d KW |
74 | |
75 | echo | |
76 | echo "== Some concurrent requests touching the same cluster ==" | |
77 | ||
78 | function overlay_io() | |
79 | { | |
80 | # Allocate middle of cluster 1, then write to somewhere before and after it | |
81 | cat <<EOF | |
82 | break write_aio A | |
83 | aio_write -P 10 0x18000 0x2000 | |
84 | wait_break A | |
85 | ||
86 | aio_write -P 11 0x12000 0x2000 | |
87 | aio_write -P 12 0x1c000 0x2000 | |
88 | ||
89 | resume A | |
90 | aio_flush | |
91 | EOF | |
92 | ||
93 | # Sequential write case: Alloc middle of cluster 2, then write overlapping | |
94 | # to next cluster | |
95 | cat <<EOF | |
96 | break write_aio A | |
97 | aio_write -P 20 0x28000 0x2000 | |
98 | wait_break A | |
99 | aio_write -P 21 0x2a000 0x10000 | |
100 | resume A | |
101 | aio_flush | |
102 | EOF | |
103 | ||
104 | # The same with a gap between both requests | |
105 | cat <<EOF | |
106 | break write_aio A | |
107 | aio_write -P 40 0x48000 0x2000 | |
108 | wait_break A | |
109 | aio_write -P 41 0x4c000 0x10000 | |
110 | resume A | |
111 | aio_flush | |
112 | EOF | |
113 | ||
114 | # Sequential write, but the next cluster is already allocated | |
115 | cat <<EOF | |
116 | write -P 70 0x76000 0x8000 | |
117 | aio_flush | |
118 | break write_aio A | |
119 | aio_write -P 60 0x66000 0x2000 | |
120 | wait_break A | |
121 | aio_write -P 61 0x6a000 0xe000 | |
122 | resume A | |
123 | aio_flush | |
124 | EOF | |
125 | ||
126 | # Sequential write, but the next cluster is already allocated | |
127 | # and phyiscally in the right position | |
128 | cat <<EOF | |
129 | write -P 89 0x80000 0x1000 | |
130 | write -P 90 0x96000 0x8000 | |
131 | aio_flush | |
132 | discard 0x80000 0x10000 | |
133 | aio_flush | |
134 | break write_aio A | |
135 | aio_write -P 80 0x86000 0x2000 | |
136 | wait_break A | |
137 | aio_write -P 81 0x8a000 0xe000 | |
138 | resume A | |
139 | aio_flush | |
140 | EOF | |
141 | ||
142 | # Sequential write, and the next cluster is compressed | |
143 | cat <<EOF | |
144 | write -P 109 0xa0000 0x1000 | |
145 | write -c -P 110 0xb0000 0x10000 | |
146 | aio_flush | |
147 | discard 0xa0000 0x10000 | |
148 | aio_flush | |
149 | break write_aio A | |
150 | aio_write -P 100 0xa6000 0x2000 | |
151 | wait_break A | |
152 | aio_write -P 101 0xaa000 0xe000 | |
153 | resume A | |
154 | aio_flush | |
155 | EOF | |
6f749281 KW |
156 | |
157 | # Reverse sequential write | |
158 | cat <<EOF | |
159 | break write_aio A | |
160 | aio_write -P 121 0xdc000 0x2000 | |
161 | wait_break A | |
162 | aio_write -P 120 0xc4000 0x18000 | |
163 | resume A | |
164 | aio_flush | |
165 | EOF | |
166 | ||
167 | # Reverse sequential write with a gap | |
168 | cat <<EOF | |
169 | break write_aio A | |
170 | aio_write -P 141 0xfc000 0x2000 | |
171 | wait_break A | |
172 | aio_write -P 140 0xe4000 0x14000 | |
173 | resume A | |
174 | aio_flush | |
175 | EOF | |
176 | ||
177 | # Allocate an area in the middle and then overwrite with a larger request | |
178 | cat <<EOF | |
179 | break write_aio A | |
180 | aio_write -P 161 0x10c000 0x8000 | |
181 | wait_break A | |
182 | aio_write -P 160 0x104000 0x18000 | |
183 | resume A | |
184 | aio_flush | |
185 | EOF | |
91d4093d KW |
186 | } |
187 | ||
fef9c191 | 188 | overlay_io | $QEMU_IO blkdebug::"$TEST_IMG" | _filter_qemu_io |\ |
91d4093d KW |
189 | sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g' |
190 | ||
191 | echo | |
192 | echo "== Verify image content ==" | |
193 | ||
194 | function verify_io() | |
195 | { | |
a71835a0 KW |
196 | if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then |
197 | # For v2 images, discarded clusters are read from the backing file | |
198 | # Keep the variable empty so that the backing file value can be used as | |
199 | # the default below | |
200 | discarded= | |
201 | else | |
202 | # Discarded clusters are zeroed for v3 or later | |
203 | discarded=0 | |
204 | fi | |
205 | ||
91d4093d KW |
206 | echo read -P 0 0 0x10000 |
207 | ||
208 | echo read -P 1 0x10000 0x2000 | |
209 | echo read -P 11 0x12000 0x2000 | |
210 | echo read -P 1 0x14000 0x4000 | |
211 | echo read -P 10 0x18000 0x2000 | |
212 | echo read -P 1 0x1a000 0x2000 | |
213 | echo read -P 12 0x1c000 0x2000 | |
214 | echo read -P 1 0x1e000 0x2000 | |
215 | ||
216 | echo read -P 2 0x20000 0x8000 | |
217 | echo read -P 20 0x28000 0x2000 | |
218 | echo read -P 21 0x2a000 0x10000 | |
219 | echo read -P 3 0x3a000 0x6000 | |
220 | ||
221 | echo read -P 4 0x40000 0x8000 | |
222 | echo read -P 40 0x48000 0x2000 | |
223 | echo read -P 4 0x4a000 0x2000 | |
224 | echo read -P 41 0x4c000 0x10000 | |
225 | echo read -P 5 0x5c000 0x4000 | |
226 | ||
227 | echo read -P 6 0x60000 0x6000 | |
228 | echo read -P 60 0x66000 0x2000 | |
229 | echo read -P 6 0x68000 0x2000 | |
230 | echo read -P 61 0x6a000 0xe000 | |
231 | echo read -P 70 0x78000 0x6000 | |
232 | echo read -P 7 0x7e000 0x2000 | |
233 | ||
a71835a0 | 234 | echo read -P ${discarded:-8} 0x80000 0x6000 |
91d4093d | 235 | echo read -P 80 0x86000 0x2000 |
a71835a0 | 236 | echo read -P ${discarded:-8} 0x88000 0x2000 |
91d4093d KW |
237 | echo read -P 81 0x8a000 0xe000 |
238 | echo read -P 90 0x98000 0x6000 | |
239 | echo read -P 9 0x9e000 0x2000 | |
240 | ||
a71835a0 | 241 | echo read -P ${discarded:-10} 0xa0000 0x6000 |
91d4093d | 242 | echo read -P 100 0xa6000 0x2000 |
a71835a0 | 243 | echo read -P ${discarded:-10} 0xa8000 0x2000 |
91d4093d KW |
244 | echo read -P 101 0xaa000 0xe000 |
245 | echo read -P 110 0xb8000 0x8000 | |
6f749281 KW |
246 | |
247 | echo read -P 12 0xc0000 0x4000 | |
248 | echo read -P 120 0xc4000 0x18000 | |
249 | echo read -P 121 0xdc000 0x2000 | |
250 | echo read -P 13 0xde000 0x2000 | |
251 | ||
252 | echo read -P 14 0xe0000 0x4000 | |
253 | echo read -P 140 0xe4000 0x14000 | |
254 | echo read -P 15 0xf8000 0x4000 | |
255 | echo read -P 141 0xfc000 0x2000 | |
256 | echo read -P 15 0xfe000 0x2000 | |
257 | ||
258 | echo read -P 16 0x100000 0x4000 | |
259 | echo read -P 160 0x104000 0x8000 | |
260 | # Undefined content for 0x10c000 0x8000 | |
261 | echo read -P 160 0x114000 0x8000 | |
262 | echo read -P 17 0x11c000 0x4000 | |
91d4093d KW |
263 | } |
264 | ||
fef9c191 | 265 | verify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |
91d4093d KW |
266 | |
267 | _check_test_img | |
268 | ||
269 | # success, all done | |
270 | echo "*** done" | |
271 | rm -f $seq.full | |
272 | status=0 |