generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 487
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018, Jeff Layton <jlayton@redhat.com>
4 #
5 # FS QA Test No. 487
6 #
7 # Open a file several times, write to it, fsync on all fds and make sure that
8 # they all return 0. Change the device to start throwing errors. Write again
9 # on all fds and fsync on all fds. Ensure that we get errors on all of them.
10 # Then fsync on all one last time and verify that all return 0.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick eio
14
15 # Override the default cleanup function.
16 _cleanup()
17 {
18         cd /
19         rm -f $tmp.*
20         _dmerror_cleanup
21 }
22
23 # Import common functions.
24 . ./common/filter
25 . ./common/dmerror
26
27 # real QA test starts here
28 _require_scratch_nocheck
29
30 sflag='-s'
31 case $FSTYP in
32         btrfs)
33                 _notrun "btrfs has a specialized test for this"
34                 ;;
35         *)
36                 ;;
37 esac
38
39 _require_logdev
40 _require_dm_target error
41
42 # Disable the scratch rt device to avoid test failures relating to the rt
43 # bitmap consuming all the free space in our small data device.
44 unset SCRATCH_RTDEV
45
46 echo "Format and mount"
47 _scratch_mkfs > $seqres.full 2>&1
48 _dmerror_init
49 _dmerror_mount
50
51 datalen=65536
52 _require_fs_space $SCRATCH_MNT $datalen
53
54 # use fd 5 to hold file open
55 testfile=$SCRATCH_MNT/fsync-open-after-err
56 exec 5>$testfile
57
58 # write some data to file and fsync it out
59 $XFS_IO_PROG -c "pwrite -q 0 $datalen" -c fsync $testfile
60
61 # flip device to non-working mode
62 _dmerror_load_error_table
63
64 # rewrite the data, call sync to ensure it's written back w/o scraping error
65 $XFS_IO_PROG -c "pwrite -q 0 $datalen" -c sync $testfile
66
67 # heal the device error
68 _dmerror_load_working_table
69
70 # open again and call fsync
71 echo "The following fsync should fail with EIO:"
72 $XFS_IO_PROG -c fsync $testfile
73 echo "done"
74
75 # close file
76 exec 5>&-
77
78 # success, all done
79 _dmerror_cleanup
80
81 status=0
82 exit