generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 106
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 106
6 #
7 # Test that if we remove one hard link from an inode, evict the inode, fsync the
8 # inode, power fail and then mount the filesystem, the hard link we removed does
9 # not exists anymore and the filesystem metadata is in a consistent state.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick metadata log
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         _cleanup_flakey
18         rm -f $tmp.*
19 }
20
21 # Import common functions.
22 . ./common/filter
23 . ./common/dmflakey
24
25 # real QA test starts here
26 _supported_fs generic
27 _require_scratch
28 _require_hardlinks
29 _require_dm_target flakey
30
31 _scratch_mkfs >>$seqres.full 2>&1
32 _require_metadata_journaling $SCRATCH_DEV
33 _init_flakey
34 _mount_flakey
35
36 # Create our test file with 2 hard links.
37 mkdir $SCRATCH_MNT/testdir
38 touch $SCRATCH_MNT/testdir/foo
39 ln $SCRATCH_MNT/testdir/foo $SCRATCH_MNT/testdir/bar
40
41 # Make sure everything done so far is durably persisted.
42 sync
43
44 # Now remove one of the links, trigger inode eviction and then fsync our
45 # inode.
46 unlink $SCRATCH_MNT/testdir/bar
47 echo 2 > /proc/sys/vm/drop_caches
48 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/testdir/foo
49
50 _flakey_drop_and_remount
51
52 # Now verify our directory entries.
53 echo "Entries in testdir:"
54 ls -1 $SCRATCH_MNT/testdir
55
56 # If we remove our inode, its parent should become empty and therefore we should
57 # be able to remove the parent.
58 rm -f $SCRATCH_MNT/testdir/*
59 rmdir $SCRATCH_MNT/testdir
60
61 _unmount_flakey
62
63 # The fstests framework will call fsck against our filesystem which will verify
64 # that all metadata is in a consistent state.
65
66 status=0
67 exit