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 xattrs.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
31 # remove previous $seqres.full before test
34 # real QA test starts here
40 _require_test_program "punch-alternating"
41 _require_xfs_io_error_injection "reduce_max_iextents"
42 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
44 echo "Format and mount fs"
45 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
46 _scratch_mount >> $seqres.full
48 # Disable realtime inherit flag (if any) on root directory so that space on data
49 # device gets fragmented rather than realtime device.
50 $XFS_IO_PROG -c 'chattr -t' $SCRATCH_MNT
52 bsize=$(_get_block_size $SCRATCH_MNT)
56 testfile=$SCRATCH_MNT/testfile
58 echo "Consume free space"
59 fillerdir=$SCRATCH_MNT/fillerdir
60 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
61 nr_free_blks=$((nr_free_blks * 90 / 100))
63 _fill_fs $((bsize * nr_free_blks)) $fillerdir $bsize 0 >> $seqres.full 2>&1
65 echo "Create fragmented filesystem"
66 for dentry in $(ls -1 $fillerdir/); do
67 $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
70 echo "Inject bmap_alloc_minlen_extent error tag"
71 _scratch_inject_error bmap_alloc_minlen_extent 1
75 echo "Create \$testfile"
78 echo "Inject reduce_max_iextents error tag"
79 _scratch_inject_error reduce_max_iextents 1
82 nr_attrs=$((bsize * 20 / attr_len))
83 for i in $(seq 1 $nr_attrs); do
84 attr="$(printf "trusted.%0247d" $i)"
85 $SETFATTR_PROG -n "$attr" $testfile >> $seqres.full 2>&1
86 [[ $? != 0 ]] && break
89 echo "Verify \$testfile's naextent count"
91 naextents=$(_xfs_get_fsxattr naextents $testfile)
92 if (( $naextents > 10 )); then
93 echo "Extent count overflow check failed: naextents = $naextents"
97 echo "Disable reduce_max_iextents error tag"
98 _scratch_inject_error reduce_max_iextents 0
100 echo "Remove \$testfile"
103 echo "* Remove xattrs"
105 echo "Create \$testfile"
108 echo "Create initial xattr extents"
113 nr_attrs=$((bsize / attr_len))
115 while (( $naextents < 4 )); do
116 end=$((start + nr_attrs - 1))
118 for i in $(seq $start $end); do
119 attr="$(printf "trusted.%0247d" $i)"
120 $SETFATTR_PROG -n $attr $testfile
125 naextents=$(_xfs_get_fsxattr naextents $testfile)
128 echo "Inject reduce_max_iextents error tag"
129 _scratch_inject_error reduce_max_iextents 1
131 echo "Remove xattr to trigger -EFBIG"
132 attr="$(printf "trusted.%0247d" 1)"
133 $SETFATTR_PROG -x "$attr" $testfile >> $seqres.full 2>&1
134 if [[ $? == 0 ]]; then
135 echo "Xattr removal succeeded; Should have failed "
139 echo "Disable reduce_max_iextents error tag"
140 _scratch_inject_error reduce_max_iextents 0