common/rc: Add _require_{chown,chmod}()
[xfstests-dev.git] / tests / generic / 487
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018, Jeff Layton <jlayton@redhat.com>
4 #
5 # FS QA Test No. 487
6 #
7 # Open a file several times, write to it, fsync on all fds and make sure that
8 # they all return 0. Change the device to start throwing errors. Write again
9 # on all fds and fsync on all fds. Ensure that we get errors on all of them.
10 # Then fsync on all one last time and verify that all return 0.
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 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25         _dmerror_cleanup
26 }
27
28 # get standard environment, filters and checks
29 . ./common/rc
30 . ./common/filter
31 . ./common/dmerror
32
33 # real QA test starts here
34 _require_scratch_nocheck
35
36 sflag='-s'
37 case $FSTYP in
38         btrfs)
39                 _notrun "btrfs has a specialized test for this"
40                 ;;
41         *)
42                 ;;
43 esac
44
45 _require_logdev
46 _require_dm_target error
47
48 rm -f $seqres.full
49
50 # Disable the scratch rt device to avoid test failures relating to the rt
51 # bitmap consuming all the free space in our small data device.
52 unset SCRATCH_RTDEV
53
54 echo "Format and mount"
55 _scratch_mkfs > $seqres.full 2>&1
56 _dmerror_init
57 _dmerror_mount
58
59 datalen=65536
60 _require_fs_space $SCRATCH_MNT $datalen
61
62 # use fd 5 to hold file open
63 testfile=$SCRATCH_MNT/fsync-open-after-err
64 exec 5>$testfile
65
66 # write some data to file and fsync it out
67 $XFS_IO_PROG -c "pwrite -q 0 $datalen" -c fsync $testfile
68
69 # flip device to non-working mode
70 _dmerror_load_error_table
71
72 # rewrite the data, call sync to ensure it's written back w/o scraping error
73 $XFS_IO_PROG -c "pwrite -q 0 $datalen" -c sync $testfile
74
75 # heal the device error
76 _dmerror_load_working_table
77
78 # open again and call fsync
79 echo "The following fsync should fail with EIO:"
80 $XFS_IO_PROG -c fsync $testfile
81 echo "done"
82
83 # close file
84 exec 5>&-
85
86 # success, all done
87 _dmerror_cleanup
88
89 status=0
90 exit