xfstests: remove _need_to_be_root
[xfstests-dev.git] / tests / generic / 107
1 #! /bin/bash
2 # FSQA Test No. 107
3 #
4 # Test that when we have a file with multiple hard links belonging to different
5 # parent directories, if we remove one of those links, fsync the file using one
6 # of its other links (that has a parent directory different from the one we
7 # removed a link from), power fail and then replay the fsync log/journal, the
8 # hard link we removed is not available anymore and all the filesystem metadata
9 # is in a consistent state.
10 #
11 #-----------------------------------------------------------------------
12 #
13 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
14 # Author: Filipe Manana <fdmanana@suse.com>
15 #
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
19 #
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
28 #-----------------------------------------------------------------------
29 #
30
31 seq=`basename $0`
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by $seq"
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
37
38 _cleanup()
39 {
40         _cleanup_flakey
41         rm -f $tmp.*
42 }
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47 . ./common/dmflakey
48
49 # real QA test starts here
50 _supported_fs generic
51 _supported_os Linux
52 _require_scratch
53 _require_dm_target flakey
54 _require_metadata_journaling $SCRATCH_DEV
55
56 rm -f $seqres.full
57
58 _scratch_mkfs >>$seqres.full 2>&1
59 _init_flakey
60 _mount_flakey
61
62 # Create our test directory and file.
63 mkdir $SCRATCH_MNT/testdir
64 touch $SCRATCH_MNT/foo
65 ln $SCRATCH_MNT/foo $SCRATCH_MNT/testdir/foo2
66 ln $SCRATCH_MNT/foo $SCRATCH_MNT/testdir/foo3
67
68 # Make sure everything done so far is durably persisted.
69 sync
70
71 # Now we remove one of our file's hardlinks in the directory testdir.
72 unlink $SCRATCH_MNT/testdir/foo3
73
74 # We now fsync our file using the "foo" link, which has a parent that
75 # is not the directory "testdir".
76 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
77
78 _flakey_drop_and_remount
79
80 # After the journal/log is replayed we expect to not see the "foo3" link anymore
81 # and we should be able to remove all names in the directory "testdir" and then
82 # remove it (no stale directory entries left after the journal/log replay).
83 echo "Entries in testdir:"
84 ls -1 $SCRATCH_MNT/testdir
85
86 rm -f $SCRATCH_MNT/testdir/*
87 rmdir $SCRATCH_MNT/testdir
88
89 _unmount_flakey
90
91 status=0
92 exit