9dd2e6b27e3e35705a59439525b19b60831f9704
[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 _need_to_be_root
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 file with 2 hard links.
61 mkdir $SCRATCH_MNT/testdir
62 touch $SCRATCH_MNT/testdir/foo
63 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
64
65 # Make sure everything done so far is durably persisted.
66 sync
67
68 # Now remove one of the links, trigger inode eviction and then fsync our
69 # inode.
70 unlink $SCRATCH_MNT/testdir/bar
71 echo 2 > /proc/sys/vm/drop_caches
72 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/foo
73
74 _flakey_drop_and_remount
75
76 # Now verify our directory entries.
77 echo "Entries in testdir:"
78 ls -1 $SCRATCH_MNT/testdir
79
80 # If we remove our inode, its parent should become empty and therefore we should
81 # be able to remove the parent.
82 rm -f $SCRATCH_MNT/testdir/*
83 rmdir $SCRATCH_MNT/testdir
84
85 _unmount_flakey
86
87 # The fstests framework will call fsck against our filesystem which will verify
88 # that all metadata is in a consistent state.
89
90 status=0
91 exit