111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29dd003a9SVladimir Sementsov-Ogievskiy# group: rw auto aio quick 391d4093dSKevin Wolf# 491d4093dSKevin Wolf# Test concurrent cluster allocations 591d4093dSKevin Wolf# 691d4093dSKevin Wolf# Copyright (C) 2012 Red Hat, Inc. 791d4093dSKevin Wolf# 891d4093dSKevin Wolf# This program is free software; you can redistribute it and/or modify 991d4093dSKevin Wolf# it under the terms of the GNU General Public License as published by 1091d4093dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 1191d4093dSKevin Wolf# (at your option) any later version. 1291d4093dSKevin Wolf# 1391d4093dSKevin Wolf# This program is distributed in the hope that it will be useful, 1491d4093dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 1591d4093dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1691d4093dSKevin Wolf# GNU General Public License for more details. 1791d4093dSKevin Wolf# 1891d4093dSKevin Wolf# You should have received a copy of the GNU General Public License 1991d4093dSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 2091d4093dSKevin Wolf# 2191d4093dSKevin Wolf 2291d4093dSKevin Wolf# creator 2391d4093dSKevin Wolfowner=kwolf@redhat.com 2491d4093dSKevin Wolf 2591d4093dSKevin Wolfseq=`basename $0` 2691d4093dSKevin Wolfecho "QA output created by $seq" 2791d4093dSKevin Wolf 2891d4093dSKevin Wolfstatus=1 # failure is the default! 2991d4093dSKevin Wolf 3091d4093dSKevin Wolf_cleanup() 3191d4093dSKevin Wolf{ 3291d4093dSKevin Wolf _cleanup_test_img 3391d4093dSKevin Wolf} 3491d4093dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3591d4093dSKevin Wolf 3691d4093dSKevin Wolf# get standard environment, filters and checks 3791d4093dSKevin Wolf. ./common.rc 3891d4093dSKevin Wolf. ./common.filter 3991d4093dSKevin Wolf 4091d4093dSKevin Wolf_supported_fmt qcow2 4157284d2aSMax Reitz_supported_proto file fuse 423be2024aSMax Reitz# data_file does not support compressed clusters 433be2024aSMax Reitz_unsupported_imgopts data_file 4491d4093dSKevin Wolf 4591d4093dSKevin WolfCLUSTER_SIZE=64k 4691d4093dSKevin Wolfsize=128M 4791d4093dSKevin Wolf 4891d4093dSKevin Wolfecho 4991d4093dSKevin Wolfecho "== creating backing file for COW tests ==" 5091d4093dSKevin Wolf 5163c17df7SMax ReitzTEST_IMG_SAVE=$TEST_IMG 5263c17df7SMax ReitzTEST_IMG="$TEST_IMG.base" 5391d4093dSKevin Wolf_make_test_img $size 5491d4093dSKevin Wolf 558cedcffdSEric Blakebacking_io() 5691d4093dSKevin Wolf{ 5791d4093dSKevin Wolf local offset=$1 5891d4093dSKevin Wolf local sectors=$2 5991d4093dSKevin Wolf local op=$3 6091d4093dSKevin Wolf local pattern=0 6191d4093dSKevin Wolf local cur_sec=0 6291d4093dSKevin Wolf 6330edd9faSThomas Huth for ((i=0;i<=$((sectors - 1));i++)); do 6491d4093dSKevin Wolf cur_sec=$((offset / 65536 + i)) 6591d4093dSKevin Wolf pattern=$(( ( (cur_sec % 128) + (cur_sec / 128)) % 128 )) 6691d4093dSKevin Wolf 6791d4093dSKevin Wolf echo "$op -P $pattern $((cur_sec * 64))k 64k" 6891d4093dSKevin Wolf done 6991d4093dSKevin Wolf} 7091d4093dSKevin Wolf 71fef9c191SJeff Codybacking_io 0 32 write | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 7291d4093dSKevin Wolf 7363c17df7SMax ReitzTEST_IMG=$TEST_IMG_SAVE 74b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT 6G 7591d4093dSKevin Wolf 7691d4093dSKevin Wolfecho 7791d4093dSKevin Wolfecho "== Some concurrent requests touching the same cluster ==" 7891d4093dSKevin Wolf 798cedcffdSEric Blakeoverlay_io() 8091d4093dSKevin Wolf{ 8191d4093dSKevin Wolf# Allocate middle of cluster 1, then write to somewhere before and after it 8291d4093dSKevin Wolfcat <<EOF 8391d4093dSKevin Wolfbreak write_aio A 8491d4093dSKevin Wolfaio_write -P 10 0x18000 0x2000 8591d4093dSKevin Wolfwait_break A 8691d4093dSKevin Wolf 8791d4093dSKevin Wolfaio_write -P 11 0x12000 0x2000 8891d4093dSKevin Wolfaio_write -P 12 0x1c000 0x2000 8991d4093dSKevin Wolf 9091d4093dSKevin Wolfresume A 9191d4093dSKevin Wolfaio_flush 9291d4093dSKevin WolfEOF 9391d4093dSKevin Wolf 9491d4093dSKevin Wolf# Sequential write case: Alloc middle of cluster 2, then write overlapping 9591d4093dSKevin Wolf# to next cluster 9691d4093dSKevin Wolfcat <<EOF 9791d4093dSKevin Wolfbreak write_aio A 9891d4093dSKevin Wolfaio_write -P 20 0x28000 0x2000 9991d4093dSKevin Wolfwait_break A 10091d4093dSKevin Wolfaio_write -P 21 0x2a000 0x10000 10191d4093dSKevin Wolfresume A 10291d4093dSKevin Wolfaio_flush 10391d4093dSKevin WolfEOF 10491d4093dSKevin Wolf 10591d4093dSKevin Wolf# The same with a gap between both requests 10691d4093dSKevin Wolfcat <<EOF 10791d4093dSKevin Wolfbreak write_aio A 10891d4093dSKevin Wolfaio_write -P 40 0x48000 0x2000 10991d4093dSKevin Wolfwait_break A 11091d4093dSKevin Wolfaio_write -P 41 0x4c000 0x10000 11191d4093dSKevin Wolfresume A 11291d4093dSKevin Wolfaio_flush 11391d4093dSKevin WolfEOF 11491d4093dSKevin Wolf 11591d4093dSKevin Wolf# Sequential write, but the next cluster is already allocated 11691d4093dSKevin Wolfcat <<EOF 11791d4093dSKevin Wolfwrite -P 70 0x76000 0x8000 11891d4093dSKevin Wolfaio_flush 11991d4093dSKevin Wolfbreak write_aio A 12091d4093dSKevin Wolfaio_write -P 60 0x66000 0x2000 12191d4093dSKevin Wolfwait_break A 12291d4093dSKevin Wolfaio_write -P 61 0x6a000 0xe000 12391d4093dSKevin Wolfresume A 12491d4093dSKevin Wolfaio_flush 12591d4093dSKevin WolfEOF 12691d4093dSKevin Wolf 12791d4093dSKevin Wolf# Sequential write, but the next cluster is already allocated 128*96420a30SMichael Tokarev# and physically in the right position 12991d4093dSKevin Wolfcat <<EOF 13091d4093dSKevin Wolfwrite -P 89 0x80000 0x1000 13191d4093dSKevin Wolfwrite -P 90 0x96000 0x8000 13291d4093dSKevin Wolfaio_flush 13391d4093dSKevin Wolfdiscard 0x80000 0x10000 13491d4093dSKevin Wolfaio_flush 13591d4093dSKevin Wolfbreak write_aio A 13691d4093dSKevin Wolfaio_write -P 80 0x86000 0x2000 13791d4093dSKevin Wolfwait_break A 13891d4093dSKevin Wolfaio_write -P 81 0x8a000 0xe000 13991d4093dSKevin Wolfresume A 14091d4093dSKevin Wolfaio_flush 14191d4093dSKevin WolfEOF 14291d4093dSKevin Wolf 14391d4093dSKevin Wolf# Sequential write, and the next cluster is compressed 14491d4093dSKevin Wolfcat <<EOF 14591d4093dSKevin Wolfwrite -P 109 0xa0000 0x1000 14691d4093dSKevin Wolfwrite -c -P 110 0xb0000 0x10000 14791d4093dSKevin Wolfaio_flush 14891d4093dSKevin Wolfdiscard 0xa0000 0x10000 14991d4093dSKevin Wolfaio_flush 15091d4093dSKevin Wolfbreak write_aio A 15191d4093dSKevin Wolfaio_write -P 100 0xa6000 0x2000 15291d4093dSKevin Wolfwait_break A 15391d4093dSKevin Wolfaio_write -P 101 0xaa000 0xe000 15491d4093dSKevin Wolfresume A 15591d4093dSKevin Wolfaio_flush 15691d4093dSKevin WolfEOF 1576f749281SKevin Wolf 1586f749281SKevin Wolf# Reverse sequential write 1596f749281SKevin Wolfcat <<EOF 1606f749281SKevin Wolfbreak write_aio A 1616f749281SKevin Wolfaio_write -P 121 0xdc000 0x2000 1626f749281SKevin Wolfwait_break A 1636f749281SKevin Wolfaio_write -P 120 0xc4000 0x18000 1646f749281SKevin Wolfresume A 1656f749281SKevin Wolfaio_flush 1666f749281SKevin WolfEOF 1676f749281SKevin Wolf 1686f749281SKevin Wolf# Reverse sequential write with a gap 1696f749281SKevin Wolfcat <<EOF 1706f749281SKevin Wolfbreak write_aio A 1716f749281SKevin Wolfaio_write -P 141 0xfc000 0x2000 1726f749281SKevin Wolfwait_break A 1736f749281SKevin Wolfaio_write -P 140 0xe4000 0x14000 1746f749281SKevin Wolfresume A 1756f749281SKevin Wolfaio_flush 1766f749281SKevin WolfEOF 1776f749281SKevin Wolf 1786f749281SKevin Wolf# Allocate an area in the middle and then overwrite with a larger request 1796f749281SKevin Wolfcat <<EOF 1806f749281SKevin Wolfbreak write_aio A 1816f749281SKevin Wolfaio_write -P 161 0x10c000 0x8000 1826f749281SKevin Wolfwait_break A 1836f749281SKevin Wolfaio_write -P 160 0x104000 0x18000 1846f749281SKevin Wolfresume A 1856f749281SKevin Wolfaio_flush 1866f749281SKevin WolfEOF 18791d4093dSKevin Wolf} 18891d4093dSKevin Wolf 189fef9c191SJeff Codyoverlay_io | $QEMU_IO blkdebug::"$TEST_IMG" | _filter_qemu_io |\ 1906d7bb951SMax Reitz sed -e 's/[0-9]*\/[0-9]* bytes at offset [0-9]*/XXX\/XXX bytes at offset XXX/g' \ 1916d7bb951SMax Reitz -e 's/^[0-9]* KiB/XXX KiB/g' 19291d4093dSKevin Wolf 19391d4093dSKevin Wolfecho 19491d4093dSKevin Wolfecho "== Verify image content ==" 19591d4093dSKevin Wolf 1968cedcffdSEric Blakeverify_io() 19791d4093dSKevin Wolf{ 19855e5a3b6SFam Zheng if ($QEMU_IMG info -U -f "$IMGFMT" "$TEST_IMG" | grep "compat: 0.10" > /dev/null); then 19980f5c011SAlberto Garcia # In v2 images clusters are not discarded when there is a backing file. 20080f5c011SAlberto Garcia # Keep the variable empty so that the previous value can be used as 201a71835a0SKevin Wolf # the default below 202a71835a0SKevin Wolf discarded= 203a71835a0SKevin Wolf else 204a71835a0SKevin Wolf # Discarded clusters are zeroed for v3 or later 205a71835a0SKevin Wolf discarded=0 206a71835a0SKevin Wolf fi 207a71835a0SKevin Wolf 20891d4093dSKevin Wolf echo read -P 0 0 0x10000 20991d4093dSKevin Wolf 21091d4093dSKevin Wolf echo read -P 1 0x10000 0x2000 21191d4093dSKevin Wolf echo read -P 11 0x12000 0x2000 21291d4093dSKevin Wolf echo read -P 1 0x14000 0x4000 21391d4093dSKevin Wolf echo read -P 10 0x18000 0x2000 21491d4093dSKevin Wolf echo read -P 1 0x1a000 0x2000 21591d4093dSKevin Wolf echo read -P 12 0x1c000 0x2000 21691d4093dSKevin Wolf echo read -P 1 0x1e000 0x2000 21791d4093dSKevin Wolf 21891d4093dSKevin Wolf echo read -P 2 0x20000 0x8000 21991d4093dSKevin Wolf echo read -P 20 0x28000 0x2000 22091d4093dSKevin Wolf echo read -P 21 0x2a000 0x10000 22191d4093dSKevin Wolf echo read -P 3 0x3a000 0x6000 22291d4093dSKevin Wolf 22391d4093dSKevin Wolf echo read -P 4 0x40000 0x8000 22491d4093dSKevin Wolf echo read -P 40 0x48000 0x2000 22591d4093dSKevin Wolf echo read -P 4 0x4a000 0x2000 22691d4093dSKevin Wolf echo read -P 41 0x4c000 0x10000 22791d4093dSKevin Wolf echo read -P 5 0x5c000 0x4000 22891d4093dSKevin Wolf 22991d4093dSKevin Wolf echo read -P 6 0x60000 0x6000 23091d4093dSKevin Wolf echo read -P 60 0x66000 0x2000 23191d4093dSKevin Wolf echo read -P 6 0x68000 0x2000 23291d4093dSKevin Wolf echo read -P 61 0x6a000 0xe000 23391d4093dSKevin Wolf echo read -P 70 0x78000 0x6000 23491d4093dSKevin Wolf echo read -P 7 0x7e000 0x2000 23591d4093dSKevin Wolf 23680f5c011SAlberto Garcia echo read -P ${discarded:-89} 0x80000 0x1000 23780f5c011SAlberto Garcia echo read -P ${discarded:-8} 0x81000 0x5000 23891d4093dSKevin Wolf echo read -P 80 0x86000 0x2000 239a71835a0SKevin Wolf echo read -P ${discarded:-8} 0x88000 0x2000 24091d4093dSKevin Wolf echo read -P 81 0x8a000 0xe000 24191d4093dSKevin Wolf echo read -P 90 0x98000 0x6000 24291d4093dSKevin Wolf echo read -P 9 0x9e000 0x2000 24391d4093dSKevin Wolf 24480f5c011SAlberto Garcia echo read -P ${discarded:-109} 0xa0000 0x1000 24580f5c011SAlberto Garcia echo read -P ${discarded:-10} 0xa1000 0x5000 24691d4093dSKevin Wolf echo read -P 100 0xa6000 0x2000 247a71835a0SKevin Wolf echo read -P ${discarded:-10} 0xa8000 0x2000 24891d4093dSKevin Wolf echo read -P 101 0xaa000 0xe000 24991d4093dSKevin Wolf echo read -P 110 0xb8000 0x8000 2506f749281SKevin Wolf 2516f749281SKevin Wolf echo read -P 12 0xc0000 0x4000 2526f749281SKevin Wolf echo read -P 120 0xc4000 0x18000 2536f749281SKevin Wolf echo read -P 121 0xdc000 0x2000 2546f749281SKevin Wolf echo read -P 13 0xde000 0x2000 2556f749281SKevin Wolf 2566f749281SKevin Wolf echo read -P 14 0xe0000 0x4000 2576f749281SKevin Wolf echo read -P 140 0xe4000 0x14000 2586f749281SKevin Wolf echo read -P 15 0xf8000 0x4000 2596f749281SKevin Wolf echo read -P 141 0xfc000 0x2000 2606f749281SKevin Wolf echo read -P 15 0xfe000 0x2000 2616f749281SKevin Wolf 2626f749281SKevin Wolf echo read -P 16 0x100000 0x4000 2636f749281SKevin Wolf echo read -P 160 0x104000 0x8000 2646f749281SKevin Wolf # Undefined content for 0x10c000 0x8000 2656f749281SKevin Wolf echo read -P 160 0x114000 0x8000 2666f749281SKevin Wolf echo read -P 17 0x11c000 0x4000 26791d4093dSKevin Wolf} 26891d4093dSKevin Wolf 269fef9c191SJeff Codyverify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 27091d4093dSKevin Wolf 27191d4093dSKevin Wolf_check_test_img 27291d4093dSKevin Wolf 27391d4093dSKevin Wolf# success, all done 27491d4093dSKevin Wolfecho "*** done" 27591d4093dSKevin Wolfrm -f $seq.full 27691d4093dSKevin Wolfstatus=0 277