2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Samsung Electronics. All Rights Reserved.
5 # FS QA Test No. generic/064
7 # Test multiple fallocate insert/collapse range calls on same file.
8 # Call insert range on alternate blocks multiple times until the file
9 # is left with 50 extents and as many holes. Then call collapse range
10 # on the previously inserted ranges to test merge code of collapse
11 # range. Also check for data integrity and file system consistency.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
21 # get standard environment, filters and checks
25 # real QA test starts here
30 _require_xfs_io_command "fiemap"
31 _require_xfs_io_command "finsert"
32 _require_xfs_io_command "fcollapse"
36 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
39 src=$SCRATCH_MNT/testfile
40 dest=$SCRATCH_MNT/testfile.dest
42 BSIZE=`_get_block_size $SCRATCH_MNT`
43 length=$(($BLOCKS * $BSIZE))
46 _do "$XFS_IO_PROG -f -c \"pwrite 0 $length\" -c fsync $src"
48 extent_before=`_count_extents $dest`
50 # Insert alternate blocks
51 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
52 offset=$((($j*$BSIZE)*2))
53 _do "$XFS_IO_PROG -c \"finsert $offset $BSIZE\" $dest"
56 # Check if 50 extents are present, allowing some slop for file systems
57 # that don't have ideal allocation behavior
58 num_extents=`_count_extents $dest`
59 _within_tolerance "Extent count after inserts" $num_extents 50 0 6% -v
67 # Collapse alternate blocks
68 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
69 offset=$((($j*$BSIZE)))
70 _do "$XFS_IO_PROG -c \"fcollapse $offset $BSIZE\" $dest"
73 extent_after=`_count_extents $dest`
74 if [ $extent_before -ne $extent_after ]; then
75 echo "extents mismatched before = $extent_before after = $extent_after"
78 # compare original file and test file.
79 cmp $src $dest || _fail "file bytes check failed"