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