fef3583e14df216921f71090ba9cac84d04abac7
[xfstests-dev.git] / tests / generic / 104
1 #! /bin/bash
2 # FSQA Test No. 104
3 #
4 # Test that if we add hard links (in the same directory) to two files and then
5 # fsync only one of the files, after the fsync log/journal is replayed all the
6 # links exist and the filesystem metadata (directory and file inodes) is in a
7 # consistent state.
8 #
9 #-----------------------------------------------------------------------
10 #
11 # Copyright (C) 2015 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         rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/dmflakey
46
47 # real QA test starts here
48 _need_to_be_root
49 _supported_fs generic
50 _supported_os Linux
51 _require_scratch
52 _require_dm_flakey
53 _require_metadata_journaling $SCRATCH_DEV
54
55 rm -f $seqres.full
56
57 _scratch_mkfs >>$seqres.full 2>&1
58 _init_flakey
59 _mount_flakey
60
61 # Create our test directory and files.
62 mkdir $SCRATCH_MNT/testdir
63 touch $SCRATCH_MNT/testdir/foo
64 touch $SCRATCH_MNT/testdir/bar
65
66 # Make sure everything done so far is durably persisted.
67 sync
68
69 # Create one hard link for file foo and another one for file bar. After that
70 # fsync only the file bar.
71 ln $SCRATCH_MNT/testdir/bar $SCRATCH_MNT/testdir/bar_link
72 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/foo_link
73 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/bar
74
75 # Silently drop all writes on our scratch device to simulate a power failure.
76 _load_flakey_table $FLAKEY_DROP_WRITES
77 _unmount_flakey
78
79 # Allow writes again and mount the fs to trigger log/journal replay.
80 _load_flakey_table $FLAKEY_ALLOW_WRITES
81 _mount_flakey
82
83 # Now verify both our files have a link count of 2.
84 echo "Link count for file foo: $(stat -c %h $SCRATCH_MNT/testdir/foo)"
85 echo "Link count for file bar: $(stat -c %h $SCRATCH_MNT/testdir/bar)"
86
87 # We should be able to remove all the links of our files in testdir, and after
88 # that the parent directory should become empty and therefore possible to
89 # remove it.
90 rm -f $SCRATCH_MNT/testdir/*
91 rmdir $SCRATCH_MNT/testdir
92
93 _unmount_flakey
94
95 # The fstests framework will call fsck against our filesystem which will verify
96 # that all metadata is in a consistent state.
97
98 status=0
99 exit