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 a single extent while there's no possibility of splitting an existing
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
33 # remove previous $seqres.full before test
36 # real QA test starts here
42 _require_test_program "punch-alternating"
43 _require_xfs_io_command "falloc"
44 _require_xfs_io_error_injection "reduce_max_iextents"
45 _require_xfs_io_error_injection "bmap_alloc_minlen_extent"
47 echo "Format and mount fs"
48 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full
49 _scratch_mount -o uquota >> $seqres.full
51 bsize=$(_get_file_block_size $SCRATCH_MNT)
53 echo "* Delalloc to written extent conversion"
55 testfile=$SCRATCH_MNT/testfile
57 echo "Inject reduce_max_iextents error tag"
58 _scratch_inject_error reduce_max_iextents 1
62 echo "Create fragmented file"
63 for i in $(seq 0 2 $((nr_blks - 1))); do
64 $XFS_IO_PROG -f -s -c "pwrite $((i * bsize)) $bsize" $testfile \
66 [[ $? != 0 ]] && break
69 echo "Verify \$testfile's extent count"
71 nextents=$(_xfs_get_fsxattr nextents $testfile)
72 if (( $nextents > 10 )); then
73 echo "Extent count overflow check failed: nextents = $nextents"
79 echo "* Fallocate unwritten extents"
81 echo "Fallocate fragmented file"
82 for i in $(seq 0 2 $((nr_blks - 1))); do
83 $XFS_IO_PROG -f -c "falloc $((i * bsize)) $bsize" $testfile \
85 [[ $? != 0 ]] && break
88 echo "Verify \$testfile's extent count"
90 nextents=$(_xfs_get_fsxattr nextents $testfile)
91 if (( $nextents > 10 )); then
92 echo "Extent count overflow check failed: nextents = $nextents"
98 echo "* Directio write"
100 echo "Create fragmented file via directio writes"
101 for i in $(seq 0 2 $((nr_blks - 1))); do
102 $XFS_IO_PROG -d -s -f -c "pwrite $((i * bsize)) $bsize" $testfile \
104 [[ $? != 0 ]] && break
107 echo "Verify \$testfile's extent count"
109 nextents=$(_xfs_get_fsxattr nextents $testfile)
110 if (( $nextents > 10 )); then
111 echo "Extent count overflow check failed: nextents = $nextents"
117 # Check if XFS gracefully returns with an error code when we try to increase
118 # extent count of user quota inode beyond the pseudo max extent count limit.
119 echo "* Extend quota inodes"
121 echo "Disable reduce_max_iextents error tag"
122 _scratch_inject_error reduce_max_iextents 0
124 echo "Consume free space"
125 fillerdir=$SCRATCH_MNT/fillerdir
126 nr_free_blks=$(stat -f -c '%f' $SCRATCH_MNT)
127 nr_free_blks=$((nr_free_blks * 90 / 100))
129 _fill_fs $((bsize * nr_free_blks)) $fillerdir $bsize 0 >> $seqres.full 2>&1
131 echo "Create fragmented filesystem"
132 for dentry in $(ls -1 $fillerdir/); do
133 $here/src/punch-alternating $fillerdir/$dentry >> $seqres.full
136 echo "Inject reduce_max_iextents error tag"
137 _scratch_inject_error reduce_max_iextents 1
139 echo "Inject bmap_alloc_minlen_extent error tag"
140 _scratch_inject_error bmap_alloc_minlen_extent 1
144 # This is a rough calculation; It doesn't take block headers into
146 # gdb -batch vmlinux -ex 'print sizeof(struct xfs_dqblk)'
148 nr_quotas_per_block=$((bsize / 136))
149 nr_quotas=$((nr_quotas_per_block * nr_blks))
151 echo "Extend uquota file"
152 for i in $(seq 0 $nr_quotas_per_block $nr_quotas); do
153 chown $i $testfile >> $seqres.full 2>&1
154 [[ $? != 0 ]] && break
157 _scratch_unmount >> $seqres.full
159 echo "Verify uquota inode's extent count"
160 uquotino=$(_scratch_xfs_get_metadata_field 'uquotino' 'sb 0')
162 nextents=$(_scratch_get_iext_count $uquotino data || \
163 _fail "Unable to obtain inode fork's extent count")
164 if (( $nextents > 10 )); then
165 echo "Extent count overflow check failed: nextents = $nextents"