xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 531
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2021 Chandan Babu R.  All Rights Reserved.
4 #
5 # FS QA Test 531
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # punching out an extent.
9 . ./common/preamble
10 _begin_fstest auto quick punch zero insert collapse
11
12 # Import common functions.
13 . ./common/filter
14 . ./common/inject
15
16 # real QA test starts here
17
18 _supported_fs xfs
19 _require_scratch
20 _require_xfs_debug
21 _require_xfs_io_command "fpunch"
22 _require_xfs_io_command "finsert"
23 _require_xfs_io_command "fcollapse"
24 _require_xfs_io_command "fzero"
25 _require_xfs_io_error_injection "reduce_max_iextents"
26
27 echo "Format and mount fs"
28 _scratch_mkfs >> $seqres.full
29 _scratch_mount >> $seqres.full
30
31 bsize=$(_get_file_block_size $SCRATCH_MNT)
32 nr_blks=30
33
34 testfile=$SCRATCH_MNT/testfile
35
36 for op in fpunch finsert fcollapse fzero; do
37         echo "* $op regular file"
38
39         echo "Create \$testfile"
40         touch $testfile
41
42         echo "Inject reduce_max_iextents error tag"
43         _scratch_inject_error reduce_max_iextents 1
44
45         $XFS_IO_PROG -f -s \
46                      -c "pwrite -b $((nr_blks * bsize)) 0 $((nr_blks * bsize))" \
47                      $testfile  >> $seqres.full
48
49         echo "$op alternating blocks"
50         for i in $(seq 1 2 $((nr_blks - 1))); do
51                 $XFS_IO_PROG -f -c "$op $((i * bsize)) $bsize" $testfile \
52                        >> $seqres.full 2>&1
53                 [[ $? != 0 ]] && break
54         done
55
56         echo "Verify \$testfile's extent count"
57
58         nextents=$(_xfs_get_fsxattr nextents $testfile)
59         if (( $nextents > 10 )); then
60                 echo "Extent count overflow check failed: nextents = $nextents"
61                 exit 1
62         fi
63
64         echo "Disable reduce_max_iextents error tag"
65         _scratch_inject_error reduce_max_iextents 0
66
67         rm $testfile
68 done
69
70 # success, all done
71 status=0
72 exit