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