1#!/bin/bash 2# 3# Test concurrent pread/pwrite 4# 5# Copyright (C) 2014 Red Hat, Inc. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program. If not, see <http://www.gnu.org/licenses/>. 19# 20 21# creator 22owner=kwolf@redhat.com 23 24seq=`basename $0` 25echo "QA output created by $seq" 26 27here=`pwd` 28tmp=/tmp/$$ 29status=1 # failure is the default! 30 31_cleanup() 32{ 33 _cleanup_test_img 34} 35trap "_cleanup; exit \$status" 0 1 2 3 15 36 37# get standard environment, filters and checks 38. ./common.rc 39. ./common.filter 40 41_supported_fmt raw 42_supported_proto generic 43_supported_os Linux 44 45CLUSTER_SIZE=4k 46size=128M 47 48_make_test_img $size 49 50echo 51echo "== Some concurrent requests involving RMW ==" 52 53function test_io() 54{ 55echo "open -o driver=$IMGFMT,file.align=4k blkdebug::$TEST_IMG" 56# A simple RMW request 57cat <<EOF 58aio_write -P 10 0x200 0x200 59aio_flush 60EOF 61 62# Sequential RMW requests on the same physical sector 63off=0x1000 64for ev in "head" "after_head" "tail" "after_tail"; do 65cat <<EOF 66break pwritev_rmw_$ev A 67aio_write -P 10 $((off + 0x200)) 0x200 68wait_break A 69aio_write -P 11 $((off + 0x400)) 0x200 70sleep 100 71resume A 72aio_flush 73EOF 74off=$((off + 0x1000)) 75done 76 77# Chained dependencies 78cat <<EOF 79break pwritev_rmw_after_tail A 80aio_write -P 10 0x5000 0x200 81wait_break A 82aio_write -P 11 0x5200 0x200 83aio_write -P 12 0x5400 0x200 84aio_write -P 13 0x5600 0x200 85aio_write -P 14 0x5800 0x200 86aio_write -P 15 0x5a00 0x200 87aio_write -P 16 0x5c00 0x200 88aio_write -P 17 0x5e00 0x200 89sleep 100 90resume A 91aio_flush 92EOF 93 94# Overlapping multiple requests 95cat <<EOF 96break pwritev_rmw_after_tail A 97aio_write -P 10 0x6000 0x200 98wait_break A 99break pwritev_rmw_after_head B 100aio_write -P 10 0x7e00 0x200 101wait_break B 102aio_write -P 11 0x6800 0x1000 103resume A 104sleep 100 105resume B 106aio_flush 107EOF 108 109cat <<EOF 110break pwritev_rmw_after_tail A 111aio_write -P 10 0x8000 0x200 112wait_break A 113break pwritev_rmw_after_head B 114aio_write -P 10 0x9e00 0x200 115wait_break B 116aio_write -P 11 0x8800 0x1000 117resume B 118sleep 100 119resume A 120aio_flush 121EOF 122 123cat <<EOF 124break pwritev_rmw_after_tail A 125aio_write -P 10 0xa000 0x200 126wait_break A 127aio_write -P 11 0xa800 0x1000 128break pwritev_rmw_after_head B 129aio_write -P 10 0xbe00 0x200 130wait_break B 131resume A 132sleep 100 133resume B 134aio_flush 135EOF 136 137cat <<EOF 138break pwritev_rmw_after_tail A 139aio_write -P 10 0xc000 0x200 140wait_break A 141aio_write -P 11 0xc800 0x1000 142break pwritev_rmw_after_head B 143aio_write -P 10 0xde00 0x200 144wait_break B 145resume B 146sleep 100 147resume A 148aio_flush 149EOF 150 151# Only RMW for the tail part 152cat <<EOF 153break pwritev_rmw_after_tail A 154aio_write -P 10 0xe000 0x1800 155wait_break A 156aio_write -P 11 0xf000 0xc00 157sleep 100 158resume A 159aio_flush 160EOF 161 162cat <<EOF 163break pwritev A 164aio_write -P 10 0x10000 0x800 165wait_break A 166break pwritev_rmw_after_tail B 167aio_write -P 11 0x10000 0x400 168break pwritev_done C 169resume A 170wait_break C 171resume C 172sleep 100 173wait_break B 174resume B 175aio_flush 176EOF 177 178cat <<EOF 179break pwritev A 180aio_write -P 10 0x11000 0x800 181wait_break A 182aio_write -P 11 0x11000 0x1000 183sleep 100 184resume A 185aio_flush 186EOF 187} 188 189test_io | $QEMU_IO | _filter_qemu_io | \ 190 sed -e 's,[0-9/]* bytes at offset [0-9]*,XXX/XXX bytes at offset XXX,g' \ 191 -e 's/^[0-9]* \(bytes\|KiB\)/XXX bytes/' \ 192 -e '/Suspended/d' 193 194echo 195echo "== Verify image content ==" 196 197function verify_io() 198{ 199 # A simple RMW request 200 echo read -P 0 0 0x200 201 echo read -P 10 0x200 0x200 202 echo read -P 0 0x400 0xc00 203 204 # Sequential RMW requests on the same physical sector 205 echo read -P 0 0x1000 0x200 206 echo read -P 10 0x1200 0x200 207 echo read -P 11 0x1400 0x200 208 echo read -P 0 0x1600 0xa00 209 210 echo read -P 0 0x2000 0x200 211 echo read -P 10 0x2200 0x200 212 echo read -P 11 0x2400 0x200 213 echo read -P 0 0x2600 0xa00 214 215 echo read -P 0 0x3000 0x200 216 echo read -P 10 0x3200 0x200 217 echo read -P 11 0x3400 0x200 218 echo read -P 0 0x3600 0xa00 219 220 echo read -P 0 0x4000 0x200 221 echo read -P 10 0x4200 0x200 222 echo read -P 11 0x4400 0x200 223 echo read -P 0 0x4600 0xa00 224 225 # Chained dependencies 226 echo read -P 10 0x5000 0x200 227 echo read -P 11 0x5200 0x200 228 echo read -P 12 0x5400 0x200 229 echo read -P 13 0x5600 0x200 230 echo read -P 14 0x5800 0x200 231 echo read -P 15 0x5a00 0x200 232 echo read -P 16 0x5c00 0x200 233 echo read -P 17 0x5e00 0x200 234 235 # Overlapping multiple requests 236 echo read -P 10 0x6000 0x200 237 echo read -P 0 0x6200 0x600 238 echo read -P 11 0x6800 0x1000 239 echo read -P 0 0x7800 0x600 240 echo read -P 10 0x7e00 0x200 241 242 echo read -P 10 0x8000 0x200 243 echo read -P 0 0x8200 0x600 244 echo read -P 11 0x8800 0x1000 245 echo read -P 0 0x9800 0x600 246 echo read -P 10 0x9e00 0x200 247 248 echo read -P 10 0xa000 0x200 249 echo read -P 0 0xa200 0x600 250 echo read -P 11 0xa800 0x1000 251 echo read -P 0 0xb800 0x600 252 echo read -P 10 0xbe00 0x200 253 254 echo read -P 10 0xc000 0x200 255 echo read -P 0 0xc200 0x600 256 echo read -P 11 0xc800 0x1000 257 echo read -P 0 0xd800 0x600 258 echo read -P 10 0xde00 0x200 259 260 # Only RMW for the tail part 261 echo read -P 10 0xe000 0x1000 262 echo read -P 11 0xf800 0x400 263 echo read -P 0 0xfc00 0x400 264 265 echo read -P 11 0x10000 0x400 266 echo read -P 10 0x10400 0x400 267 268 echo read -P 11 0x11800 0x800 269} 270 271verify_io | $QEMU_IO "$TEST_IMG" | _filter_qemu_io 272 273_check_test_img 274 275# success, all done 276echo "*** done" 277rm -f $seq.full 278status=0 279