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 # swapping forks between files
10 _begin_fstest auto quick
12 # Import common functions.
16 # real QA test starts here
21 _require_xfs_scratch_rmapbt
22 _require_xfs_io_command "fcollapse"
23 _require_xfs_io_command "swapext"
24 _require_xfs_io_error_injection "reduce_max_iextents"
26 echo "* Swap extent forks"
28 echo "Format and mount fs"
29 _scratch_mkfs >> $seqres.full
30 _scratch_mount >> $seqres.full
32 bsize=$(_get_block_size $SCRATCH_MNT)
34 srcfile=${SCRATCH_MNT}/srcfile
35 donorfile=${SCRATCH_MNT}/donorfile
37 echo "Create \$donorfile having an extent of length 67 blocks"
38 $XFS_IO_PROG -f -s -c "pwrite -b $((17 * bsize)) 0 $((17 * bsize))" $donorfile \
41 # After the for loop the donor file will have the following extent layout
42 # | 0-4 | 5 | 6 | 7 | 8 | 9 | 10 |
43 echo "Fragment \$donorfile"
44 for i in $(seq 5 10); do
45 start_offset=$((i * bsize))
46 $XFS_IO_PROG -f -c "fcollapse $start_offset $bsize" $donorfile >> $seqres.full
49 echo "Create \$srcfile having an extent of length 18 blocks"
50 $XFS_IO_PROG -f -s -c "pwrite -b $((18 * bsize)) 0 $((18 * bsize))" $srcfile \
53 echo "Fragment \$srcfile"
54 # After the for loop the src file will have the following extent layout
55 # | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7-10 |
56 for i in $(seq 1 7); do
57 start_offset=$((i * bsize))
58 $XFS_IO_PROG -f -c "fcollapse $start_offset $bsize" $srcfile >> $seqres.full
61 echo "Collect \$donorfile's extent count"
62 donor_nr_exts=$(_xfs_get_fsxattr nextents $donorfile)
64 echo "Collect \$srcfile's extent count"
65 src_nr_exts=$(_xfs_get_fsxattr nextents $srcfile)
67 echo "Inject reduce_max_iextents error tag"
68 _scratch_inject_error reduce_max_iextents 1
70 echo "Swap \$srcfile's and \$donorfile's extent forks"
71 $XFS_IO_PROG -f -c "swapext $donorfile" $srcfile >> $seqres.full 2>&1
73 echo "Check for \$donorfile's extent count overflow"
74 nextents=$(_xfs_get_fsxattr nextents $donorfile)
76 if (( $nextents == $src_nr_exts )); then
77 echo "\$donorfile: Extent count overflow check failed"
80 echo "Check for \$srcfile's extent count overflow"
81 nextents=$(_xfs_get_fsxattr nextents $srcfile)
83 if (( $nextents == $donor_nr_exts )); then
84 echo "\$srcfile: Extent count overflow check failed"