generic: test reporting of wb errors via syncfs
[xfstests-dev.git] / tests / generic / 484
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2020, Jeff Layton. All rights reserved.
4 # FS QA Test No. 484
5 #
6 # Open a file and write to it and fsync. Then, flip the data device to throw
7 # errors, write to it again and do an fdatasync. Then open an O_RDONLY fd on
8 # the same file and call syncfs against it and ensure that an error is reported.
9 # Then call syncfs again and ensure that no error is reported. Finally, repeat
10 # the open and syncfs and ensure that there is no error reported.
11 #
12 # Kernel with the following patches should pass the test:
13 #
14 #    vfs: track per-sb writeback errors and report them to syncfs
15 #    buffer: record blockdev write errors in super_block that it backs
16
17 seq=`basename $0`
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
20
21 here=`pwd`
22 tmp=/tmp/$$
23 status=1    # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
25
26 _cleanup()
27 {
28         cd /
29         rm -f $tmp.*
30         _dmerror_cleanup
31 }
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36 . ./common/dmerror
37
38 # real QA test starts here
39 _supported_os Linux
40 _require_scratch_nocheck
41 # This test uses "dm" without taking into account the data could be on
42 # realtime subvolume, thus the test will fail with rtinherit=1
43 _require_no_rtinherit
44 _require_dm_target error
45
46 rm -f $seqres.full
47
48 echo "Format and mount"
49 _scratch_mkfs > $seqres.full 2>&1
50 _dmerror_init
51 _dmerror_mount
52
53
54 # create file
55 testfile=$SCRATCH_MNT/syncfs-reports-errors
56 touch $testfile
57
58 # write a page of data to file, and call fsync
59 datalen=$(getconf PAGE_SIZE)
60 $XFS_IO_PROG -c "pwrite -W -q 0 $datalen" $testfile
61
62 # flip device to non-working mode
63 _dmerror_load_error_table
64
65 # rewrite the data and call fdatasync
66 $XFS_IO_PROG -c "pwrite -w -q 0 $datalen" $testfile
67
68 # heal the device error
69 _dmerror_load_working_table
70
71 # open again and call syncfs twice
72 echo "One of the following syncfs calls should fail with EIO:"
73 $XFS_IO_PROG -r -c syncfs -c syncfs $testfile
74 echo "done"
75
76 echo "This syncfs call should succeed:"
77 $XFS_IO_PROG -r -c syncfs $testfile
78 echo "done"
79
80 # success, all done
81 _dmerror_cleanup
82
83 status=0
84 exit