aboutsummaryrefslogtreecommitdiff
path: root/tests/qemu-iotests/046
blob: e528b67cc62fca2b9bf64d898dcc259608a564dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/bash
#
# Test concurrent cluster allocations
#
# Copyright (C) 2012 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# creator
owner=kwolf@redhat.com

seq=`basename $0`
echo "QA output created by $seq"

here=`pwd`
status=1	# failure is the default!

_cleanup()
{
	_cleanup_test_img
}
trap "_cleanup; exit \$status" 0 1 2 3 15

# get standard environment, filters and checks
. ./common.rc
. ./common.filter

_supported_fmt qcow2
_supported_proto file
_supported_os Linux

CLUSTER_SIZE=64k
size=128M

echo
echo "== creating backing file for COW tests =="

_make_test_img $size

function backing_io()
{
    local offset=$1
    local sectors=$2
    local op=$3
    local pattern=0
    local cur_sec=0

    for i in $(seq 0 $((sectors - 1))); do
        cur_sec=$((offset / 65536 + i))
        pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))

        echo "$op -P $pattern $((cur_sec * 64))k 64k"
    done
}

backing_io 0 32 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io

mv "$TEST_IMG" "$TEST_IMG.base"

_make_test_img -b "$TEST_IMG.base" 6G

echo
echo "== Some concurrent requests touching the same cluster =="

function overlay_io()
{
# Allocate middle of cluster 1, then write to somewhere before and after it
cat  <<EOF
break write_aio A
aio_write -P 10 0x18000 0x2000
wait_break A

aio_write -P 11 0x12000 0x2000
aio_write -P 12 0x1c000 0x2000

resume A
aio_flush
EOF

# Sequential write case: Alloc middle of cluster 2, then write overlapping
# to next cluster
cat  <<EOF
break write_aio A
aio_write -P 20 0x28000 0x2000
wait_break A
aio_write -P 21 0x2a000 0x10000
resume A
aio_flush
EOF

# The same with a gap between both requests
cat  <<EOF
break write_aio A
aio_write -P 40 0x48000 0x2000
wait_break A
aio_write -P 41 0x4c000 0x10000
resume A
aio_flush
EOF

# Sequential write, but the next cluster is already allocated
cat  <<EOF
write -P 70 0x76000 0x8000
aio_flush
break write_aio A
aio_write -P 60 0x66000 0x2000
wait_break A
aio_write -P 61 0x6a000 0xe000
resume A
aio_flush
EOF

# Sequential write, but the next cluster is already allocated
# and phyiscally in the right position
cat  <<EOF
write -P 89 0x80000 0x1000
write -P 90 0x96000 0x8000
aio_flush
discard 0x80000 0x10000
aio_flush
break write_aio A
aio_write -P 80 0x86000 0x2000
wait_break A
aio_write -P 81 0x8a000 0xe000
resume A
aio_flush
EOF

# Sequential write, and the next cluster is compressed
cat  <<EOF
write    -P 109 0xa0000 0x1000
write -c -P 110 0xb0000 0x10000
aio_flush
discard 0xa0000 0x10000
aio_flush
break write_aio A
aio_write -P 100 0xa6000 0x2000
wait_break A
aio_write -P 101 0xaa000 0xe000
resume A
aio_flush
EOF

# Reverse sequential write
cat  <<EOF
break write_aio A
aio_write -P 121 0xdc000 0x2000
wait_break A
aio_write -P 120 0xc4000 0x18000
resume A
aio_flush
EOF

# Reverse sequential write with a gap
cat  <<EOF
break write_aio A
aio_write -P 141 0xfc000 0x2000
wait_break A
aio_write -P 140 0xe4000 0x14000
resume A
aio_flush
EOF

# Allocate an area in the middle and then overwrite with a larger request
cat  <<EOF
break write_aio A
aio_write -P 161 0x10c000 0x8000
wait_break A
aio_write -P 160 0x104000 0x18000
resume A
aio_flush
EOF
}

overlay_io | $QEMU_IO blkdebug::"$TEST_IMG" | _filter_qemu_io |\
	sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g'

echo
echo "== Verify image content =="

function verify_io()
{
    if ($QEMU_IMG info -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then
        # For v2 images, discarded clusters are read from the backing file
        # Keep the variable empty so that the backing file value can be used as
        # the default below
        discarded=
    else
        # Discarded clusters are zeroed for v3 or later
        discarded=0
    fi

    echo read -P 0 0 0x10000

    echo read -P 1  0x10000 0x2000
    echo read -P 11 0x12000 0x2000
    echo read -P 1  0x14000 0x4000
    echo read -P 10 0x18000 0x2000
    echo read -P 1  0x1a000 0x2000
    echo read -P 12 0x1c000 0x2000
    echo read -P 1  0x1e000 0x2000

    echo read -P 2  0x20000 0x8000
    echo read -P 20 0x28000 0x2000
    echo read -P 21 0x2a000 0x10000
    echo read -P 3  0x3a000 0x6000

    echo read -P 4  0x40000 0x8000
    echo read -P 40 0x48000 0x2000
    echo read -P 4  0x4a000 0x2000
    echo read -P 41 0x4c000 0x10000
    echo read -P 5  0x5c000 0x4000

    echo read -P 6  0x60000 0x6000
    echo read -P 60 0x66000 0x2000
    echo read -P 6  0x68000 0x2000
    echo read -P 61 0x6a000 0xe000
    echo read -P 70 0x78000 0x6000
    echo read -P 7  0x7e000 0x2000

    echo read -P ${discarded:-8} 0x80000 0x6000
    echo read -P 80 0x86000 0x2000
    echo read -P ${discarded:-8} 0x88000 0x2000
    echo read -P 81 0x8a000 0xe000
    echo read -P 90 0x98000 0x6000
    echo read -P 9  0x9e000 0x2000

    echo read -P ${discarded:-10} 0xa0000 0x6000
    echo read -P 100 0xa6000 0x2000
    echo read -P ${discarded:-10} 0xa8000 0x2000
    echo read -P 101 0xaa000 0xe000
    echo read -P 110 0xb8000 0x8000

    echo read -P 12  0xc0000 0x4000
    echo read -P 120 0xc4000 0x18000
    echo read -P 121 0xdc000 0x2000
    echo read -P 13  0xde000 0x2000

    echo read -P 14  0xe0000 0x4000
    echo read -P 140 0xe4000 0x14000
    echo read -P 15  0xf8000 0x4000
    echo read -P 141 0xfc000 0x2000
    echo read -P 15  0xfe000 0x2000

    echo read -P 16  0x100000 0x4000
    echo read -P 160 0x104000 0x8000
    # Undefined content for 0x10c000 0x8000
    echo read -P 160 0x114000 0x8000
    echo read -P 17  0x11c000 0x4000
}

verify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io

_check_test_img

# success, all done
echo "*** done"
rm -f $seq.full
status=0