xref: /openbmc/qemu/tests/qemu-iotests/037 (revision 57284d2a)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Wolfstatus=1	# failure is the default!
28bce283ccSKevin Wolf
29bce283ccSKevin Wolf_cleanup()
30bce283ccSKevin Wolf{
31bce283ccSKevin Wolf	_cleanup_test_img
32bce283ccSKevin Wolf}
33bce283ccSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
34bce283ccSKevin Wolf
35bce283ccSKevin Wolf# get standard environment, filters and checks
36bce283ccSKevin Wolf. ./common.rc
37bce283ccSKevin Wolf. ./common.filter
38bce283ccSKevin Wolf
39bce283ccSKevin Wolf_supported_fmt qcow qcow2 vmdk qed
40*57284d2aSMax Reitz_supported_proto file fuse
41d2329f27SFam Zheng_unsupported_imgopts "subformat=monolithicFlat" \
42d2329f27SFam Zheng                     "subformat=twoGbMaxExtentFlat" \
43325dd915SMax Reitz                     "subformat=twoGbMaxExtentSparse" \
44325dd915SMax Reitz                     "subformat=streamOptimized"
45bce283ccSKevin Wolf
46bce283ccSKevin WolfCLUSTER_SIZE=4k
47bce283ccSKevin Wolfsize=128M
48bce283ccSKevin Wolf
49bce283ccSKevin Wolfecho
50bce283ccSKevin Wolfecho "== creating backing file for COW tests =="
51bce283ccSKevin Wolf
529b652fbeSFam ZhengTEST_IMG_SAVE="$TEST_IMG"
539b652fbeSFam ZhengTEST_IMG="$TEST_IMG.base"
549b652fbeSFam Zheng
55bce283ccSKevin Wolf_make_test_img $size
56bce283ccSKevin Wolf
578cedcffdSEric Blakebacking_io()
58bce283ccSKevin Wolf{
59bce283ccSKevin Wolf    local offset=$1
60bce283ccSKevin Wolf    local sectors=$2
61bce283ccSKevin Wolf    local op=$3
62bce283ccSKevin Wolf    local pattern=0
63bce283ccSKevin Wolf    local cur_sec=0
64bce283ccSKevin Wolf
6530edd9faSThomas Huth    for ((i=0;i<=$((sectors - 1));i++)); do
66bce283ccSKevin Wolf        cur_sec=$((offset / 512 + i))
67bce283ccSKevin Wolf        pattern=$(( ( (cur_sec % 256) + (cur_sec / 256)) % 256 ))
68bce283ccSKevin Wolf
69bce283ccSKevin Wolf        echo "$op -P $pattern $((cur_sec * 512)) 512"
70bce283ccSKevin Wolf    done
71bce283ccSKevin Wolf}
72bce283ccSKevin Wolf
73fef9c191SJeff Codybacking_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
74bce283ccSKevin Wolf
759b652fbeSFam ZhengTEST_IMG="$TEST_IMG_SAVE"
76bce283ccSKevin Wolf
77b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G
78bce283ccSKevin Wolf
79bce283ccSKevin Wolfecho
80bce283ccSKevin Wolfecho "== COW in a single cluster =="
81fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io
82fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io
83fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io
84bce283ccSKevin Wolf
85fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 0 2k" "$TEST_IMG" | _filter_qemu_io
86fef9c191SJeff Codybacking_io $((2 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
87fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 6k 2k" "$TEST_IMG" | _filter_qemu_io
88fef9c191SJeff Codybacking_io $((8 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
89fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 9k 2k" "$TEST_IMG" | _filter_qemu_io
90fef9c191SJeff Codybacking_io $((11 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
91bce283ccSKevin Wolf
92bce283ccSKevin Wolfecho
93bce283ccSKevin Wolfecho "== COW in two-cluster allocations =="
94fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io
95fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io
96fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io
97bce283ccSKevin Wolf
98fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 16k 6k" "$TEST_IMG" | _filter_qemu_io
99fef9c191SJeff Codybacking_io $((22 * 1024)) 8 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
100fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 26k 6k" "$TEST_IMG" | _filter_qemu_io
101fef9c191SJeff Codybacking_io $((32 * 1024)) 2 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
102fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 33k 5k" "$TEST_IMG" | _filter_qemu_io
103fef9c191SJeff Codybacking_io $((38 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
104bce283ccSKevin Wolf
105bce283ccSKevin Wolfecho
106bce283ccSKevin Wolfecho "== COW in multi-cluster allocations =="
107fef9c191SJeff Cody$QEMU_IO -c "write -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io
108fef9c191SJeff Cody$QEMU_IO -c "write -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io
109fef9c191SJeff Cody$QEMU_IO -c "write -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io
110bce283ccSKevin Wolf
111fef9c191SJeff Cody$QEMU_IO -c "read -P 0x77 48k 15k" "$TEST_IMG" | _filter_qemu_io
112fef9c191SJeff Codybacking_io $((63 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
113fef9c191SJeff Cody$QEMU_IO -c "read -P 0x88 66k 14k" "$TEST_IMG" | _filter_qemu_io
114fef9c191SJeff Codybacking_io $((80 * 1024)) 6 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
115fef9c191SJeff Cody$QEMU_IO -c "read -P 0x99 83k 15k" "$TEST_IMG" | _filter_qemu_io
116fef9c191SJeff Codybacking_io $((98 * 1024)) 4 read | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
117bce283ccSKevin Wolf
118bce283ccSKevin Wolf_check_test_img
119bce283ccSKevin Wolf
120bce283ccSKevin Wolf# success, all done
121bce283ccSKevin Wolfecho "*** done"
122bce283ccSKevin Wolfrm -f $seq.full
123bce283ccSKevin Wolfstatus=0
124