fstests: use _require_symlinks on all necessary tests
[xfstests-dev.git] / tests / generic / 034
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 034
6 #
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:
13 #
14 #     Btrfs: fix directory recovery from fsync log
15 #
16 seq=`basename $0`
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
19
20 here=`pwd`
21 status=1        # failure is the default!
22
23 _cleanup()
24 {
25         _cleanup_flakey
26 }
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/dmflakey
33
34 # real QA test starts here
35 _supported_fs generic
36 _supported_os Linux
37 _require_scratch
38 _require_dm_target flakey
39
40 rm -f $seqres.full
41
42 _scratch_mkfs >> $seqres.full 2>&1
43 _require_metadata_journaling $SCRATCH_DEV
44 _init_flakey
45 _mount_flakey
46
47 mkdir $SCRATCH_MNT/test_dir
48 touch $SCRATCH_MNT/test_dir/foo
49
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
53 # bug on btrfs.
54 sync
55
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
59
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
65
66 [ -f $SCRATCH_MNT/test_dir/foo ] || echo "file foo is missing"
67 [ -f $SCRATCH_MNT/test_dir/bar ] || echo "file bar is missing"
68
69 rm -f $SCRATCH_MNT/test_dir/foo
70 rm -f $SCRATCH_MNT/test_dir/bar
71
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
75 # entries in it).
76 rmdir $SCRATCH_MNT/test_dir
77 [ -d $SCRATCH_MNT/test_dir ] && echo "rmdir didn't succeed"
78
79 _unmount_flakey
80
81 echo "Silence is golden"
82
83 status=0
84 exit