misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 471
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, SUSE Linux Products.  All Rights Reserved.
4 #
5 # FS QA Test No. 471
6 #
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.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19
20 # get standard environment, filters and checks
21 . ./common/rc
22 . ./common/populate
23 . ./common/filter
24 . ./common/attr
25
26 # real QA test starts here
27 _require_odirect
28 _require_test
29 _require_xfs_io_command pwrite -N
30
31 # Remove reminiscence of previously run tests
32 testdir=$TEST_DIR/$seq
33 if [ -e $testdir ]; then
34         rm -Rf $testdir
35 fi
36
37 mkdir $testdir
38
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
45         _require_chattr C
46         touch $testdir/f1
47         $CHATTR_PROG +C $testdir/f1
48 fi
49
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
52
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
55
56 time_taken=`$XFS_IO_PROG -d -c "pwrite -S 0xbb -N -V 1 -b 1M 2M 1M" $testdir/f1 | awk '/^1/ {print $5}'`
57
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."
63 else
64         echo "RWF_NOWAIT took $time_taken seconds"
65 fi
66
67 $XFS_IO_PROG -c "pread -v 0 8M" $testdir/f1 | _filter_xfs_io_unique
68
69 # success, all done
70 status=0
71 exit