generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
18 _begin_fstest auto quick
19
20 # Override the default cleanup function.
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25         _dmerror_cleanup
26 }
27
28 # Import common functions.
29 . ./common/filter
30 . ./common/dmerror
31
32 # real QA test starts here
33 _require_scratch_nocheck
34 _require_dm_target error
35 _require_xfs_io_command "syncfs"
36
37 # Disable the scratch rt device to avoid test failures relating to the rt
38 # bitmap consuming all the free space in our small data device.
39 unset SCRATCH_RTDEV
40
41 echo "Format and mount"
42 _scratch_mkfs > $seqres.full 2>&1
43 _dmerror_init
44 _dmerror_mount
45
46 # create file
47 testfile=$SCRATCH_MNT/syncfs-reports-errors
48 touch $testfile
49
50 # write a page of data to file, and call fsync
51 datalen=$(getconf PAGE_SIZE)
52 $XFS_IO_PROG -c "pwrite -W -q 0 $datalen" $testfile
53
54 # flip device to non-working mode
55 _dmerror_load_error_table
56
57 # rewrite the data and call fdatasync
58 $XFS_IO_PROG -c "pwrite -w -q 0 $datalen" $testfile
59
60 # heal the device error
61 _dmerror_load_working_table
62
63 # open again and call syncfs twice
64 echo "One of the following syncfs calls should fail with EIO:"
65 $XFS_IO_PROG -r -c syncfs -c syncfs $testfile
66 echo "done"
67
68 echo "This syncfs call should succeed:"
69 $XFS_IO_PROG -r -c syncfs $testfile
70 echo "done"
71
72 # success, all done
73 _dmerror_cleanup
74
75 status=0
76 exit