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