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