generic/554: hide permision warning on exfat
[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 seq=`basename $0`
20 seqres=$RESULT_DIR/$seq
21 echo "QA output created by $seq"
22
23 here=`pwd`
24 tmp=/tmp/$$
25 status=1        # failure is the default!
26
27 _cleanup()
28 {
29         _cleanup_flakey
30 }
31 trap "_cleanup; exit \$status" 0 1 2 3 15
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36 . ./common/dmflakey
37
38 # real QA test starts here
39 _supported_fs generic
40 _require_scratch
41 _require_hardlinks
42 _require_dm_target flakey
43
44 rm -f $seqres.full
45
46 _scratch_mkfs >> $seqres.full 2>&1
47 _require_metadata_journaling $SCRATCH_DEV
48 _init_flakey
49 _mount_flakey
50
51 # Create a test file with 2 hard links in the same directory.
52 mkdir -p $SCRATCH_MNT/a/b
53 echo "hello world" > $SCRATCH_MNT/a/b/foo
54 ln $SCRATCH_MNT/a/b/foo $SCRATCH_MNT/a/b/bar
55
56 # Make sure all metadata and data are durably persisted.
57 sync
58
59 # Now remove one of the hard links and fsync the inode.
60 rm -f $SCRATCH_MNT/a/b/bar
61 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a/b/foo
62
63 _flakey_drop_and_remount
64
65 # Remove the last hard link of the file and attempt to remove its parent
66 # directory - this failed in btrfs because the fsync log and replay code
67 # didn't decrement the parent directory's i_size and left dangling directory
68 # index entries - this made the btrfs rmdir implementation always fail with
69 # the error -ENOTEMPTY.
70 #
71 # The dangling directory index entries were visible to user space, but it was
72 # impossible to do anything on them (unlink, open, read, write, stat, etc)
73 # because the inode they pointed to did not exist anymore.
74 #
75 # The parent directory's metadata inconsistency (stale index entries) was
76 # also detected by btrfs' fsck tool, which is run automatically by the fstests
77 # framework when the test finishes. The error message reported by fsck was:
78 #
79 # root 5 inode 259 errors 2001, no inode item, link count wrong
80 #   unresolved ref dir 258 index 3 namelen 3 name bar filetype 1 errors 4, no inode ref
81 #
82 rm -f $SCRATCH_MNT/a/b/*
83 rmdir $SCRATCH_MNT/a/b
84 rmdir $SCRATCH_MNT/a
85
86 echo "Silence is golden"
87 status=0
88 exit