generic: test deadlock on O_DIRECT|O_DSYNC
[xfstests-dev.git] / tests / generic / 480
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 480
6 #
7 # Test that if we have a file with two hard links in the same parent directory,
8 # then remove of the links, create a new file in the same parent directory and
9 # with the name of the link removed, fsync the new file and have a power loss,
10 # mounting the filesystem succeeds.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         _cleanup_flakey
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/dmflakey
30
31 # real QA test starts here
32 _supported_fs generic
33 _supported_os Linux
34 _require_scratch
35 _require_hardlinks
36 _require_dm_target flakey
37
38 rm -f $seqres.full
39
40 _scratch_mkfs >>$seqres.full 2>&1
41 _require_metadata_journaling $SCRATCH_DEV
42 _init_flakey
43 _mount_flakey
44
45 mkdir $SCRATCH_MNT/testdir
46 touch $SCRATCH_MNT/testdir/foo
47 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
48
49 # Make sure everything done so far is durably persisted.
50 sync
51
52 # Now remove of the links of our file and create a new file with the same name
53 # and in the same parent directory, and finally fsync this new file.
54 unlink $SCRATCH_MNT/testdir/bar
55 touch $SCRATCH_MNT/testdir/bar
56 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/bar
57
58 # Simulate a power failure and mount the filesystem to check that replaying the
59 # the fsync log/journal succeeds, that is the mount operation does not fail.
60 _flakey_drop_and_remount
61
62 _unmount_flakey
63 _cleanup_flakey
64
65 echo "Silence is golden"
66 status=0
67 exit