xfs: make sure syncfs(2) passes back super_operations.sync_fs errors
[xfstests-dev.git] / tests / xfs / 546
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2022 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 546
6 #
7 # Regression test for kernel commits:
8 #
9 # 5679897eb104 ("vfs: make sync_filesystem return errors from ->sync_fs")
10 # 2d86293c7075 ("xfs: return errors in xfs_fs_sync_fs")
11 #
12 # During a code inspection, I noticed that sync_filesystem ignores the return
13 # value of the ->sync_fs calls that it makes.  sync_filesystem, in turn is used
14 # by the syncfs(2) syscall to persist filesystem changes to disk.  This means
15 # that syncfs(2) does not capture internal filesystem errors that are neither
16 # visible from the block device (e.g. media error) nor recorded in s_wb_err.
17 # XFS historically returned 0 from ->sync_fs even if there were log failures,
18 # so that had to be corrected as well.
19 #
20 # The kernel commits above fix this problem, so this test tries to trigger the
21 # bug by using the shutdown ioctl on a clean, freshly mounted filesystem in the
22 # hope that the EIO generated as a result of the filesystem being shut down is
23 # only visible via ->sync_fs.
24 #
25 . ./common/preamble
26 _begin_fstest auto quick shutdown
27
28 # real QA test starts here
29
30 # Modify as appropriate.
31 _supported_fs xfs
32 _require_xfs_io_command syncfs
33 _require_scratch_nocheck
34 _require_scratch_shutdown
35
36 # Reuse the fs formatted when we checked for the shutdown ioctl, and don't
37 # bother checking the filesystem afterwards since we never wrote anything.
38 _scratch_mount
39 $XFS_IO_PROG -x -c 'shutdown -f ' -c syncfs $SCRATCH_MNT
40
41 # success, all done
42 status=0
43 exit