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