generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 557
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 557
6 #
7 # Test that if we fsync a file, evict its inode, unlink it and then fsync its
8 # parent directory, after a power failure the file does not exists.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick log
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16         _cleanup_flakey
17         cd /
18         rm -f $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/dmflakey
24
25 # real QA test starts here
26 _supported_fs generic
27 _require_scratch
28 _require_dm_target flakey
29
30 _scratch_mkfs >>$seqres.full 2>&1
31 _require_metadata_journaling $SCRATCH_DEV
32 _init_flakey
33 _mount_flakey
34
35 # Create our test directory with one file in it and fsync the file.
36 mkdir $SCRATCH_MNT/dir
37 touch $SCRATCH_MNT/dir/foo
38 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir/foo
39
40 # Keep an open file descriptor on our directory while we evict inodes. We just
41 # want to evict the file's inode, the directory's inode must not be evicted.
42 (
43         cd $SCRATCH_MNT/dir
44         while true; do
45                 :
46         done
47 ) &
48 pid=$!
49 # Wait a bit to give time to background process to chdir to our test directory.
50 sleep 0.1
51
52 # Trigger eviction of the file's inode.
53 echo 2 > /proc/sys/vm/drop_caches
54
55 # Unlink our file and fsync the parent directory. After a power failure we don't
56 # expect to see the file anymore, since we fsync'ed the parent directory.
57 unlink $SCRATCH_MNT/dir/foo
58 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir
59
60 # Kill the background process using our test directory.
61 kill $pid
62 wait $pid
63
64 # Simulate a power failure and then check file foo does not exists anymore.
65 _flakey_drop_and_remount
66
67 [ -f $SCRATCH_MNT/dir/foo ] && echo "File foo still exists"
68
69 _unmount_flakey
70 echo "Silence is golden"
71 status=0
72 exit