fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 107
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 107
6 #
7 # Test that when we have a file with multiple hard links belonging to different
8 # parent directories, if we remove one of those links, fsync the file using one
9 # of its other links (that has a parent directory different from the one we
10 # removed a link from), power fail and then replay the fsync log/journal, the
11 # hard link we removed is not available anymore and all the filesystem metadata
12 # is in a consistent state.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         _cleanup_flakey
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/dmflakey
31
32 # real QA test starts here
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch
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 directory and file.
46 mkdir $SCRATCH_MNT/testdir
47 touch $SCRATCH_MNT/foo
48 ln $SCRATCH_MNT/foo $SCRATCH_MNT/testdir/foo2
49 ln $SCRATCH_MNT/foo $SCRATCH_MNT/testdir/foo3
50
51 # Make sure everything done so far is durably persisted.
52 sync
53
54 # Now we remove one of our file's hardlinks in the directory testdir.
55 unlink $SCRATCH_MNT/testdir/foo3
56
57 # We now fsync our file using the "foo" link, which has a parent that
58 # is not the directory "testdir".
59 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
60
61 _flakey_drop_and_remount
62
63 # After the journal/log is replayed we expect to not see the "foo3" link anymore
64 # and we should be able to remove all names in the directory "testdir" and then
65 # remove it (no stale directory entries left after the journal/log replay).
66 echo "Entries in testdir:"
67 ls -1 $SCRATCH_MNT/testdir
68
69 rm -f $SCRATCH_MNT/testdir/*
70 rmdir $SCRATCH_MNT/testdir
71
72 _unmount_flakey
73
74 status=0
75 exit