2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, SUSE Linux Products. All Rights Reserved.
7 # write a file with RWF_NOWAIT and it would fail because there are no
8 # blocks allocated. Create a file with direct I/O and re-write it
9 # using RWF_NOWAIT. I/O should finish within 50 microsecods since
10 # block allocations are already performed.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
20 # get standard environment, filters and checks
26 # real QA test starts here
29 _require_xfs_io_command pwrite -N
31 # Remove reminiscence of previously run tests
32 testdir=$TEST_DIR/$seq
33 if [ -e $testdir ]; then
39 # Btrfs is a COW filesystem, so a RWF_NOWAIT write will always fail with -EAGAIN
40 # when writing to a file range except if it's a NOCOW file and an extent for the
41 # range already exists or if it's a COW file and preallocated/unwritten extent
42 # exists in the target range. So to make sure that the last write succeeds on
43 # all filesystems, use a NOCOW file on btrfs.
44 if [ $FSTYP == "btrfs" ]; then
47 $CHATTR_PROG +C $testdir/f1
50 # Create a file with pwrite nowait (will fail with EAGAIN)
51 $XFS_IO_PROG -f -d -c "pwrite -N -V 1 -b 1M 0 1M" $testdir/f1
53 # Write the file without nowait
54 $XFS_IO_PROG -f -d -c "pwrite -S 0xaa -W -w -V 1 -b 1M 0 8M" $testdir/f1 | _filter_xfs_io
56 time_taken=`$XFS_IO_PROG -d -c "pwrite -S 0xbb -N -V 1 -b 1M 2M 1M" $testdir/f1 | awk '/^1/ {print $5}'`
58 # RWF_NOWAIT should finish within a short period of time so we are choosing
59 # a conservative value of 50 ms. Anything longer means it is waiting
60 # for something in the kernel which would be a fail.
61 if (( $(echo "$time_taken < 0.05" | bc -l) )); then
62 echo "RWF_NOWAIT time is within limits."
64 echo "RWF_NOWAIT took $time_taken seconds"
67 $XFS_IO_PROG -c "pread -v 0 8M" $testdir/f1 | _filter_xfs_io_unique