xref: /openbmc/qemu/tests/qemu-iotests/037 (revision bce283cc)
1*bce283ccSKevin Wolf#!/bin/bash
2*bce283ccSKevin Wolf#
3*bce283ccSKevin Wolf# Test COW from backing files
4*bce283ccSKevin Wolf#
5*bce283ccSKevin Wolf# Copyright (C) 2012 Red Hat, Inc.
6*bce283ccSKevin Wolf#
7*bce283ccSKevin Wolf# This program is free software; you can redistribute it and/or modify
8*bce283ccSKevin Wolf# it under the terms of the GNU General Public License as published by
9*bce283ccSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
10*bce283ccSKevin Wolf# (at your option) any later version.
11*bce283ccSKevin Wolf#
12*bce283ccSKevin Wolf# This program is distributed in the hope that it will be useful,
13*bce283ccSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*bce283ccSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*bce283ccSKevin Wolf# GNU General Public License for more details.
16*bce283ccSKevin Wolf#
17*bce283ccSKevin Wolf# You should have received a copy of the GNU General Public License
18*bce283ccSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*bce283ccSKevin Wolf#
20*bce283ccSKevin Wolf
21*bce283ccSKevin Wolf# creator
22*bce283ccSKevin Wolfowner=kwolf@redhat.com
23*bce283ccSKevin Wolf
24*bce283ccSKevin Wolfseq=`basename $0`
25*bce283ccSKevin Wolfecho "QA output created by $seq"
26*bce283ccSKevin Wolf
27*bce283ccSKevin Wolfhere=`pwd`
28*bce283ccSKevin Wolftmp=/tmp/$$
29*bce283ccSKevin Wolfstatus=1	# failure is the default!
30*bce283ccSKevin Wolf
31*bce283ccSKevin Wolf_cleanup()
32*bce283ccSKevin Wolf{
33*bce283ccSKevin Wolf	_cleanup_test_img
34*bce283ccSKevin Wolf}
35*bce283ccSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
36*bce283ccSKevin Wolf
37*bce283ccSKevin Wolf# get standard environment, filters and checks
38*bce283ccSKevin Wolf. ./common.rc
39*bce283ccSKevin Wolf. ./common.filter
40*bce283ccSKevin Wolf
41*bce283ccSKevin Wolf_supported_fmt qcow qcow2 vmdk qed
42*bce283ccSKevin Wolf_supported_proto generic
43*bce283ccSKevin Wolf_supported_os Linux
44*bce283ccSKevin Wolf
45*bce283ccSKevin WolfCLUSTER_SIZE=4k
46*bce283ccSKevin Wolfsize=128M
47*bce283ccSKevin Wolf
48*bce283ccSKevin Wolfecho
49*bce283ccSKevin Wolfecho "== creating backing file for COW tests =="
50*bce283ccSKevin Wolf
51*bce283ccSKevin Wolf_make_test_img $size
52*bce283ccSKevin Wolf
53*bce283ccSKevin Wolffunction backing_io()
54*bce283ccSKevin Wolf{
55*bce283ccSKevin Wolf    local offset=$1
56*bce283ccSKevin Wolf    local sectors=$2
57*bce283ccSKevin Wolf    local op=$3
58*bce283ccSKevin Wolf    local pattern=0
59*bce283ccSKevin Wolf    local cur_sec=0
60*bce283ccSKevin Wolf
61*bce283ccSKevin Wolf    for i in $(seq 0 $((sectors - 1))); do
62*bce283ccSKevin Wolf        cur_sec=$((offset / 512 + i))
63*bce283ccSKevin Wolf        pattern=$(( ( (cur_sec % 256) + (cur_sec / 256)) % 256 ))
64*bce283ccSKevin Wolf
65*bce283ccSKevin Wolf        echo "$op -P $pattern $((cur_sec * 512)) 512"
66*bce283ccSKevin Wolf    done
67*bce283ccSKevin Wolf}
68*bce283ccSKevin Wolf
69*bce283ccSKevin Wolfbacking_io 0 256 write | $QEMU_IO $TEST_IMG | _filter_qemu_io
70*bce283ccSKevin Wolf
71*bce283ccSKevin Wolfmv $TEST_IMG $TEST_IMG.base
72*bce283ccSKevin Wolf
73*bce283ccSKevin Wolf_make_test_img -b $TEST_IMG.base 6G
74*bce283ccSKevin Wolf
75*bce283ccSKevin Wolfecho
76*bce283ccSKevin Wolfecho "== COW in a single cluster =="
77*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x77 0 2k" $TEST_IMG | _filter_qemu_io
78*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x88 6k 2k" $TEST_IMG | _filter_qemu_io
79*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x99 9k 2k" $TEST_IMG | _filter_qemu_io
80*bce283ccSKevin Wolf
81*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x77 0 2k" $TEST_IMG | _filter_qemu_io
82*bce283ccSKevin Wolfbacking_io $((2 * 1024)) 8 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
83*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x88 6k 2k" $TEST_IMG | _filter_qemu_io
84*bce283ccSKevin Wolfbacking_io $((8 * 1024)) 2 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
85*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x99 9k 2k" $TEST_IMG | _filter_qemu_io
86*bce283ccSKevin Wolfbacking_io $((11 * 1024)) 2 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
87*bce283ccSKevin Wolf
88*bce283ccSKevin Wolfecho
89*bce283ccSKevin Wolfecho "== COW in two-cluster allocations =="
90*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x77 16k 6k" $TEST_IMG | _filter_qemu_io
91*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x88 26k 6k" $TEST_IMG | _filter_qemu_io
92*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x99 33k 5k" $TEST_IMG | _filter_qemu_io
93*bce283ccSKevin Wolf
94*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x77 16k 6k" $TEST_IMG | _filter_qemu_io
95*bce283ccSKevin Wolfbacking_io $((22 * 1024)) 8 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
96*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x88 26k 6k" $TEST_IMG | _filter_qemu_io
97*bce283ccSKevin Wolfbacking_io $((32 * 1024)) 2 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
98*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x99 33k 5k" $TEST_IMG | _filter_qemu_io
99*bce283ccSKevin Wolfbacking_io $((38 * 1024)) 4 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
100*bce283ccSKevin Wolf
101*bce283ccSKevin Wolfecho
102*bce283ccSKevin Wolfecho "== COW in multi-cluster allocations =="
103*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x77 48k 15k" $TEST_IMG | _filter_qemu_io
104*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x88 66k 14k" $TEST_IMG | _filter_qemu_io
105*bce283ccSKevin Wolf$QEMU_IO -c "write -P 0x99 83k 15k" $TEST_IMG | _filter_qemu_io
106*bce283ccSKevin Wolf
107*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x77 48k 15k" $TEST_IMG | _filter_qemu_io
108*bce283ccSKevin Wolfbacking_io $((63 * 1024)) 6 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
109*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x88 66k 14k" $TEST_IMG | _filter_qemu_io
110*bce283ccSKevin Wolfbacking_io $((80 * 1024)) 6 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
111*bce283ccSKevin Wolf$QEMU_IO -c "read -P 0x99 83k 15k" $TEST_IMG | _filter_qemu_io
112*bce283ccSKevin Wolfbacking_io $((98 * 1024)) 4 read | $QEMU_IO $TEST_IMG | _filter_qemu_io
113*bce283ccSKevin Wolf
114*bce283ccSKevin Wolf_check_test_img
115*bce283ccSKevin Wolf
116*bce283ccSKevin Wolf# success, all done
117*bce283ccSKevin Wolfecho "*** done"
118*bce283ccSKevin Wolfrm -f $seq.full
119*bce283ccSKevin Wolfstatus=0
120