2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Chandan Babu R. All Rights Reserved.
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # adding/removing directory entries.
10 _begin_fstest auto quick dir hardlink symlink
12 # Import common functions.
17 # real QA test starts here
22 _require_test_program "punch-alternating"
23 _require_xfs_io_error_injection "reduce_max_iextents"
24 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
26 _scratch_mkfs_sized $((1024 * 1024 * 1024)) | _filter_mkfs >> $seqres.full 2> $tmp.mkfs
29 # Filesystems with directory block size greater than one FSB will not be tested,
30 # since "7 (i.e. XFS_DA_NODE_MAXDEPTH + 1 data block + 1 free block) * 2 (fsb
31 # count) = 14" is greater than the pseudo max extent count limit of 10.
32 # Extending the pseudo max limit won't help either. Consider the case where 1
33 # FSB is 1k in size and 1 dir block is 64k in size (i.e. fsb count = 64). In
34 # this case, the pseudo max limit has to be greater than 7 * 64 = 448 extents.
35 if (( $dirbsize > $dbsize )); then
36 _notrun "Directory block size ($dirbsize) is larger than FSB size ($dbsize)"
39 echo "Format and mount fs"
40 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
41 _scratch_mount >> $seqres.full
43 # Disable realtime inherit flag (if any) on root directory so that space on data
44 # device gets fragmented rather than realtime device.
45 _xfs_force_bdev data $SCRATCH_MNT
47 echo "Consume free space"
48 fillerdir=$SCRATCH_MNT/fillerdir
49 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
50 nr_free_blks=$((nr_free_blks * 90 / 100))
52 _fill_fs $((dbsize * nr_free_blks)) $fillerdir $dbsize 0 >> $seqres.full 2>&1
54 echo "Create fragmented filesystem"
55 for dentry in $(ls -1 $fillerdir/); do
56 $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
59 echo "Inject reduce_max_iextents error tag"
60 _scratch_inject_error reduce_max_iextents 1
62 echo "Inject bmap_alloc_minlen_extent error tag"
63 _scratch_inject_error bmap_alloc_minlen_extent 1
67 echo "* Create directory entries"
69 testdir=$SCRATCH_MNT/testdir
72 nr_dents=$((dbsize * 20 / dent_len))
73 for i in $(seq 1 $nr_dents); do
74 dentry="$(printf "%0255d" $i)"
75 touch ${testdir}/$dentry >> $seqres.full 2>&1 || break
78 echo "Verify directory's extent count"
79 nextents=$(_xfs_get_fsxattr nextents $testdir)
80 if (( $nextents > 10 )); then
81 echo "Extent count overflow check failed: nextents = $nextents"
87 echo "* Rename: Populate destination directory"
89 dstdir=$SCRATCH_MNT/dstdir
92 nr_dents=$((dirbsize * 20 / dent_len))
94 echo "Populate \$dstdir by moving new directory entries"
95 for i in $(seq 1 $nr_dents); do
96 dentry="$(printf "%0255d" $i)"
97 dentry=${SCRATCH_MNT}/${dentry}
98 touch $dentry || break
99 mv $dentry $dstdir >> $seqres.full 2>&1 || break
104 echo "Verify \$dstdir's extent count"
106 nextents=$(_xfs_get_fsxattr nextents $dstdir)
107 if (( $nextents > 10 )); then
108 echo "Extent count overflow check failed: nextents = $nextents"
114 echo "* Create multiple hard links to a single file"
116 testdir=$SCRATCH_MNT/testdir
119 testfile=$SCRATCH_MNT/testfile
122 nr_dents=$((dirbsize * 20 / dent_len))
124 echo "Create multiple hardlinks"
125 for i in $(seq 1 $nr_dents); do
126 dentry="$(printf "%0255d" $i)"
127 ln $testfile ${testdir}/${dentry} >> $seqres.full 2>&1 || break
132 echo "Verify directory's extent count"
133 nextents=$(_xfs_get_fsxattr nextents $testdir)
134 if (( $nextents > 10 )); then
135 echo "Extent count overflow check failed: nextents = $nextents"
141 echo "* Create multiple symbolic links to a single file"
143 testdir=$SCRATCH_MNT/testdir
146 testfile=$SCRATCH_MNT/testfile
149 nr_dents=$((dirbsize * 20 / dent_len))
151 echo "Create multiple symbolic links"
152 for i in $(seq 1 $nr_dents); do
153 dentry="$(printf "%0255d" $i)"
154 ln -s $testfile ${testdir}/${dentry} >> $seqres.full 2>&1 || break;
159 echo "Verify directory's extent count"
160 nextents=$(_xfs_get_fsxattr nextents $testdir)
161 if (( $nextents > 10 )); then
162 echo "Extent count overflow check failed: nextents = $nextents"