fstests: move test group info to test files
[xfstests-dev.git] / tests / generic / 039
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 039
6 #
7 # This test is motivated by an fsync issue discovered in btrfs.
8 # The issue was that after fsyncing an inode that got its link count
9 # decremented, and the new link count is greater than zero, after the
10 # fsync log replay the inode's parent directory metadata became
11 # inconsistent - it had a wrong i_size and dangling index entries which
12 # prevented the directory from ever being removed (rmdir always failed
13 # with -ENOTEMPTY, even if the directory had no more child inodes).
14 #
15 # The btrfs issue was fixed by the following linux kernel patch:
16 #
17 #    Btrfs: fix directory inconsistency after fsync log replay
18 #
19 . ./common/preamble
20 _begin_fstest metadata auto quick log
21
22 # Override the default cleanup function.
23 _cleanup()
24 {
25         _cleanup_flakey
26 }
27
28 # Import common functions.
29 . ./common/filter
30 . ./common/dmflakey
31
32 # real QA test starts here
33 _supported_fs generic
34 _require_scratch
35 _require_hardlinks
36 _require_dm_target flakey
37
38 _scratch_mkfs >> $seqres.full 2>&1
39 _require_metadata_journaling $SCRATCH_DEV
40 _init_flakey
41 _mount_flakey
42
43 # Create a test file with 2 hard links in the same directory.
44 mkdir -p $SCRATCH_MNT/a/b
45 echo "hello world" > $SCRATCH_MNT/a/b/foo
46 ln $SCRATCH_MNT/a/b/foo $SCRATCH_MNT/a/b/bar
47
48 # Make sure all metadata and data are durably persisted.
49 sync
50
51 # Now remove one of the hard links and fsync the inode.
52 rm -f $SCRATCH_MNT/a/b/bar
53 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/b/foo
54
55 _flakey_drop_and_remount
56
57 # Remove the last hard link of the file and attempt to remove its parent
58 # directory - this failed in btrfs because the fsync log and replay code
59 # didn't decrement the parent directory's i_size and left dangling directory
60 # index entries - this made the btrfs rmdir implementation always fail with
61 # the error -ENOTEMPTY.
62 #
63 # The dangling directory index entries were visible to user space, but it was
64 # impossible to do anything on them (unlink, open, read, write, stat, etc)
65 # because the inode they pointed to did not exist anymore.
66 #
67 # The parent directory's metadata inconsistency (stale index entries) was
68 # also detected by btrfs' fsck tool, which is run automatically by the fstests
69 # framework when the test finishes. The error message reported by fsck was:
70 #
71 # root 5 inode 259 errors 2001, no inode item, link count wrong
72 #   unresolved ref dir 258 index 3 namelen 3 name bar filetype 1 errors 4, no inode ref
73 #
74 rm -f $SCRATCH_MNT/a/b/*
75 rmdir $SCRATCH_MNT/a/b
76 rmdir $SCRATCH_MNT/a
77
78 echo "Silence is golden"
79 status=0
80 exit