generic: test dir fsync after deleting dentry post eviction of its inode
[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 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         _cleanup_flakey
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/dmflakey
28
29 # real QA test starts here
30 _supported_fs generic
31 _supported_os Linux
32 _require_scratch
33 _require_dm_target flakey
34
35 rm -f $seqres.full
36
37 _scratch_mkfs >>$seqres.full 2>&1
38 _require_metadata_journaling $SCRATCH_DEV
39 _init_flakey
40 _mount_flakey
41
42 # Create our test directory with one file in it and fsync the file.
43 mkdir $SCRATCH_MNT/dir
44 touch $SCRATCH_MNT/dir/foo
45 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir/foo
46
47 # Keep an open file descriptor on our directory while we evict inodes. We just
48 # want to evict the file's inode, the directory's inode must not be evicted.
49 (
50         cd $SCRATCH_MNT/dir
51         while true; do
52                 :
53         done
54 ) &
55 pid=$!
56 # Wait a bit to give time to background process to chdir to our test directory.
57 sleep 0.1
58
59 # Trigger eviction of the file's inode.
60 echo 2 > /proc/sys/vm/drop_caches
61
62 # Unlink our file and fsync the parent directory. After a power failure we don't
63 # expect to see the file anymore, since we fsync'ed the parent directory.
64 unlink $SCRATCH_MNT/dir/foo
65 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir
66
67 # Kill the background process using our test directory.
68 kill $pid
69 wait $pid
70
71 # Simulate a power failure and then check file foo does not exists anymore.
72 _flakey_drop_and_remount
73
74 [ -f $SCRATCH_MNT/dir/foo ] && echo "File foo still exists"
75
76 _unmount_flakey
77 echo "Silence is golden"
78 status=0
79 exit