xref: /openbmc/qemu/tests/qemu-iotests/038 (revision 0446919d)
1*0446919dSKevin Wolf#!/bin/bash
2*0446919dSKevin Wolf#
3*0446919dSKevin Wolf# Test COW from backing files with AIO
4*0446919dSKevin Wolf#
5*0446919dSKevin Wolf# Copyright (C) 2012 Red Hat, Inc.
6*0446919dSKevin Wolf#
7*0446919dSKevin Wolf# This program is free software; you can redistribute it and/or modify
8*0446919dSKevin Wolf# it under the terms of the GNU General Public License as published by
9*0446919dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10*0446919dSKevin Wolf# (at your option) any later version.
11*0446919dSKevin Wolf#
12*0446919dSKevin Wolf# This program is distributed in the hope that it will be useful,
13*0446919dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*0446919dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*0446919dSKevin Wolf# GNU General Public License for more details.
16*0446919dSKevin Wolf#
17*0446919dSKevin Wolf# You should have received a copy of the GNU General Public License
18*0446919dSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*0446919dSKevin Wolf#
20*0446919dSKevin Wolf
21*0446919dSKevin Wolf# creator
22*0446919dSKevin Wolfowner=kwolf@redhat.com
23*0446919dSKevin Wolf
24*0446919dSKevin Wolfseq=`basename $0`
25*0446919dSKevin Wolfecho "QA output created by $seq"
26*0446919dSKevin Wolf
27*0446919dSKevin Wolfhere=`pwd`
28*0446919dSKevin Wolftmp=/tmp/$$
29*0446919dSKevin Wolfstatus=1	# failure is the default!
30*0446919dSKevin Wolf
31*0446919dSKevin Wolf_cleanup()
32*0446919dSKevin Wolf{
33*0446919dSKevin Wolf	_cleanup_test_img
34*0446919dSKevin Wolf}
35*0446919dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36*0446919dSKevin Wolf
37*0446919dSKevin Wolf# get standard environment, filters and checks
38*0446919dSKevin Wolf. ./common.rc
39*0446919dSKevin Wolf. ./common.filter
40*0446919dSKevin Wolf
41*0446919dSKevin Wolf_supported_fmt qcow2 qed
42*0446919dSKevin Wolf_supported_proto generic
43*0446919dSKevin Wolf_supported_os Linux
44*0446919dSKevin Wolf
45*0446919dSKevin WolfCLUSTER_SIZE=2M
46*0446919dSKevin Wolfsize=128M
47*0446919dSKevin Wolf
48*0446919dSKevin Wolfecho
49*0446919dSKevin Wolfecho "== creating backing file for COW tests =="
50*0446919dSKevin Wolf
51*0446919dSKevin Wolf_make_test_img $size
52*0446919dSKevin Wolf
53*0446919dSKevin Wolffunction backing_io()
54*0446919dSKevin Wolf{
55*0446919dSKevin Wolf    local offset=$1
56*0446919dSKevin Wolf    local sectors=$2
57*0446919dSKevin Wolf    local op=$3
58*0446919dSKevin Wolf    local pattern=0
59*0446919dSKevin Wolf    local cur_sec=0
60*0446919dSKevin Wolf
61*0446919dSKevin Wolf    for i in $(seq 0 $((sectors - 1))); do
62*0446919dSKevin Wolf        cur_sec=$((offset / 65536 + i))
63*0446919dSKevin Wolf        pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
64*0446919dSKevin Wolf
65*0446919dSKevin Wolf        echo "$op -P $pattern $((cur_sec * 64))k 64k"
66*0446919dSKevin Wolf    done
67*0446919dSKevin Wolf}
68*0446919dSKevin Wolf
69*0446919dSKevin Wolfbacking_io 0 256 write | $QEMU_IO $TEST_IMG | _filter_qemu_io
70*0446919dSKevin Wolf
71*0446919dSKevin Wolfmv $TEST_IMG $TEST_IMG.base
72*0446919dSKevin Wolf
73*0446919dSKevin Wolf_make_test_img -b $TEST_IMG.base 6G
74*0446919dSKevin Wolf
75*0446919dSKevin Wolfecho
76*0446919dSKevin Wolfecho "== Some concurrent requests touching the same cluster =="
77*0446919dSKevin Wolf
78*0446919dSKevin Wolffunction overlay_io()
79*0446919dSKevin Wolf{
80*0446919dSKevin Wolf    # Start with a request touching two clusters
81*0446919dSKevin Wolf    echo aio_write -P 0x80 2020k 80k
82*0446919dSKevin Wolf
83*0446919dSKevin Wolf    # Then add some requests all over the place
84*0446919dSKevin Wolf    for i in $(seq 0 15; seq 17 31; seq 33 47); do
85*0446919dSKevin Wolf        echo aio_write -P $((0x81 + i)) $((i * 128))k 64k
86*0446919dSKevin Wolf    done
87*0446919dSKevin Wolf
88*0446919dSKevin Wolf    # Then backwards overwriting part of them
89*0446919dSKevin Wolf    for i in $( (seq 0 15; seq 17 31; seq 33 47) | tac); do
90*0446919dSKevin Wolf        echo aio_write -P $((0x81 + i)) $((i * 128 + 32))k 64k
91*0446919dSKevin Wolf    done
92*0446919dSKevin Wolf
93*0446919dSKevin Wolf    # And finally crossing the next cluster boundary
94*0446919dSKevin Wolf    echo aio_write -P 0x90 4080k 80k
95*0446919dSKevin Wolf}
96*0446919dSKevin Wolf
97*0446919dSKevin Wolfoverlay_io | $QEMU_IO $TEST_IMG | _filter_qemu_io |\
98*0446919dSKevin Wolf	sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g'
99*0446919dSKevin Wolf
100*0446919dSKevin Wolfecho
101*0446919dSKevin Wolfecho "== Verify image content =="
102*0446919dSKevin Wolf
103*0446919dSKevin Wolffunction verify_io()
104*0446919dSKevin Wolf{
105*0446919dSKevin Wolf    echo read -P 31 2016k 4k
106*0446919dSKevin Wolf    echo read -P 0x80 2020k 80k
107*0446919dSKevin Wolf    echo read -P 32 2100k 12k
108*0446919dSKevin Wolf    echo read -P 33 2112k 64k
109*0446919dSKevin Wolf
110*0446919dSKevin Wolf    echo read -P 63 4064k 16k
111*0446919dSKevin Wolf    echo read -P 0x90 4080k 80k
112*0446919dSKevin Wolf    echo read -P 65 4160k 64k
113*0446919dSKevin Wolf
114*0446919dSKevin Wolf    for i in $(seq 0 15; seq 17 31; seq 33 47); do
115*0446919dSKevin Wolf        echo read -P $((0x81 + i)) $((i * 128))k 96k
116*0446919dSKevin Wolf    done
117*0446919dSKevin Wolf
118*0446919dSKevin Wolf    for i in $(seq 0 14; seq 16 30; seq 32 47); do
119*0446919dSKevin Wolf        local cur_sec=$(( i * 2 + 1 ))
120*0446919dSKevin Wolf        local pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
121*0446919dSKevin Wolf
122*0446919dSKevin Wolf        echo read -P $pattern $((i * 128 + 96))k 32k
123*0446919dSKevin Wolf    done
124*0446919dSKevin Wolf}
125*0446919dSKevin Wolf
126*0446919dSKevin Wolfverify_io | $QEMU_IO $TEST_IMG | _filter_qemu_io
127*0446919dSKevin Wolf
128*0446919dSKevin Wolf_check_test_img
129*0446919dSKevin Wolf
130*0446919dSKevin Wolf# success, all done
131*0446919dSKevin Wolfecho "*** done"
132*0446919dSKevin Wolfrm -f $seq.full
133*0446919dSKevin Wolfstatus=0
134