xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[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 . ./common/preamble
10 _begin_fstest auto quick
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 "falloc"
22 _require_xfs_io_error_injection "reduce_max_iextents"
23
24 echo "Format and mount fs"
25 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >> $seqres.full
26 _scratch_mount >> $seqres.full
27
28 bsize=$(_get_file_block_size $SCRATCH_MNT)
29
30 testfile=${SCRATCH_MNT}/testfile
31
32 nr_blks=15
33
34 for io in Buffered Direct; do
35         echo "* $io write to unwritten extent"
36
37         echo "Fallocate $nr_blks blocks"
38         $XFS_IO_PROG -f -c "falloc 0 $((nr_blks * bsize))" $testfile >> $seqres.full
39
40         if [[ $io == "Buffered" ]]; then
41                 xfs_io_flag=""
42         else
43                 xfs_io_flag="-d"
44         fi
45
46         echo "Inject reduce_max_iextents error tag"
47         _scratch_inject_error reduce_max_iextents 1
48
49         echo "$io write to every other block of fallocated space"
50         for i in $(seq 1 2 $((nr_blks - 1))); do
51                 $XFS_IO_PROG -f -s $xfs_io_flag -c "pwrite $((i * bsize)) $bsize" \
52                        $testfile >> $seqres.full 2>&1
53                 [[ $? != 0 ]] && break
54         done
55
56         echo "Verify \$testfile's extent count"
57         nextents=$(_xfs_get_fsxattr nextents $testfile)
58         if (( $nextents > 10 )); then
59                 echo "Extent count overflow check failed: nextents = $nextents"
60                 exit 1
61         fi
62
63         echo "Disable reduce_max_iextents error tag"
64         _scratch_inject_error reduce_max_iextents 0
65
66         rm $testfile
67 done
68
69 # success, all done
70 status=0
71 exit