xfs: Check for extent overflow when remapping an extent
[xfstests-dev.git] / tests / xfs / 536
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 536
6 #
7 # Verify that XFS does not cause inode fork's extent count to overflow when
8 # remapping extents from one file's inode fork to another.
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/reflink
28 . ./common/inject
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34
35 _supported_fs xfs
36 _require_scratch
37 _require_scratch_reflink
38 _require_xfs_debug
39 _require_xfs_io_command "reflink"
40 _require_xfs_io_error_injection "reduce_max_iextents"
41
42 echo "* Reflink remap extents"
43
44 echo "Format and mount fs"
45 _scratch_mkfs >> $seqres.full
46 _scratch_mount >> $seqres.full
47
48 bsize=$(_get_block_size $SCRATCH_MNT)
49
50 srcfile=${SCRATCH_MNT}/srcfile
51 dstfile=${SCRATCH_MNT}/dstfile
52
53 nr_blks=15
54
55 echo "Create \$srcfile having an extent of length $nr_blks blocks"
56 $XFS_IO_PROG -f -c "pwrite -b $((nr_blks * bsize))  0 $((nr_blks * bsize))" \
57        -c fsync $srcfile >> $seqres.full
58
59 echo "Create \$dstfile having an extent of length $nr_blks blocks"
60 $XFS_IO_PROG -f -c "pwrite -b $((nr_blks * bsize))  0 $((nr_blks * bsize))" \
61        -c fsync $dstfile >> $seqres.full
62
63 echo "Inject reduce_max_iextents error tag"
64 _scratch_inject_error reduce_max_iextents 1
65
66 echo "Reflink every other block from \$srcfile into \$dstfile"
67 for i in $(seq 1 2 $((nr_blks - 1))); do
68         _reflink_range $srcfile $((i * bsize)) $dstfile $((i * bsize)) $bsize \
69                        >> $seqres.full 2>&1
70 done
71
72 echo "Verify \$dstfile's extent count"
73 nextents=$(_xfs_get_fsxattr nextents $dstfile)
74 if (( $nextents > 10 )); then
75         echo "Extent count overflow check failed: nextents = $nextents"
76         exit 1
77 fi
78
79 # success, all done
80 status=0
81 exit