xref: /openbmc/qemu/tests/qemu-iotests/038 (revision 57284d2a)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env 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 Wolfstatus=1	# failure is the default!
280446919dSKevin Wolf
290446919dSKevin Wolf_cleanup()
300446919dSKevin Wolf{
310446919dSKevin Wolf	_cleanup_test_img
320446919dSKevin Wolf}
330446919dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
340446919dSKevin Wolf
350446919dSKevin Wolf# get standard environment, filters and checks
360446919dSKevin Wolf. ./common.rc
370446919dSKevin Wolf. ./common.filter
380446919dSKevin Wolf
390446919dSKevin Wolf_supported_fmt qcow2 qed
40*57284d2aSMax Reitz_supported_proto file fuse
410446919dSKevin Wolf_supported_os Linux
420446919dSKevin Wolf
430446919dSKevin WolfCLUSTER_SIZE=2M
440446919dSKevin Wolfsize=128M
450446919dSKevin Wolf
460446919dSKevin Wolfecho
470446919dSKevin Wolfecho "== creating backing file for COW tests =="
480446919dSKevin Wolf
491b935e1dSFam ZhengTEST_IMG_SAVE="$TEST_IMG"
501b935e1dSFam ZhengTEST_IMG="$TEST_IMG.base"
511b935e1dSFam Zheng
520446919dSKevin Wolf_make_test_img $size
530446919dSKevin Wolf
548cedcffdSEric Blakebacking_io()
550446919dSKevin Wolf{
560446919dSKevin Wolf    local offset=$1
570446919dSKevin Wolf    local sectors=$2
580446919dSKevin Wolf    local op=$3
590446919dSKevin Wolf    local pattern=0
600446919dSKevin Wolf    local cur_sec=0
610446919dSKevin Wolf
620446919dSKevin Wolf    for i in $(seq 0 $((sectors - 1))); do
630446919dSKevin Wolf        cur_sec=$((offset / 65536 + i))
640446919dSKevin Wolf        pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
650446919dSKevin Wolf
660446919dSKevin Wolf        echo "$op -P $pattern $((cur_sec * 64))k 64k"
670446919dSKevin Wolf    done
680446919dSKevin Wolf}
690446919dSKevin Wolf
70fef9c191SJeff Codybacking_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
710446919dSKevin Wolf
721b935e1dSFam ZhengTEST_IMG="$TEST_IMG_SAVE"
730446919dSKevin Wolf
74b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G
750446919dSKevin Wolf
760446919dSKevin Wolfecho
770446919dSKevin Wolfecho "== Some concurrent requests touching the same cluster =="
780446919dSKevin Wolf
798cedcffdSEric Blakeoverlay_io()
800446919dSKevin Wolf{
810446919dSKevin Wolf    # Start with a request touching two clusters
820446919dSKevin Wolf    echo aio_write -P 0x80 2020k 80k
830446919dSKevin Wolf
840446919dSKevin Wolf    # Then add some requests all over the place
850446919dSKevin Wolf    for i in $(seq 0 15; seq 17 31; seq 33 47); do
860446919dSKevin Wolf        echo aio_write -P $((0x81 + i)) $((i * 128))k 64k
870446919dSKevin Wolf    done
880446919dSKevin Wolf
890446919dSKevin Wolf    # Then backwards overwriting part of them
900446919dSKevin Wolf    for i in $( (seq 0 15; seq 17 31; seq 33 47) | tac); do
910446919dSKevin Wolf        echo aio_write -P $((0x81 + i)) $((i * 128 + 32))k 64k
920446919dSKevin Wolf    done
930446919dSKevin Wolf
940446919dSKevin Wolf    # And finally crossing the next cluster boundary
950446919dSKevin Wolf    echo aio_write -P 0x90 4080k 80k
960446919dSKevin Wolf}
970446919dSKevin Wolf
98fef9c191SJeff Codyoverlay_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |\
99c21bddf2SMax Reitz    sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g' \
100c21bddf2SMax Reitz    -e 's/qemu-io> //g' | paste - - | sort | tr '\t' '\n'
1010446919dSKevin Wolf
1020446919dSKevin Wolfecho
1030446919dSKevin Wolfecho "== Verify image content =="
1040446919dSKevin Wolf
1058cedcffdSEric Blakeverify_io()
1060446919dSKevin Wolf{
1070446919dSKevin Wolf    echo read -P 31 2016k 4k
1080446919dSKevin Wolf    echo read -P 0x80 2020k 80k
1090446919dSKevin Wolf    echo read -P 32 2100k 12k
1100446919dSKevin Wolf    echo read -P 33 2112k 64k
1110446919dSKevin Wolf
1120446919dSKevin Wolf    echo read -P 63 4064k 16k
1130446919dSKevin Wolf    echo read -P 0x90 4080k 80k
1140446919dSKevin Wolf    echo read -P 65 4160k 64k
1150446919dSKevin Wolf
1160446919dSKevin Wolf    for i in $(seq 0 15; seq 17 31; seq 33 47); do
1170446919dSKevin Wolf        echo read -P $((0x81 + i)) $((i * 128))k 96k
1180446919dSKevin Wolf    done
1190446919dSKevin Wolf
1200446919dSKevin Wolf    for i in $(seq 0 14; seq 16 30; seq 32 47); do
1210446919dSKevin Wolf        local cur_sec=$(( i * 2 + 1 ))
1220446919dSKevin Wolf        local pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 ))
1230446919dSKevin Wolf
1240446919dSKevin Wolf        echo read -P $pattern $((i * 128 + 96))k 32k
1250446919dSKevin Wolf    done
1260446919dSKevin Wolf}
1270446919dSKevin Wolf
128fef9c191SJeff Codyverify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io
1290446919dSKevin Wolf
1300446919dSKevin Wolf_check_test_img
1310446919dSKevin Wolf
1320446919dSKevin Wolf# success, all done
1330446919dSKevin Wolfecho "*** done"
1340446919dSKevin Wolfrm -f $seq.full
1350446919dSKevin Wolfstatus=0
136