2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2020, Jeff Layton. All rights reserved.
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.
12 # Kernel with the following patches should pass the test:
14 # vfs: track per-sb writeback errors and report them to syncfs
15 # buffer: record blockdev write errors in super_block that it backs
18 seqres=$RESULT_DIR/$seq
19 echo "QA output created by $seq"
23 status=1 # failure is the default!
24 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # get standard environment, filters and checks
38 # real QA test starts here
39 _require_scratch_nocheck
40 _require_dm_target error
41 _require_xfs_io_command "syncfs"
45 # Disable the scratch rt device to avoid test failures relating to the rt
46 # bitmap consuming all the free space in our small data device.
49 echo "Format and mount"
50 _scratch_mkfs > $seqres.full 2>&1
56 testfile=$SCRATCH_MNT/syncfs-reports-errors
59 # write a page of data to file, and call fsync
60 datalen=$(getconf PAGE_SIZE)
61 $XFS_IO_PROG -c "pwrite -W -q 0 $datalen" $testfile
63 # flip device to non-working mode
64 _dmerror_load_error_table
66 # rewrite the data and call fdatasync
67 $XFS_IO_PROG -c "pwrite -w -q 0 $datalen" $testfile
69 # heal the device error
70 _dmerror_load_working_table
72 # open again and call syncfs twice
73 echo "One of the following syncfs calls should fail with EIO:"
74 $XFS_IO_PROG -r -c syncfs -c syncfs $testfile
77 echo "This syncfs call should succeed:"
78 $XFS_IO_PROG -r -c syncfs $testfile