common/fuzzy: try to clear blocking flags first in _scratch_fuzz_modify
[xfstests-dev.git] / tests / generic / 041
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. 041
6 #
7 # This test is motivated by an fsync issue discovered in btrfs.
8 # The steps to trigger the issue were:
9 #
10 # 1) remove an hard link from an inode with a large number of hard links;
11 # 2) add a new hard link;
12 # 3) add another hard link with the same name as the one removed in step 1;
13 # 4) fsync the inode.
14 #
15 # These steps made the btrfs fsync log replay fail (with the -EOVERFLOW error),
16 # making the filesystem unmountable, requiring the use of btrfs-zero-log (it
17 # wipes the fsync log) in order to make the filesystem mountable again (but
18 # losing some data/metadata).
19 #
20 # The btrfs issue was fixed by the following linux kernel patches:
21 #
22 #  Btrfs: fix fsync when extend references are added to an inode
23 #  Btrfs: fix fsync log replay for inodes with a mix of regular refs and extrefs
24 #
25 # This issue was present in btrfs since the extrefs (extend references)
26 # feature was added (2012).
27 #
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35
36 _cleanup()
37 {
38         _cleanup_flakey
39 }
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/dmflakey
46
47 # real QA test starts here
48 _supported_fs generic
49 _supported_os Linux
50 _require_scratch
51 _require_hardlinks
52 _require_dm_target flakey
53
54 rm -f $seqres.full
55
56 # If the test filesystem is btrfs, make sure we create a filesystem with
57 # the extend references (extrefs) feature enabled (it's enabled by default
58 # in recent versions of btrfs-progs).
59 if [ "$FSTYP" = "btrfs" ]; then
60         _scratch_mkfs "-O extref" >> $seqres.full 2>&1
61 else
62         _scratch_mkfs >> $seqres.full 2>&1
63 fi
64
65 _require_metadata_journaling $SCRATCH_DEV
66 _init_flakey
67 _mount_flakey
68
69 # Create a test file with 3001 hard links. This number is large enough to
70 # make btrfs start using extrefs at some point even if the fs has the maximum
71 # possible leaf/node size (64Kb).
72 echo "hello world" > $SCRATCH_MNT/foo
73 for i in `seq 1 3000`; do
74         ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link_`printf "%04d" $i`
75 done
76
77 # Make sure all metadata and data are durably persisted.
78 sync
79
80 # Now remove one link, add a new one with a new name, add another new one with
81 # the same name as the one we just removed and fsync the inode.
82 rm -f $SCRATCH_MNT/foo_link_0001
83 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link_3001
84 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link_0001
85 rm -f $SCRATCH_MNT/foo_link_0002
86 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link_3002
87 ln $SCRATCH_MNT/foo $SCRATCH_MNT/foo_link_3003
88 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foo
89
90 _flakey_drop_and_remount
91
92 # Check that the number of hard links is correct, we are able to remove all
93 # the hard links and read the file's data. This is just to verify we don't
94 # get stale file handle errors (due to dangling directory index entries that
95 # point to inodes that no longer exist).
96 echo "Link count: $(stat -c %h $SCRATCH_MNT/foo)"
97 [ -f $SCRATCH_MNT/foo ] || echo "Link foo is missing"
98 for ((i = 1; i <= 3003; i++)); do
99         name=foo_link_`printf "%04d" $i`
100         if [ $i -eq 2 ]; then
101                 [ -f $SCRATCH_MNT/$name ] && echo "Link $name found"
102         else
103                 [ -f $SCRATCH_MNT/$name ] || echo "Link $name is missing"
104         fi
105 done
106 rm -f $SCRATCH_MNT/foo_link_*
107 cat $SCRATCH_MNT/foo
108 rm -f $SCRATCH_MNT/foo
109
110 status=0
111 exit