xref: /openbmc/qemu/tests/qemu-iotests/038 (revision 1b935e1d)
10446919dSKevin Wolf#!/bin/bash
20446919dSKevin Wolf#
30446919dSKevin Wolf# Test COW from backing files with AIO
40446919dSKevin Wolf#
50446919dSKevin Wolf# Copyright (C) 2012 Red Hat, Inc.
60446919dSKevin Wolf#
70446919dSKevin Wolf# This program is free software; you can redistribute it and/or modify
80446919dSKevin Wolf# it under the terms of the GNU General Public License as published by
90446919dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or
100446919dSKevin Wolf# (at your option) any later version.
110446919dSKevin Wolf#
120446919dSKevin Wolf# This program is distributed in the hope that it will be useful,
130446919dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
140446919dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
150446919dSKevin Wolf# GNU General Public License for more details.
160446919dSKevin Wolf#
170446919dSKevin Wolf# You should have received a copy of the GNU General Public License
180446919dSKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
190446919dSKevin Wolf#
200446919dSKevin Wolf
210446919dSKevin Wolf# creator
220446919dSKevin Wolfowner=kwolf@redhat.com
230446919dSKevin Wolf
240446919dSKevin Wolfseq=`basename $0`
250446919dSKevin Wolfecho "QA output created by $seq"
260446919dSKevin Wolf
270446919dSKevin Wolfhere=`pwd`
280446919dSKevin Wolftmp=/tmp/$$
290446919dSKevin Wolfstatus=1	# failure is the default!
300446919dSKevin Wolf
310446919dSKevin Wolf_cleanup()
320446919dSKevin Wolf{
330446919dSKevin Wolf	_cleanup_test_img
340446919dSKevin Wolf}
350446919dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
360446919dSKevin Wolf
370446919dSKevin Wolf# get standard environment, filters and checks
380446919dSKevin Wolf. ./common.rc
390446919dSKevin Wolf. ./common.filter
400446919dSKevin Wolf
410446919dSKevin Wolf_supported_fmt qcow2 qed
421f7bf7d0SPeter Lieven_supported_proto file
430446919dSKevin Wolf_supported_os Linux
440446919dSKevin Wolf
450446919dSKevin WolfCLUSTER_SIZE=2M
460446919dSKevin Wolfsize=128M
470446919dSKevin Wolf
480446919dSKevin Wolfecho
490446919dSKevin Wolfecho "== creating backing file for COW tests =="
500446919dSKevin Wolf
51*1b935e1dSFam ZhengTEST_IMG_SAVE="$TEST_IMG"
52*1b935e1dSFam ZhengTEST_IMG="$TEST_IMG.base"
53*1b935e1dSFam Zheng
540446919dSKevin Wolf_make_test_img $size
550446919dSKevin Wolf
560446919dSKevin Wolffunction backing_io()
570446919dSKevin Wolf{
580446919dSKevin Wolf    local offset=$1
590446919dSKevin Wolf    local sectors=$2
600446919dSKevin Wolf    local op=$3
610446919dSKevin Wolf    local pattern=0
620446919dSKevin Wolf    local cur_sec=0
630446919dSKevin Wolf
640446919dSKevin Wolf    for i in $(seq 0 $((sectors - 1))); do
650446919dSKevin Wolf        cur_sec=$((offset / 65536 + i))
660446919dSKevin Wolf        pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
670446919dSKevin Wolf
680446919dSKevin Wolf        echo "$op -P $pattern $((cur_sec * 64))k 64k"
690446919dSKevin Wolf    done
700446919dSKevin Wolf}
710446919dSKevin Wolf
72fef9c191SJeff Codybacking_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
730446919dSKevin Wolf
74*1b935e1dSFam ZhengTEST_IMG="$TEST_IMG_SAVE"
750446919dSKevin Wolf
76fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" 6G
770446919dSKevin Wolf
780446919dSKevin Wolfecho
790446919dSKevin Wolfecho "== Some concurrent requests touching the same cluster =="
800446919dSKevin Wolf
810446919dSKevin Wolffunction overlay_io()
820446919dSKevin Wolf{
830446919dSKevin Wolf    # Start with a request touching two clusters
840446919dSKevin Wolf    echo aio_write -P 0x80 2020k 80k
850446919dSKevin Wolf
860446919dSKevin Wolf    # Then add some requests all over the place
870446919dSKevin Wolf    for i in $(seq 0 15; seq 17 31; seq 33 47); do
880446919dSKevin Wolf        echo aio_write -P $((0x81 + i)) $((i * 128))k 64k
890446919dSKevin Wolf    done
900446919dSKevin Wolf
910446919dSKevin Wolf    # Then backwards overwriting part of them
920446919dSKevin Wolf    for i in $( (seq 0 15; seq 17 31; seq 33 47) | tac); do
930446919dSKevin Wolf        echo aio_write -P $((0x81 + i)) $((i * 128 + 32))k 64k
940446919dSKevin Wolf    done
950446919dSKevin Wolf
960446919dSKevin Wolf    # And finally crossing the next cluster boundary
970446919dSKevin Wolf    echo aio_write -P 0x90 4080k 80k
980446919dSKevin Wolf}
990446919dSKevin Wolf
100fef9c191SJeff Codyoverlay_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |\
101c21bddf2SMax Reitz    sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g' \
102c21bddf2SMax Reitz    -e 's/qemu-io> //g' | paste - - | sort | tr '\t' '\n'
1030446919dSKevin Wolf
1040446919dSKevin Wolfecho
1050446919dSKevin Wolfecho "== Verify image content =="
1060446919dSKevin Wolf
1070446919dSKevin Wolffunction verify_io()
1080446919dSKevin Wolf{
1090446919dSKevin Wolf    echo read -P 31 2016k 4k
1100446919dSKevin Wolf    echo read -P 0x80 2020k 80k
1110446919dSKevin Wolf    echo read -P 32 2100k 12k
1120446919dSKevin Wolf    echo read -P 33 2112k 64k
1130446919dSKevin Wolf
1140446919dSKevin Wolf    echo read -P 63 4064k 16k
1150446919dSKevin Wolf    echo read -P 0x90 4080k 80k
1160446919dSKevin Wolf    echo read -P 65 4160k 64k
1170446919dSKevin Wolf
1180446919dSKevin Wolf    for i in $(seq 0 15; seq 17 31; seq 33 47); do
1190446919dSKevin Wolf        echo read -P $((0x81 + i)) $((i * 128))k 96k
1200446919dSKevin Wolf    done
1210446919dSKevin Wolf
1220446919dSKevin Wolf    for i in $(seq 0 14; seq 16 30; seq 32 47); do
1230446919dSKevin Wolf        local cur_sec=$(( i * 2 + 1 ))
1240446919dSKevin Wolf        local pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
1250446919dSKevin Wolf
1260446919dSKevin Wolf        echo read -P $pattern $((i * 128 + 96))k 32k
1270446919dSKevin Wolf    done
1280446919dSKevin Wolf}
1290446919dSKevin Wolf
130fef9c191SJeff Codyverify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
1310446919dSKevin Wolf
1320446919dSKevin Wolf_check_test_img
1330446919dSKevin Wolf
1340446919dSKevin Wolf# success, all done
1350446919dSKevin Wolfecho "*** done"
1360446919dSKevin Wolfrm -f $seq.full
1370446919dSKevin Wolfstatus=0
138