2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
7 # This test is motivated by a bug found in btrfs when replaying a directory
8 # from the fsync log. The issue was that if a directory entry is both found
9 # in the persisted metadata and in the fsync log, at log replay time the
10 # directory got set with a wrong i_size. This had the consequence of not being
11 # able to rmdir empty directories (failed with errno ENOTEMPTY).
12 # This was fixed in btrfs with the following linux kernel patch:
14 # Btrfs: fix directory recovery from fsync log
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
21 status=1 # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # get standard environment, filters and checks
34 # real QA test starts here
38 _require_dm_target flakey
42 _scratch_mkfs >> $seqres.full 2>&1
43 _require_metadata_journaling $SCRATCH_DEV
47 mkdir $SCRATCH_MNT/test_dir
48 touch $SCRATCH_MNT/test_dir/foo
50 # Invoke sync here because it's necessary to trigger the original bug in btrfs.
51 # The intention is that at log recovery time we have a dir entry for 'foo' both
52 # in the fs/subvol tree and in the log tree - this is necessary to trigger the
56 touch $SCRATCH_MNT/test_dir/bar
57 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/test_dir
58 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/test_dir/bar
60 # In the original btrfs bug, log replay would update the directory's inode
61 # i_size incorrectly - it would sum again the size of dentry 'foo' (3) to
62 # the inode's i_size, which is incorrect because the dentry was already
63 # persisted before (in the fs/subvol tree).
64 _flakey_drop_and_remount
66 [ -f $SCRATCH_MNT/test_dir/foo ] || echo "file foo is missing"
67 [ -f $SCRATCH_MNT/test_dir/bar ] || echo "file bar is missing"
69 rm -f $SCRATCH_MNT/test_dir/foo
70 rm -f $SCRATCH_MNT/test_dir/bar
72 # In btrfs removing all entries from a directory should set the directory's
73 # inode i_size to 0, but with this bug that didn't happen and this made
74 # an rmdir fail with errno ENOTEMPTY (even though the directory had no more
76 rmdir $SCRATCH_MNT/test_dir
77 [ -d $SCRATCH_MNT/test_dir ] && echo "rmdir didn't succeed"
81 echo "Silence is golden"