xref: /openbmc/qemu/tests/qemu-iotests/046 (revision 54aa3de7)
1#!/usr/bin/env 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
22owner=kwolf@redhat.com
23
24seq=`basename $0`
25echo "QA output created by $seq"
26
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
40_supported_proto file fuse
41# data_file does not support compressed clusters
42_unsupported_imgopts data_file
43
44CLUSTER_SIZE=64k
45size=128M
46
47echo
48echo "== creating backing file for COW tests =="
49
50TEST_IMG_SAVE=$TEST_IMG
51TEST_IMG="$TEST_IMG.base"
52_make_test_img $size
53
54backing_io()
55{
56    local offset=$1
57    local sectors=$2
58    local op=$3
59    local pattern=0
60    local cur_sec=0
61
62    for ((i=0;i<=$((sectors - 1));i++)); do
63        cur_sec=$((offset / 65536 + i))
64        pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
65
66        echo "$op -P $pattern $((cur_sec * 64))k 64k"
67    done
68}
69
70backing_io 0 32 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
71
72TEST_IMG=$TEST_IMG_SAVE
73_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G
74
75echo
76echo "== Some concurrent requests touching the same cluster =="
77
78overlay_io()
79{
80# Allocate middle of cluster 1, then write to somewhere before and after it
81cat  <<EOF
82break write_aio A
83aio_write -P 10 0x18000 0x2000
84wait_break A
85
86aio_write -P 11 0x12000 0x2000
87aio_write -P 12 0x1c000 0x2000
88
89resume A
90aio_flush
91EOF
92
93# Sequential write case: Alloc middle of cluster 2, then write overlapping
94# to next cluster
95cat  <<EOF
96break write_aio A
97aio_write -P 20 0x28000 0x2000
98wait_break A
99aio_write -P 21 0x2a000 0x10000
100resume A
101aio_flush
102EOF
103
104# The same with a gap between both requests
105cat  <<EOF
106break write_aio A
107aio_write -P 40 0x48000 0x2000
108wait_break A
109aio_write -P 41 0x4c000 0x10000
110resume A
111aio_flush
112EOF
113
114# Sequential write, but the next cluster is already allocated
115cat  <<EOF
116write -P 70 0x76000 0x8000
117aio_flush
118break write_aio A
119aio_write -P 60 0x66000 0x2000
120wait_break A
121aio_write -P 61 0x6a000 0xe000
122resume A
123aio_flush
124EOF
125
126# Sequential write, but the next cluster is already allocated
127# and phyiscally in the right position
128cat  <<EOF
129write -P 89 0x80000 0x1000
130write -P 90 0x96000 0x8000
131aio_flush
132discard 0x80000 0x10000
133aio_flush
134break write_aio A
135aio_write -P 80 0x86000 0x2000
136wait_break A
137aio_write -P 81 0x8a000 0xe000
138resume A
139aio_flush
140EOF
141
142# Sequential write, and the next cluster is compressed
143cat  <<EOF
144write    -P 109 0xa0000 0x1000
145write -c -P 110 0xb0000 0x10000
146aio_flush
147discard 0xa0000 0x10000
148aio_flush
149break write_aio A
150aio_write -P 100 0xa6000 0x2000
151wait_break A
152aio_write -P 101 0xaa000 0xe000
153resume A
154aio_flush
155EOF
156
157# Reverse sequential write
158cat  <<EOF
159break write_aio A
160aio_write -P 121 0xdc000 0x2000
161wait_break A
162aio_write -P 120 0xc4000 0x18000
163resume A
164aio_flush
165EOF
166
167# Reverse sequential write with a gap
168cat  <<EOF
169break write_aio A
170aio_write -P 141 0xfc000 0x2000
171wait_break A
172aio_write -P 140 0xe4000 0x14000
173resume A
174aio_flush
175EOF
176
177# Allocate an area in the middle and then overwrite with a larger request
178cat  <<EOF
179break write_aio A
180aio_write -P 161 0x10c000 0x8000
181wait_break A
182aio_write -P 160 0x104000 0x18000
183resume A
184aio_flush
185EOF
186}
187
188overlay_io | $QEMU_IO blkdebug::"$TEST_IMG" | _filter_qemu_io |\
189	sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g'
190
191echo
192echo "== Verify image content =="
193
194verify_io()
195{
196    if ($QEMU_IMG info -U -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
197        # In v2 images clusters are not discarded when there is a backing file.
198        # Keep the variable empty so that the previous 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
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
234    echo read -P ${discarded:-89} 0x80000 0x1000
235    echo read -P ${discarded:-8} 0x81000 0x5000
236    echo read -P 80 0x86000 0x2000
237    echo read -P ${discarded:-8} 0x88000 0x2000
238    echo read -P 81 0x8a000 0xe000
239    echo read -P 90 0x98000 0x6000
240    echo read -P 9  0x9e000 0x2000
241
242    echo read -P ${discarded:-109} 0xa0000 0x1000
243    echo read -P ${discarded:-10} 0xa1000 0x5000
244    echo read -P 100 0xa6000 0x2000
245    echo read -P ${discarded:-10} 0xa8000 0x2000
246    echo read -P 101 0xaa000 0xe000
247    echo read -P 110 0xb8000 0x8000
248
249    echo read -P 12  0xc0000 0x4000
250    echo read -P 120 0xc4000 0x18000
251    echo read -P 121 0xdc000 0x2000
252    echo read -P 13  0xde000 0x2000
253
254    echo read -P 14  0xe0000 0x4000
255    echo read -P 140 0xe4000 0x14000
256    echo read -P 15  0xf8000 0x4000
257    echo read -P 141 0xfc000 0x2000
258    echo read -P 15  0xfe000 0x2000
259
260    echo read -P 16  0x100000 0x4000
261    echo read -P 160 0x104000 0x8000
262    # Undefined content for 0x10c000 0x8000
263    echo read -P 160 0x114000 0x8000
264    echo read -P 17  0x11c000 0x4000
265}
266
267verify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
268
269_check_test_img
270
271# success, all done
272echo "*** done"
273rm -f $seq.full
274status=0
275