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 420446919dSKevin Wolf_supported_proto generic 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 510446919dSKevin Wolf_make_test_img $size 520446919dSKevin Wolf 530446919dSKevin Wolffunction backing_io() 540446919dSKevin Wolf{ 550446919dSKevin Wolf local offset=$1 560446919dSKevin Wolf local sectors=$2 570446919dSKevin Wolf local op=$3 580446919dSKevin Wolf local pattern=0 590446919dSKevin Wolf local cur_sec=0 600446919dSKevin Wolf 610446919dSKevin Wolf for i in $(seq 0 $((sectors - 1))); do 620446919dSKevin Wolf cur_sec=$((offset / 65536 + i)) 630446919dSKevin Wolf pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 )) 640446919dSKevin Wolf 650446919dSKevin Wolf echo "$op -P $pattern $((cur_sec * 64))k 64k" 660446919dSKevin Wolf done 670446919dSKevin Wolf} 680446919dSKevin Wolf 69*fef9c191SJeff Codybacking_io 0 256 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 700446919dSKevin Wolf 71*fef9c191SJeff Codymv "$TEST_IMG" "$TEST_IMG.base" 720446919dSKevin Wolf 73*fef9c191SJeff Cody_make_test_img -b "$TEST_IMG.base" 6G 740446919dSKevin Wolf 750446919dSKevin Wolfecho 760446919dSKevin Wolfecho "== Some concurrent requests touching the same cluster ==" 770446919dSKevin Wolf 780446919dSKevin Wolffunction overlay_io() 790446919dSKevin Wolf{ 800446919dSKevin Wolf # Start with a request touching two clusters 810446919dSKevin Wolf echo aio_write -P 0x80 2020k 80k 820446919dSKevin Wolf 830446919dSKevin Wolf # Then add some requests all over the place 840446919dSKevin Wolf for i in $(seq 0 15; seq 17 31; seq 33 47); do 850446919dSKevin Wolf echo aio_write -P $((0x81 + i)) $((i * 128))k 64k 860446919dSKevin Wolf done 870446919dSKevin Wolf 880446919dSKevin Wolf # Then backwards overwriting part of them 890446919dSKevin Wolf for i in $( (seq 0 15; seq 17 31; seq 33 47) | tac); do 900446919dSKevin Wolf echo aio_write -P $((0x81 + i)) $((i * 128 + 32))k 64k 910446919dSKevin Wolf done 920446919dSKevin Wolf 930446919dSKevin Wolf # And finally crossing the next cluster boundary 940446919dSKevin Wolf echo aio_write -P 0x90 4080k 80k 950446919dSKevin Wolf} 960446919dSKevin Wolf 97*fef9c191SJeff Codyoverlay_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io |\ 98c21bddf2SMax Reitz sed -e 's/bytes at offset [0-9]*/bytes at offset XXX/g' \ 99c21bddf2SMax Reitz -e 's/qemu-io> //g' | paste - - | sort | tr '\t' '\n' 1000446919dSKevin Wolf 1010446919dSKevin Wolfecho 1020446919dSKevin Wolfecho "== Verify image content ==" 1030446919dSKevin Wolf 1040446919dSKevin Wolffunction verify_io() 1050446919dSKevin Wolf{ 1060446919dSKevin Wolf echo read -P 31 2016k 4k 1070446919dSKevin Wolf echo read -P 0x80 2020k 80k 1080446919dSKevin Wolf echo read -P 32 2100k 12k 1090446919dSKevin Wolf echo read -P 33 2112k 64k 1100446919dSKevin Wolf 1110446919dSKevin Wolf echo read -P 63 4064k 16k 1120446919dSKevin Wolf echo read -P 0x90 4080k 80k 1130446919dSKevin Wolf echo read -P 65 4160k 64k 1140446919dSKevin Wolf 1150446919dSKevin Wolf for i in $(seq 0 15; seq 17 31; seq 33 47); do 1160446919dSKevin Wolf echo read -P $((0x81 + i)) $((i * 128))k 96k 1170446919dSKevin Wolf done 1180446919dSKevin Wolf 1190446919dSKevin Wolf for i in $(seq 0 14; seq 16 30; seq 32 47); do 1200446919dSKevin Wolf local cur_sec=$(( i * 2 + 1 )) 1210446919dSKevin Wolf local pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 )) 1220446919dSKevin Wolf 1230446919dSKevin Wolf echo read -P $pattern $((i * 128 + 96))k 32k 1240446919dSKevin Wolf done 1250446919dSKevin Wolf} 1260446919dSKevin Wolf 127*fef9c191SJeff Codyverify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 1280446919dSKevin Wolf 1290446919dSKevin Wolf_check_test_img 1300446919dSKevin Wolf 1310446919dSKevin Wolf# success, all done 1320446919dSKevin Wolfecho "*** done" 1330446919dSKevin Wolfrm -f $seq.full 1340446919dSKevin Wolfstatus=0 135