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 # writing to a shared extent.
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
24 # get standard environment, filters and checks
30 # remove previous $seqres.full before test
33 # real QA test starts here
37 _require_scratch_reflink
39 _require_xfs_io_command "reflink"
40 _require_xfs_io_command "funshare"
41 _require_xfs_io_error_injection "reduce_max_iextents"
43 echo "Format and mount fs"
44 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full
45 _scratch_mount >> $seqres.full
47 bsize=$(_get_block_size $SCRATCH_MNT)
51 srcfile=${SCRATCH_MNT}/srcfile
52 dstfile=${SCRATCH_MNT}/dstfile
54 echo "Inject reduce_max_iextents error tag"
55 _scratch_inject_error reduce_max_iextents 1
57 echo "Create a \$srcfile having an extent of length $nr_blks blocks"
58 $XFS_IO_PROG -f -c "pwrite -b $((nr_blks * bsize)) 0 $((nr_blks * bsize))" \
59 -c fsync $srcfile >> $seqres.full
61 echo "* Write to shared extent"
63 echo "Share the extent with \$dstfile"
64 _reflink $srcfile $dstfile >> $seqres.full
66 echo "Buffered write to every other block of \$dstfile's shared extent"
67 for i in $(seq 1 2 $((nr_blks - 1))); do
68 $XFS_IO_PROG -f -s -c "pwrite $((i * bsize)) $bsize" $dstfile \
70 [[ $? != 0 ]] && break
73 echo "Verify \$dstfile's extent count"
74 nextents=$(_xfs_get_fsxattr nextents $dstfile)
75 if (( $nextents > 10 )); then
76 echo "Extent count overflow check failed: nextents = $nextents"
82 echo "* Funshare shared extent"
84 echo "Share the extent with \$dstfile"
85 _reflink $srcfile $dstfile >> $seqres.full
87 echo "Funshare every other block of \$dstfile's shared extent"
88 for i in $(seq 1 2 $((nr_blks - 1))); do
89 $XFS_IO_PROG -f -s -c "funshare $((i * bsize)) $bsize" $dstfile \
91 [[ $? != 0 ]] && break
94 echo "Verify \$dstfile's extent count"
95 nextents=$(_xfs_get_fsxattr nextents $dstfile)
96 if (( $nextents > 10 )); then
97 echo "Extent count overflow check failed: nextents = $nextents"