fstests: add _require_hardlinks for all necessary tests
[xfstests-dev.git] / tests / generic / 336
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 336
6 #
7 # Test that if we have a file F1 with two links, one in a directory A and the
8 # other in directory B, if we remove the link in directory B, move some other
9 # file F2 from directory B into directory C, fsync inode F1, power fail and
10 # remount the filesystem, file F2 exists and is located only in directory C.
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 # Create our test directories and the file we will later check if it has
46 # disappeared (file bar).
47 mkdir $SCRATCH_MNT/a
48 mkdir $SCRATCH_MNT/b
49 mkdir $SCRATCH_MNT/c
50 touch $SCRATCH_MNT/a/foo
51 ln $SCRATCH_MNT/a/foo $SCRATCH_MNT/b/foo_link
52 touch $SCRATCH_MNT/b/bar
53
54 # Make sure everything is durably persisted.
55 sync
56
57 # Now delete one of the hard links of file foo and move file bar into c/
58 unlink $SCRATCH_MNT/b/foo_link
59 mv $SCRATCH_MNT/b/bar $SCRATCH_MNT/c/
60
61 # Now fsync file foo.
62 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/foo
63
64 echo "Filesystem content before power failure:"
65 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/b $SCRATCH_MNT/c | _filter_scratch
66
67 # Simulate a power failure / crash and remount the filesystem, so that the
68 # journal/log is replayed.
69 _flakey_drop_and_remount
70
71 # We expect that after the journal/log was replayed, we no longer have the link
72 # foo_link and file bar was moved from directory b/ to directory c/.
73 echo "Filesystem content after power failure:"
74 # Must match what we had before the power failure.
75 ls -R $SCRATCH_MNT/a $SCRATCH_MNT/b $SCRATCH_MNT/c | _filter_scratch
76
77 _unmount_flakey
78
79 status=0
80 exit