generic/402: Drop useless fail message
[xfstests-dev.git] / tests / generic / 552
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. 552
6 #
7 # Check that if we write some data to a file, its inode gets evicted (while its
8 # parent directory's inode is not evicted due to being in use), then we rename
9 # the file and fsync it, after a power failure the file data is not lost.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         _cleanup_flakey
21         cd /
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/dmflakey
29
30 # real QA test starts here
31 _supported_fs generic
32 _require_scratch
33 _require_odirect
34 _require_dm_target flakey
35
36 rm -f $seqres.full
37
38 _scratch_mkfs >>$seqres.full 2>&1
39 _require_metadata_journaling $SCRATCH_DEV
40 _init_flakey
41 _mount_flakey
42
43 # Create our test directory with two files in it.
44 mkdir $SCRATCH_MNT/dir
45 touch $SCRATCH_MNT/dir/foo
46 touch $SCRATCH_MNT/dir/bar
47
48 # Do a direct IO write into file bar.
49 # To trigger the bug found in btrfs, doing a buffered write would also work as
50 # long as writeback completes before the file's inode is evicted (the inode can
51 # not be evicted while delalloc exists). But since that is hard to trigger from
52 # a user space test, without resulting in a transaction commit as well, just do
53 # a direct IO write since it is much simpler.
54 $XFS_IO_PROG -d -c "pwrite -S 0xd3 0 4K" $SCRATCH_MNT/dir/bar | _filter_xfs_io
55
56 # Keep the directory in use while we evict all inodes. This is to prevent
57 # eviction of the directory's inode (a necessary condition to trigger the bug
58 # found in btrfs, as evicting the directory inode would result in commiting the
59 # current transaction when the fsync of file foo happens below).
60 (
61         cd $SCRATCH_MNT/dir
62         while true; do
63                 :
64         done
65 ) &
66 pid=$!
67 # Wait a bit to give time to the background process to chdir to the directory.
68 sleep 0.1
69
70 # Evict all inodes from memory, except the directory's inode because a background
71 # process is using it.
72 echo 2 > /proc/sys/vm/drop_caches
73
74 # Now fsync our file foo, which ends up persisting information about its parent
75 # directory inode because it is a new inode.
76 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir/foo
77
78 # Rename our file bar to baz right before we fsync it.
79 mv $SCRATCH_MNT/dir/bar $SCRATCH_MNT/dir/baz
80
81 # Fsync our file baz, after a power failure we expect to see the data we
82 # previously wrote to it.
83 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/dir/baz
84
85 # Kill the background process using our test directory.
86 kill $pid
87 wait $pid
88
89 # Simulate a power failure and then check no data loss happened.
90 _flakey_drop_and_remount
91
92 echo "File data after power failure:"
93 od -t x1 -A d $SCRATCH_MNT/dir/baz
94
95 _unmount_flakey
96 status=0
97 exit