xref: /qemu/tests/qemu-iotests/046 (revision 91d4093d)
1*91d4093dSKevin Wolf#!/bin/bash
2*91d4093dSKevin Wolf#
3*91d4093dSKevin Wolf# Test concurrent cluster allocations
4*91d4093dSKevin Wolf#
5*91d4093dSKevin Wolf# Copyright (C) 2012 Red Hat, Inc.
6*91d4093dSKevin Wolf#
7*91d4093dSKevin Wolf# This program is free software; you can redistribute it and/or modify
8*91d4093dSKevin Wolf# it under the terms of the GNU General Public License as published by
9*91d4093dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10*91d4093dSKevin Wolf# (at your option) any later version.
11*91d4093dSKevin Wolf#
12*91d4093dSKevin Wolf# This program is distributed in the hope that it will be useful,
13*91d4093dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*91d4093dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*91d4093dSKevin Wolf# GNU General Public License for more details.
16*91d4093dSKevin Wolf#
17*91d4093dSKevin Wolf# You should have received a copy of the GNU General Public License
18*91d4093dSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*91d4093dSKevin Wolf#
20*91d4093dSKevin Wolf
21*91d4093dSKevin Wolf# creator
22*91d4093dSKevin Wolfowner=kwolf@redhat.com
23*91d4093dSKevin Wolf
24*91d4093dSKevin Wolfseq=`basename $0`
25*91d4093dSKevin Wolfecho "QA output created by $seq"
26*91d4093dSKevin Wolf
27*91d4093dSKevin Wolfhere=`pwd`
28*91d4093dSKevin Wolftmp=/tmp/$$
29*91d4093dSKevin Wolfstatus=1	# failure is the default!
30*91d4093dSKevin Wolf
31*91d4093dSKevin Wolf_cleanup()
32*91d4093dSKevin Wolf{
33*91d4093dSKevin Wolf	_cleanup_test_img
34*91d4093dSKevin Wolf}
35*91d4093dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36*91d4093dSKevin Wolf
37*91d4093dSKevin Wolf# get standard environment, filters and checks
38*91d4093dSKevin Wolf. ./common.rc
39*91d4093dSKevin Wolf. ./common.filter
40*91d4093dSKevin Wolf
41*91d4093dSKevin Wolf_supported_fmt qcow2
42*91d4093dSKevin Wolf_supported_proto generic
43*91d4093dSKevin Wolf_supported_os Linux
44*91d4093dSKevin Wolf
45*91d4093dSKevin WolfCLUSTER_SIZE=64k
46*91d4093dSKevin Wolfsize=128M
47*91d4093dSKevin Wolf
48*91d4093dSKevin Wolfecho
49*91d4093dSKevin Wolfecho "== creating backing file for COW tests =="
50*91d4093dSKevin Wolf
51*91d4093dSKevin Wolf_make_test_img $size
52*91d4093dSKevin Wolf
53*91d4093dSKevin Wolffunction backing_io()
54*91d4093dSKevin Wolf{
55*91d4093dSKevin Wolf    local offset=$1
56*91d4093dSKevin Wolf    local sectors=$2
57*91d4093dSKevin Wolf    local op=$3
58*91d4093dSKevin Wolf    local pattern=0
59*91d4093dSKevin Wolf    local cur_sec=0
60*91d4093dSKevin Wolf
61*91d4093dSKevin Wolf    for i in $(seq 0 $((sectors - 1))); do
62*91d4093dSKevin Wolf        cur_sec=$((offset / 65536 + i))
63*91d4093dSKevin Wolf        pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
64*91d4093dSKevin Wolf
65*91d4093dSKevin Wolf        echo "$op -P $pattern $((cur_sec * 64))k 64k"
66*91d4093dSKevin Wolf    done
67*91d4093dSKevin Wolf}
68*91d4093dSKevin Wolf
69*91d4093dSKevin Wolfbacking_io 0 16 write | $QEMU_IO $TEST_IMG | _filter_qemu_io
70*91d4093dSKevin Wolf
71*91d4093dSKevin Wolfmv $TEST_IMG $TEST_IMG.base
72*91d4093dSKevin Wolf
73*91d4093dSKevin Wolf_make_test_img -b $TEST_IMG.base 6G
74*91d4093dSKevin Wolf
75*91d4093dSKevin Wolfecho
76*91d4093dSKevin Wolfecho "== Some concurrent requests touching the same cluster =="
77*91d4093dSKevin Wolf
78*91d4093dSKevin Wolffunction overlay_io()
79*91d4093dSKevin Wolf{
80*91d4093dSKevin Wolf# Allocate middle of cluster 1, then write to somewhere before and after it
81*91d4093dSKevin Wolfcat  <<EOF
82*91d4093dSKevin Wolfbreak write_aio A
83*91d4093dSKevin Wolfaio_write -P 10 0x18000 0x2000
84*91d4093dSKevin Wolfwait_break A
85*91d4093dSKevin Wolf
86*91d4093dSKevin Wolfaio_write -P 11 0x12000 0x2000
87*91d4093dSKevin Wolfaio_write -P 12 0x1c000 0x2000
88*91d4093dSKevin Wolf
89*91d4093dSKevin Wolfresume A
90*91d4093dSKevin Wolfaio_flush
91*91d4093dSKevin WolfEOF
92*91d4093dSKevin Wolf
93*91d4093dSKevin Wolf# Sequential write case: Alloc middle of cluster 2, then write overlapping
94*91d4093dSKevin Wolf# to next cluster
95*91d4093dSKevin Wolfcat  <<EOF
96*91d4093dSKevin Wolfbreak write_aio A
97*91d4093dSKevin Wolfaio_write -P 20 0x28000 0x2000
98*91d4093dSKevin Wolfwait_break A
99*91d4093dSKevin Wolfaio_write -P 21 0x2a000 0x10000
100*91d4093dSKevin Wolfresume A
101*91d4093dSKevin Wolfaio_flush
102*91d4093dSKevin WolfEOF
103*91d4093dSKevin Wolf
104*91d4093dSKevin Wolf# The same with a gap between both requests
105*91d4093dSKevin Wolfcat  <<EOF
106*91d4093dSKevin Wolfbreak write_aio A
107*91d4093dSKevin Wolfaio_write -P 40 0x48000 0x2000
108*91d4093dSKevin Wolfwait_break A
109*91d4093dSKevin Wolfaio_write -P 41 0x4c000 0x10000
110*91d4093dSKevin Wolfresume A
111*91d4093dSKevin Wolfaio_flush
112*91d4093dSKevin WolfEOF
113*91d4093dSKevin Wolf
114*91d4093dSKevin Wolf# Sequential write, but the next cluster is already allocated
115*91d4093dSKevin Wolfcat  <<EOF
116*91d4093dSKevin Wolfwrite -P 70 0x76000 0x8000
117*91d4093dSKevin Wolfaio_flush
118*91d4093dSKevin Wolfbreak write_aio A
119*91d4093dSKevin Wolfaio_write -P 60 0x66000 0x2000
120*91d4093dSKevin Wolfwait_break A
121*91d4093dSKevin Wolfaio_write -P 61 0x6a000 0xe000
122*91d4093dSKevin Wolfresume A
123*91d4093dSKevin Wolfaio_flush
124*91d4093dSKevin WolfEOF
125*91d4093dSKevin Wolf
126*91d4093dSKevin Wolf# Sequential write, but the next cluster is already allocated
127*91d4093dSKevin Wolf# and phyiscally in the right position
128*91d4093dSKevin Wolfcat  <<EOF
129*91d4093dSKevin Wolfwrite -P 89 0x80000 0x1000
130*91d4093dSKevin Wolfwrite -P 90 0x96000 0x8000
131*91d4093dSKevin Wolfaio_flush
132*91d4093dSKevin Wolfdiscard 0x80000 0x10000
133*91d4093dSKevin Wolfaio_flush
134*91d4093dSKevin Wolfbreak write_aio A
135*91d4093dSKevin Wolfaio_write -P 80 0x86000 0x2000
136*91d4093dSKevin Wolfwait_break A
137*91d4093dSKevin Wolfaio_write -P 81 0x8a000 0xe000
138*91d4093dSKevin Wolfresume A
139*91d4093dSKevin Wolfaio_flush
140*91d4093dSKevin WolfEOF
141*91d4093dSKevin Wolf
142*91d4093dSKevin Wolf# Sequential write, and the next cluster is compressed
143*91d4093dSKevin Wolfcat  <<EOF
144*91d4093dSKevin Wolfwrite    -P 109 0xa0000 0x1000
145*91d4093dSKevin Wolfwrite -c -P 110 0xb0000 0x10000
146*91d4093dSKevin Wolfaio_flush
147*91d4093dSKevin Wolfdiscard 0xa0000 0x10000
148*91d4093dSKevin Wolfaio_flush
149*91d4093dSKevin Wolfbreak write_aio A
150*91d4093dSKevin Wolfaio_write -P 100 0xa6000 0x2000
151*91d4093dSKevin Wolfwait_break A
152*91d4093dSKevin Wolfaio_write -P 101 0xaa000 0xe000
153*91d4093dSKevin Wolfresume A
154*91d4093dSKevin Wolfaio_flush
155*91d4093dSKevin WolfEOF
156*91d4093dSKevin Wolf}
157*91d4093dSKevin Wolf
158*91d4093dSKevin Wolfoverlay_io | $QEMU_IO blkdebug::$TEST_IMG | _filter_qemu_io |\
159*91d4093dSKevin Wolf	sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g'
160*91d4093dSKevin Wolf
161*91d4093dSKevin Wolfecho
162*91d4093dSKevin Wolfecho "== Verify image content =="
163*91d4093dSKevin Wolf
164*91d4093dSKevin Wolffunction verify_io()
165*91d4093dSKevin Wolf{
166*91d4093dSKevin Wolf    echo read -P 0 0 0x10000
167*91d4093dSKevin Wolf
168*91d4093dSKevin Wolf    echo read -P 1  0x10000 0x2000
169*91d4093dSKevin Wolf    echo read -P 11 0x12000 0x2000
170*91d4093dSKevin Wolf    echo read -P 1  0x14000 0x4000
171*91d4093dSKevin Wolf    echo read -P 10 0x18000 0x2000
172*91d4093dSKevin Wolf    echo read -P 1  0x1a000 0x2000
173*91d4093dSKevin Wolf    echo read -P 12 0x1c000 0x2000
174*91d4093dSKevin Wolf    echo read -P 1  0x1e000 0x2000
175*91d4093dSKevin Wolf
176*91d4093dSKevin Wolf    echo read -P 2  0x20000 0x8000
177*91d4093dSKevin Wolf    echo read -P 20 0x28000 0x2000
178*91d4093dSKevin Wolf    echo read -P 21 0x2a000 0x10000
179*91d4093dSKevin Wolf    echo read -P 3  0x3a000 0x6000
180*91d4093dSKevin Wolf
181*91d4093dSKevin Wolf    echo read -P 4  0x40000 0x8000
182*91d4093dSKevin Wolf    echo read -P 40 0x48000 0x2000
183*91d4093dSKevin Wolf    echo read -P 4  0x4a000 0x2000
184*91d4093dSKevin Wolf    echo read -P 41 0x4c000 0x10000
185*91d4093dSKevin Wolf    echo read -P 5  0x5c000 0x4000
186*91d4093dSKevin Wolf
187*91d4093dSKevin Wolf    echo read -P 6  0x60000 0x6000
188*91d4093dSKevin Wolf    echo read -P 60 0x66000 0x2000
189*91d4093dSKevin Wolf    echo read -P 6  0x68000 0x2000
190*91d4093dSKevin Wolf    echo read -P 61 0x6a000 0xe000
191*91d4093dSKevin Wolf    echo read -P 70 0x78000 0x6000
192*91d4093dSKevin Wolf    echo read -P 7  0x7e000 0x2000
193*91d4093dSKevin Wolf
194*91d4093dSKevin Wolf    echo read -P 8  0x80000 0x6000
195*91d4093dSKevin Wolf    echo read -P 80 0x86000 0x2000
196*91d4093dSKevin Wolf    echo read -P 8  0x88000 0x2000
197*91d4093dSKevin Wolf    echo read -P 81 0x8a000 0xe000
198*91d4093dSKevin Wolf    echo read -P 90 0x98000 0x6000
199*91d4093dSKevin Wolf    echo read -P 9  0x9e000 0x2000
200*91d4093dSKevin Wolf
201*91d4093dSKevin Wolf    echo read -P 10  0xa0000 0x6000
202*91d4093dSKevin Wolf    echo read -P 100 0xa6000 0x2000
203*91d4093dSKevin Wolf    echo read -P 10  0xa8000 0x2000
204*91d4093dSKevin Wolf    echo read -P 101 0xaa000 0xe000
205*91d4093dSKevin Wolf    echo read -P 110 0xb8000 0x8000
206*91d4093dSKevin Wolf}
207*91d4093dSKevin Wolf
208*91d4093dSKevin Wolfverify_io | $QEMU_IO $TEST_IMG | _filter_qemu_io
209*91d4093dSKevin Wolf
210*91d4093dSKevin Wolf_check_test_img
211*91d4093dSKevin Wolf
212*91d4093dSKevin Wolf# success, all done
213*91d4093dSKevin Wolfecho "*** done"
214*91d4093dSKevin Wolfrm -f $seq.full
215*91d4093dSKevin Wolfstatus=0
216