79171994e4f474eb7f54eae617f610f6c7ff75bf
[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 _supported_fs generic
49 _supported_os Linux
50 _require_scratch
51 _require_dm_target flakey
52 _require_metadata_journaling $SCRATCH_DEV
53
54 rm -f $seqres.full
55
56 _scratch_mkfs >>$seqres.full 2>&1
57 _init_flakey
58 _mount_flakey
59
60 # Create our test directory and files.
61 mkdir $SCRATCH_MNT/testdir
62 touch $SCRATCH_MNT/testdir/foo
63 touch $SCRATCH_MNT/testdir/bar
64
65 # Make sure everything done so far is durably persisted.
66 sync
67
68 # Create one hard link for file foo and another one for file bar. After that
69 # fsync only the file bar.
70 ln $SCRATCH_MNT/testdir/bar $SCRATCH_MNT/testdir/bar_link
71 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/foo_link
72 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/bar
73
74 _flakey_drop_and_remount
75
76 # Now verify both our files have a link count of 2.
77 echo "Link count for file foo: $(stat -c %h $SCRATCH_MNT/testdir/foo)"
78 echo "Link count for file bar: $(stat -c %h $SCRATCH_MNT/testdir/bar)"
79
80 # We should be able to remove all the links of our files in testdir, and after
81 # that the parent directory should become empty and therefore possible to
82 # remove it.
83 rm -f $SCRATCH_MNT/testdir/*
84 rmdir $SCRATCH_MNT/testdir
85
86 _unmount_flakey
87
88 # The fstests framework will call fsck against our filesystem which will verify
89 # that all metadata is in a consistent state.
90
91 status=0
92 exit