xref: /openbmc/qemu/tests/qemu-iotests/037 (revision fef9c191)
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
42bce283ccSKevin Wolf_supported_proto generic
43bce283ccSKevin Wolf_supported_os Linux
44bce283ccSKevin Wolf
45bce283ccSKevin WolfCLUSTER_SIZE=4k
46bce283ccSKevin Wolfsize=128M
47bce283ccSKevin Wolf
48bce283ccSKevin Wolfecho
49bce283ccSKevin Wolfecho "== creating backing file for COW tests =="
50bce283ccSKevin Wolf
51bce283ccSKevin Wolf_make_test_img $size
52bce283ccSKevin Wolf
53bce283ccSKevin Wolffunction backing_io()
54bce283ccSKevin Wolf{
55bce283ccSKevin Wolf    local offset=$1
56bce283ccSKevin Wolf    local sectors=$2
57bce283ccSKevin Wolf    local op=$3
58bce283ccSKevin Wolf    local pattern=0
59bce283ccSKevin Wolf    local cur_sec=0
60bce283ccSKevin Wolf
61bce283ccSKevin Wolf    for i in $(seq 0 $((sectors - 1))); do
62bce283ccSKevin Wolf        cur_sec=$((offset / 512 + i))
63bce283ccSKevin Wolf        pattern=$(( ( (cur_sec % 256) + (cur_sec / 256)) % 256 ))
64bce283ccSKevin Wolf
65bce283ccSKevin Wolf        echo "$op -P $pattern $((cur_sec * 512)) 512"
66bce283ccSKevin Wolf    done
67bce283ccSKevin Wolf}
68bce283ccSKevin Wolf
69*fef9c191SJeff Codybacking_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
70bce283ccSKevin Wolf
71*fef9c191SJeff Codymv "$TEST_IMG" "$TEST_IMG.base"
72bce283ccSKevin Wolf
73*fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" 6G
74bce283ccSKevin Wolf
75bce283ccSKevin Wolfecho
76bce283ccSKevin Wolfecho "== COW in a single cluster =="
77*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io
78*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io
79*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io
80bce283ccSKevin Wolf
81*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io
82*fef9c191SJeff Codybacking_io $((2 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
83*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io
84*fef9c191SJeff Codybacking_io $((8 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
85*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io
86*fef9c191SJeff Codybacking_io $((11 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
87bce283ccSKevin Wolf
88bce283ccSKevin Wolfecho
89bce283ccSKevin Wolfecho "== COW in two-cluster allocations =="
90*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io
91*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io
92*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io
93bce283ccSKevin Wolf
94*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io
95*fef9c191SJeff Codybacking_io $((22 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
96*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io
97*fef9c191SJeff Codybacking_io $((32 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
98*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io
99*fef9c191SJeff Codybacking_io $((38 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
100bce283ccSKevin Wolf
101bce283ccSKevin Wolfecho
102bce283ccSKevin Wolfecho "== COW in multi-cluster allocations =="
103*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io
104*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io
105*fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io
106bce283ccSKevin Wolf
107*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io
108*fef9c191SJeff Codybacking_io $((63 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
109*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io
110*fef9c191SJeff Codybacking_io $((80 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
111*fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io
112*fef9c191SJeff Codybacking_io $((98 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
113bce283ccSKevin Wolf
114bce283ccSKevin Wolf_check_test_img
115bce283ccSKevin Wolf
116bce283ccSKevin Wolf# success, all done
117bce283ccSKevin Wolfecho "*** done"
118bce283ccSKevin Wolfrm -f $seq.full
119bce283ccSKevin Wolfstatus=0
120