1*11a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash 29e1cb96dSKevin Wolf# 39e1cb96dSKevin Wolf# Test concurrent pread/pwrite 49e1cb96dSKevin Wolf# 59e1cb96dSKevin Wolf# Copyright (C) 2014 Red Hat, Inc. 69e1cb96dSKevin Wolf# 79e1cb96dSKevin Wolf# This program is free software; you can redistribute it and/or modify 89e1cb96dSKevin Wolf# it under the terms of the GNU General Public License as published by 99e1cb96dSKevin Wolf# the Free Software Foundation; either version 2 of the License, or 109e1cb96dSKevin Wolf# (at your option) any later version. 119e1cb96dSKevin Wolf# 129e1cb96dSKevin Wolf# This program is distributed in the hope that it will be useful, 139e1cb96dSKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of 149e1cb96dSKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 159e1cb96dSKevin Wolf# GNU General Public License for more details. 169e1cb96dSKevin Wolf# 179e1cb96dSKevin Wolf# You should have received a copy of the GNU General Public License 189e1cb96dSKevin Wolf# along with this program. If not, see <http://www.gnu.org/licenses/>. 199e1cb96dSKevin Wolf# 209e1cb96dSKevin Wolf 219e1cb96dSKevin Wolf# creator 229e1cb96dSKevin Wolfowner=kwolf@redhat.com 239e1cb96dSKevin Wolf 249e1cb96dSKevin Wolfseq=`basename $0` 259e1cb96dSKevin Wolfecho "QA output created by $seq" 269e1cb96dSKevin Wolf 279e1cb96dSKevin Wolfstatus=1 # failure is the default! 289e1cb96dSKevin Wolf 299e1cb96dSKevin Wolf_cleanup() 309e1cb96dSKevin Wolf{ 319e1cb96dSKevin Wolf _cleanup_test_img 329e1cb96dSKevin Wolf} 339e1cb96dSKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 349e1cb96dSKevin Wolf 359e1cb96dSKevin Wolf# get standard environment, filters and checks 369e1cb96dSKevin Wolf. ./common.rc 379e1cb96dSKevin Wolf. ./common.filter 389e1cb96dSKevin Wolf 39f5106206SKevin Wolf_supported_fmt raw 409e1cb96dSKevin Wolf_supported_proto generic 419e1cb96dSKevin Wolf_supported_os Linux 429e1cb96dSKevin Wolf 439e1cb96dSKevin WolfCLUSTER_SIZE=4k 449e1cb96dSKevin Wolfsize=128M 459e1cb96dSKevin Wolf 469e1cb96dSKevin Wolf_make_test_img $size 479e1cb96dSKevin Wolf 489e1cb96dSKevin Wolfecho 499e1cb96dSKevin Wolfecho "== Some concurrent requests involving RMW ==" 509e1cb96dSKevin Wolf 518cedcffdSEric Blaketest_io() 529e1cb96dSKevin Wolf{ 538f9e835fSKevin Wolfecho "open -o driver=$IMGFMT,file.align=4k blkdebug::$TEST_IMG" 549e1cb96dSKevin Wolf# A simple RMW request 559e1cb96dSKevin Wolfcat <<EOF 569e1cb96dSKevin Wolfaio_write -P 10 0x200 0x200 579e1cb96dSKevin Wolfaio_flush 589e1cb96dSKevin WolfEOF 599e1cb96dSKevin Wolf 609e1cb96dSKevin Wolf# Sequential RMW requests on the same physical sector 619e1cb96dSKevin Wolfoff=0x1000 62117bc3faSPeter Lievenfor ev in "head" "after_head"; do 639e1cb96dSKevin Wolfcat <<EOF 645be5b776SEric Blakebreak pwritev_rmw_$ev A 659e1cb96dSKevin Wolfaio_write -P 10 $((off + 0x200)) 0x200 669e1cb96dSKevin Wolfwait_break A 679e1cb96dSKevin Wolfaio_write -P 11 $((off + 0x400)) 0x200 689e1cb96dSKevin Wolfsleep 100 699e1cb96dSKevin Wolfresume A 709e1cb96dSKevin Wolfaio_flush 719e1cb96dSKevin WolfEOF 729e1cb96dSKevin Wolfoff=$((off + 0x1000)) 739e1cb96dSKevin Wolfdone 749e1cb96dSKevin Wolf 759e1cb96dSKevin Wolf# Chained dependencies 769e1cb96dSKevin Wolfcat <<EOF 775be5b776SEric Blakebreak pwritev_rmw_after_tail A 789e1cb96dSKevin Wolfaio_write -P 10 0x5000 0x200 799e1cb96dSKevin Wolfwait_break A 809e1cb96dSKevin Wolfaio_write -P 11 0x5200 0x200 819e1cb96dSKevin Wolfaio_write -P 12 0x5400 0x200 829e1cb96dSKevin Wolfaio_write -P 13 0x5600 0x200 839e1cb96dSKevin Wolfaio_write -P 14 0x5800 0x200 849e1cb96dSKevin Wolfaio_write -P 15 0x5a00 0x200 859e1cb96dSKevin Wolfaio_write -P 16 0x5c00 0x200 869e1cb96dSKevin Wolfaio_write -P 17 0x5e00 0x200 879e1cb96dSKevin Wolfsleep 100 889e1cb96dSKevin Wolfresume A 899e1cb96dSKevin Wolfaio_flush 909e1cb96dSKevin WolfEOF 919e1cb96dSKevin Wolf 929e1cb96dSKevin Wolf# Overlapping multiple requests 939e1cb96dSKevin Wolfcat <<EOF 945be5b776SEric Blakebreak pwritev_rmw_after_tail A 959e1cb96dSKevin Wolfaio_write -P 10 0x6000 0x200 969e1cb96dSKevin Wolfwait_break A 975be5b776SEric Blakebreak pwritev_rmw_after_head B 989e1cb96dSKevin Wolfaio_write -P 10 0x7e00 0x200 999e1cb96dSKevin Wolfwait_break B 1009e1cb96dSKevin Wolfaio_write -P 11 0x6800 0x1000 1019e1cb96dSKevin Wolfresume A 1029e1cb96dSKevin Wolfsleep 100 1039e1cb96dSKevin Wolfresume B 1049e1cb96dSKevin Wolfaio_flush 1059e1cb96dSKevin WolfEOF 1069e1cb96dSKevin Wolf 1079e1cb96dSKevin Wolfcat <<EOF 1085be5b776SEric Blakebreak pwritev_rmw_after_tail A 1099e1cb96dSKevin Wolfaio_write -P 10 0x8000 0x200 1109e1cb96dSKevin Wolfwait_break A 1115be5b776SEric Blakebreak pwritev_rmw_after_head B 1129e1cb96dSKevin Wolfaio_write -P 10 0x9e00 0x200 1139e1cb96dSKevin Wolfwait_break B 1149e1cb96dSKevin Wolfaio_write -P 11 0x8800 0x1000 1159e1cb96dSKevin Wolfresume B 1169e1cb96dSKevin Wolfsleep 100 1179e1cb96dSKevin Wolfresume A 1189e1cb96dSKevin Wolfaio_flush 1199e1cb96dSKevin WolfEOF 1209e1cb96dSKevin Wolf 1219e1cb96dSKevin Wolfcat <<EOF 1225be5b776SEric Blakebreak pwritev_rmw_after_tail A 1239e1cb96dSKevin Wolfaio_write -P 10 0xa000 0x200 1249e1cb96dSKevin Wolfwait_break A 1259e1cb96dSKevin Wolfaio_write -P 11 0xa800 0x1000 1265be5b776SEric Blakebreak pwritev_rmw_after_head B 1279e1cb96dSKevin Wolfaio_write -P 10 0xbe00 0x200 1289e1cb96dSKevin Wolfwait_break B 1299e1cb96dSKevin Wolfresume A 1309e1cb96dSKevin Wolfsleep 100 1319e1cb96dSKevin Wolfresume B 1329e1cb96dSKevin Wolfaio_flush 1339e1cb96dSKevin WolfEOF 1349e1cb96dSKevin Wolf 1359e1cb96dSKevin Wolfcat <<EOF 1365be5b776SEric Blakebreak pwritev_rmw_after_tail A 1379e1cb96dSKevin Wolfaio_write -P 10 0xc000 0x200 1389e1cb96dSKevin Wolfwait_break A 1399e1cb96dSKevin Wolfaio_write -P 11 0xc800 0x1000 1405be5b776SEric Blakebreak pwritev_rmw_after_head B 1419e1cb96dSKevin Wolfaio_write -P 10 0xde00 0x200 1429e1cb96dSKevin Wolfwait_break B 1439e1cb96dSKevin Wolfresume B 1449e1cb96dSKevin Wolfsleep 100 1459e1cb96dSKevin Wolfresume A 1469e1cb96dSKevin Wolfaio_flush 1479e1cb96dSKevin WolfEOF 1489e1cb96dSKevin Wolf 1499e1cb96dSKevin Wolf# Only RMW for the tail part 1509e1cb96dSKevin Wolfcat <<EOF 1515be5b776SEric Blakebreak pwritev_rmw_after_tail A 1529e1cb96dSKevin Wolfaio_write -P 10 0xe000 0x1800 1539e1cb96dSKevin Wolfwait_break A 1549e1cb96dSKevin Wolfaio_write -P 11 0xf000 0xc00 1559e1cb96dSKevin Wolfsleep 100 1569e1cb96dSKevin Wolfresume A 1579e1cb96dSKevin Wolfaio_flush 1589e1cb96dSKevin WolfEOF 1599e1cb96dSKevin Wolf 1609e1cb96dSKevin Wolfcat <<EOF 1619e1cb96dSKevin Wolfbreak pwritev A 1629e1cb96dSKevin Wolfaio_write -P 10 0x10000 0x800 1639e1cb96dSKevin Wolfwait_break A 1645be5b776SEric Blakebreak pwritev_rmw_after_tail B 1659e1cb96dSKevin Wolfaio_write -P 11 0x10000 0x400 1669e1cb96dSKevin Wolfbreak pwritev_done C 1679e1cb96dSKevin Wolfresume A 1689e1cb96dSKevin Wolfwait_break C 1699e1cb96dSKevin Wolfresume C 1709e1cb96dSKevin Wolfsleep 100 1719e1cb96dSKevin Wolfwait_break B 1729e1cb96dSKevin Wolfresume B 1739e1cb96dSKevin Wolfaio_flush 1749e1cb96dSKevin WolfEOF 1759e1cb96dSKevin Wolf 1769e1cb96dSKevin Wolfcat <<EOF 1779e1cb96dSKevin Wolfbreak pwritev A 1789e1cb96dSKevin Wolfaio_write -P 10 0x11000 0x800 1799e1cb96dSKevin Wolfwait_break A 1809e1cb96dSKevin Wolfaio_write -P 11 0x11000 0x1000 1819e1cb96dSKevin Wolfsleep 100 1829e1cb96dSKevin Wolfresume A 1839e1cb96dSKevin Wolfaio_flush 1849e1cb96dSKevin WolfEOF 1859e1cb96dSKevin Wolf} 1869e1cb96dSKevin Wolf 1879e1cb96dSKevin Wolftest_io | $QEMU_IO | _filter_qemu_io | \ 1889e1cb96dSKevin Wolf sed -e 's,[0-9/]* bytes at offset [0-9]*,XXX/XXX bytes at offset XXX,g' \ 1899e1cb96dSKevin Wolf -e 's/^[0-9]* \(bytes\|KiB\)/XXX bytes/' \ 190d04c1555SFam Zheng -e '/Suspended/d' \ 191d04c1555SFam Zheng -e '/blkdebug: Resuming request/d' 1929e1cb96dSKevin Wolf 1939e1cb96dSKevin Wolfecho 1949e1cb96dSKevin Wolfecho "== Verify image content ==" 1959e1cb96dSKevin Wolf 1968cedcffdSEric Blakeverify_io() 1979e1cb96dSKevin Wolf{ 1989e1cb96dSKevin Wolf # A simple RMW request 1999e1cb96dSKevin Wolf echo read -P 0 0 0x200 2009e1cb96dSKevin Wolf echo read -P 10 0x200 0x200 2019e1cb96dSKevin Wolf echo read -P 0 0x400 0xc00 2029e1cb96dSKevin Wolf 2039e1cb96dSKevin Wolf # Sequential RMW requests on the same physical sector 2049e1cb96dSKevin Wolf echo read -P 0 0x1000 0x200 2059e1cb96dSKevin Wolf echo read -P 10 0x1200 0x200 2069e1cb96dSKevin Wolf echo read -P 11 0x1400 0x200 2079e1cb96dSKevin Wolf echo read -P 0 0x1600 0xa00 2089e1cb96dSKevin Wolf 2099e1cb96dSKevin Wolf echo read -P 0 0x2000 0x200 2109e1cb96dSKevin Wolf echo read -P 10 0x2200 0x200 2119e1cb96dSKevin Wolf echo read -P 11 0x2400 0x200 2129e1cb96dSKevin Wolf echo read -P 0 0x2600 0xa00 2139e1cb96dSKevin Wolf 2149e1cb96dSKevin Wolf # Chained dependencies 2159e1cb96dSKevin Wolf echo read -P 10 0x5000 0x200 2169e1cb96dSKevin Wolf echo read -P 11 0x5200 0x200 2179e1cb96dSKevin Wolf echo read -P 12 0x5400 0x200 2189e1cb96dSKevin Wolf echo read -P 13 0x5600 0x200 2199e1cb96dSKevin Wolf echo read -P 14 0x5800 0x200 2209e1cb96dSKevin Wolf echo read -P 15 0x5a00 0x200 2219e1cb96dSKevin Wolf echo read -P 16 0x5c00 0x200 2229e1cb96dSKevin Wolf echo read -P 17 0x5e00 0x200 2239e1cb96dSKevin Wolf 2249e1cb96dSKevin Wolf # Overlapping multiple requests 2259e1cb96dSKevin Wolf echo read -P 10 0x6000 0x200 2269e1cb96dSKevin Wolf echo read -P 0 0x6200 0x600 2279e1cb96dSKevin Wolf echo read -P 11 0x6800 0x1000 2289e1cb96dSKevin Wolf echo read -P 0 0x7800 0x600 2299e1cb96dSKevin Wolf echo read -P 10 0x7e00 0x200 2309e1cb96dSKevin Wolf 2319e1cb96dSKevin Wolf echo read -P 10 0x8000 0x200 2329e1cb96dSKevin Wolf echo read -P 0 0x8200 0x600 2339e1cb96dSKevin Wolf echo read -P 11 0x8800 0x1000 2349e1cb96dSKevin Wolf echo read -P 0 0x9800 0x600 2359e1cb96dSKevin Wolf echo read -P 10 0x9e00 0x200 2369e1cb96dSKevin Wolf 2379e1cb96dSKevin Wolf echo read -P 10 0xa000 0x200 2389e1cb96dSKevin Wolf echo read -P 0 0xa200 0x600 2399e1cb96dSKevin Wolf echo read -P 11 0xa800 0x1000 2409e1cb96dSKevin Wolf echo read -P 0 0xb800 0x600 2419e1cb96dSKevin Wolf echo read -P 10 0xbe00 0x200 2429e1cb96dSKevin Wolf 2439e1cb96dSKevin Wolf echo read -P 10 0xc000 0x200 2449e1cb96dSKevin Wolf echo read -P 0 0xc200 0x600 2459e1cb96dSKevin Wolf echo read -P 11 0xc800 0x1000 2469e1cb96dSKevin Wolf echo read -P 0 0xd800 0x600 2479e1cb96dSKevin Wolf echo read -P 10 0xde00 0x200 2489e1cb96dSKevin Wolf 2499e1cb96dSKevin Wolf # Only RMW for the tail part 2509e1cb96dSKevin Wolf echo read -P 10 0xe000 0x1000 2519e1cb96dSKevin Wolf echo read -P 11 0xf800 0x400 2529e1cb96dSKevin Wolf echo read -P 0 0xfc00 0x400 2539e1cb96dSKevin Wolf 2549e1cb96dSKevin Wolf echo read -P 11 0x10000 0x400 2559e1cb96dSKevin Wolf echo read -P 10 0x10400 0x400 2569e1cb96dSKevin Wolf 2579e1cb96dSKevin Wolf echo read -P 11 0x11800 0x800 2589e1cb96dSKevin Wolf} 2599e1cb96dSKevin Wolf 2609e1cb96dSKevin Wolfverify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 2619e1cb96dSKevin Wolf 2629e1cb96dSKevin Wolf_check_test_img 2639e1cb96dSKevin Wolf 2649e1cb96dSKevin Wolf# success, all done 2659e1cb96dSKevin Wolfecho "*** done" 2669e1cb96dSKevin Wolfrm -f $seq.full 2679e1cb96dSKevin Wolfstatus=0 268