generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 441
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017, Jeff Layton <jlayton@redhat.com>
4 #
5 # FS QA Test No. 441
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 -rf $tmp.* $testdir
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
29
30 # Generally, we want to avoid journal errors on the extended testcase. Only
31 # unset the -s flag if we have a logdev
32 sflag='-s'
33 case $FSTYP in
34         btrfs)
35                 _notrun "btrfs has a specialized test for this"
36                 ;;
37         ext3|ext4|xfs|bcachefs)
38                 # Do the more thorough test if we have a logdev
39                 _has_logdev && sflag=''
40                 ;;
41         *)
42                 ;;
43 esac
44
45 _require_dm_target error
46 _require_test_program fsync-err
47 _require_test_program dmerror
48
49 # Disable the scratch rt device to avoid test failures relating to the rt
50 # bitmap consuming all the free space in our small data device.
51 unset SCRATCH_RTDEV
52
53 echo "Format and mount"
54 _scratch_mkfs > $seqres.full 2>&1
55 _dmerror_init
56 _dmerror_mount
57
58 _require_fs_space $SCRATCH_MNT 65536
59
60 testfile=$SCRATCH_MNT/fsync-err-test
61
62 echo "$here/src/fsync-err $sflag -d $here/src/dmerror $testfile" >> $seqres.full
63 $here/src/fsync-err $sflag -d $here/src/dmerror $testfile
64
65 # success, all done
66 _dmerror_load_working_table
67 _dmerror_unmount
68 _dmerror_cleanup
69
70 # fs may be corrupt after this -- attempt to repair it
71 _repair_scratch_fs >> $seqres.full
72
73 status=0
74 exit