xfs: Check for extent overflow when writing to unwritten extent
[xfstests-dev.git] / tests / xfs / 534
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 534
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # writing to an unwritten extent.
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/inject
28
29 # remove previous $seqres.full before test
30 rm -f $seqres.full
31
32 # real QA test starts here
33
34 _supported_fs xfs
35 _require_scratch
36 _require_xfs_debug
37 _require_xfs_io_command "falloc"
38 _require_xfs_io_error_injection "reduce_max_iextents"
39
40 echo "Format and mount fs"
41 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
42 _scratch_mount >> $seqres.full
43
44 bsize=$(_get_file_block_size $SCRATCH_MNT)
45
46 testfile=${SCRATCH_MNT}/testfile
47
48 echo "Inject reduce_max_iextents error tag"
49 _scratch_inject_error reduce_max_iextents 1
50
51 nr_blks=15
52
53 for io in Buffered Direct; do
54         echo "* $io write to unwritten extent"
55
56         echo "Fallocate $nr_blks blocks"
57         $XFS_IO_PROG -f -c "falloc 0 $((nr_blks * bsize))" $testfile >> $seqres.full
58
59         if [[ $io == "Buffered" ]]; then
60                 xfs_io_flag=""
61         else
62                 xfs_io_flag="-d"
63         fi
64
65         echo "$io write to every other block of fallocated space"
66         for i in $(seq 1 2 $((nr_blks - 1))); do
67                 $XFS_IO_PROG -f -s $xfs_io_flag -c "pwrite $((i * bsize)) $bsize" \
68                        $testfile >> $seqres.full 2>&1
69                 [[ $? != 0 ]] && break
70         done
71
72         echo "Verify \$testfile's extent count"
73         nextents=$(_xfs_get_fsxattr nextents $testfile)
74         if (( $nextents > 10 )); then
75                 echo "Extent count overflow check failed: nextents = $nextents"
76                 exit 1
77         fi
78
79         rm $testfile
80 done
81
82 # success, all done
83 status=0
84 exit