generic: test reporting of wb errors via syncfs

Add a test for new syncfs error reporting behavior. When an inode fails
to be written back, ensure that a subsequent call to syncfs() will also
report an error.

This behavior is currently dependent on this patchset being merged:

    vfs: have syncfs() return error when there are writeback errors

Signed-off-by: Jeff Layton <>
diff --git a/tests/generic/999 b/tests/generic/999
new file mode 100755
index 0000000..7443b4c
--- /dev/null
+++ b/tests/generic/999
@@ -0,0 +1,80 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2020, Jeff Layton. All rights reserved.
+# FS QA Test No. 999
+# Open a file and write to it and fsync. Then, flip the data device to throw
+# errors, write to it again and do an fdatasync. Then open an O_RDONLY fd on
+# the same file and call syncfs against it and ensure that an error is reported.
+# Then call syncfs again and ensure that no error is reported. Finally, repeat
+# the open and syncfs and ensure that there is no error reported.
+seq=`basename $0`
+echo "QA output created by $seq"
+status=1    # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+	cd /
+	rm -f $tmp.*
+	_dmerror_cleanup
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+. ./common/dmerror
+# real QA test starts here
+_supported_os Linux
+# This test uses "dm" without taking into account the data could be on
+# realtime subvolume, thus the test will fail with rtinherit=1
+_require_dm_target error
+rm -f $seqres.full
+echo "Format and mount"
+_scratch_mkfs > $seqres.full 2>&1
+_require_fs_space $SCRATCH_MNT $datalen
+# create file
+touch $testfile
+# write some data to file and fsync it out
+$XFS_IO_PROG -c "pwrite -W -q 0 $datalen" $testfile
+# flip device to non-working mode
+# rewrite the data, and do fdatasync
+$XFS_IO_PROG -c "pwrite -w -q 0 $datalen" $testfile
+# heal the device error
+# open again and call syncfs twice
+echo "One of the following syncfs calls should fail with EIO:"
+$XFS_IO_PROG -r -c syncfs -c syncfs $testfile
+echo "done"
+echo "This syncfs call should succeed:"
+$XFS_IO_PROG -r -c syncfs $testfile
+echo "done"
+# success, all done
diff --git a/tests/generic/999.out b/tests/generic/999.out
new file mode 100644
index 0000000..950a2ba
--- /dev/null
+++ b/tests/generic/999.out
@@ -0,0 +1,8 @@
+QA output created by 999
+Format and mount
+fdatasync: Input/output error
+One of the following syncfs calls should fail with EIO:
+syncfs: Input/output error
+This syncfs call should succeed:
diff --git a/tests/generic/group b/tests/generic/group
index 99d06c9..028cdbd 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -598,3 +598,4 @@
 594 auto quick quota
 595 auto quick encrypt
 596 auto quick
+999 auto quick