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 bsize=$(_get_block_size $SCRATCH_MNT)
52 testfile=$SCRATCH_MNT/testfile
54 echo "Consume free space"
55 fillerdir=$SCRATCH_MNT/fillerdir
56 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
57 nr_free_blks=$((nr_free_blks * 90 / 100))
59 _fill_fs $((bsize * nr_free_blks)) $fillerdir $bsize 0 >> $seqres.full 2>&1
61 echo "Create fragmented filesystem"
62 for dentry in $(ls -1 $fillerdir/); do
63 $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
66 echo "Inject reduce_max_iextents error tag"
67 _scratch_inject_error reduce_max_iextents 1
69 echo "Inject bmap_alloc_minlen_extent error tag"
70 _scratch_inject_error bmap_alloc_minlen_extent 1
74 echo "Create \$testfile"
78 nr_attrs=$((bsize * 20 / attr_len))
79 for i in $(seq 1 $nr_attrs); do
80 attr="$(printf "trusted.%0247d" $i)"
81 $SETFATTR_PROG -n "$attr" $testfile >> $seqres.full 2>&1
82 [[ $? != 0 ]] && break
85 echo "Verify \$testfile's naextent count"
87 naextents=$(_xfs_get_fsxattr naextents $testfile)
88 if (( $naextents > 10 )); then
89 echo "Extent count overflow check failed: naextents = $naextents"
93 echo "Remove \$testfile"
96 echo "* Remove xattrs"
98 echo "Create \$testfile"
101 echo "Disable reduce_max_iextents error tag"
102 _scratch_inject_error reduce_max_iextents 0
104 echo "Create initial xattr extents"
109 nr_attrs=$((bsize / attr_len))
111 while (( $naextents < 4 )); do
112 end=$((start + nr_attrs - 1))
114 for i in $(seq $start $end); do
115 attr="$(printf "trusted.%0247d" $i)"
116 $SETFATTR_PROG -n $attr $testfile
121 naextents=$(_xfs_get_fsxattr naextents $testfile)
124 echo "Inject reduce_max_iextents error tag"
125 _scratch_inject_error reduce_max_iextents 1
127 echo "Remove xattr to trigger -EFBIG"
128 attr="$(printf "trusted.%0247d" 1)"
129 $SETFATTR_PROG -x "$attr" $testfile >> $seqres.full 2>&1
130 if [[ $? == 0 ]]; then
131 echo "Xattr removal succeeded; Should have failed "
135 rm $testfile && echo "Successfully removed \$testfile"