generic: test fsync new file after removing hard link
[xfstests-dev.git] / tests / generic / 480
1 #! /bin/bash
2 # FSQA Test No. 480
3 #
4 # Test that if we have a file with two hard links in the same parent directory,
5 # then remove of the links, create a new file in the same parent directory and
6 # with the name of the link removed, fsync the new file and have a power loss,
7 # mounting the filesystem succeeds.
8 #
9 #-----------------------------------------------------------------------
10 #
11 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
12 # Author: Filipe Manana <fdmanana@suse.com>
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27 #
28
29 seq=`basename $0`
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
32 tmp=/tmp/$$
33 status=1        # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38         _cleanup_flakey
39         cd /
40         rm -f $tmp.*
41 }
42
43 # get standard environment, filters and checks
44 . ./common/rc
45 . ./common/filter
46 . ./common/dmflakey
47
48 # real QA test starts here
49 _supported_fs generic
50 _supported_os Linux
51 _require_scratch
52 _require_dm_target flakey
53
54 rm -f $seqres.full
55
56 _scratch_mkfs >>$seqres.full 2>&1
57 _require_metadata_journaling $SCRATCH_DEV
58 _init_flakey
59 _mount_flakey
60
61 mkdir $SCRATCH_MNT/testdir
62 touch $SCRATCH_MNT/testdir/foo
63 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
64
65 # Make sure everything done so far is durably persisted.
66 sync
67
68 # Now remove of the links of our file and create a new file with the same name
69 # and in the same parent directory, and finally fsync this new file.
70 unlink $SCRATCH_MNT/testdir/bar
71 touch $SCRATCH_MNT/testdir/bar
72 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/bar
73
74 # Simulate a power failure and mount the filesystem to check that replaying the
75 # the fsync log/journal succeeds, that is the mount operation does not fail.
76 _flakey_drop_and_remount
77
78 _unmount_flakey
79 _cleanup_flakey
80
81 echo "Silence is golden"
82 status=0
83 exit