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 _begin_fstest auto quick prealloc collapse insert
15 # Import common functions.
18 # real QA test starts here
22 _require_xfs_io_command "fiemap"
23 _require_xfs_io_command "finsert"
24 _require_xfs_io_command "fcollapse"
26 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
29 src=$SCRATCH_MNT/testfile
30 dest=$SCRATCH_MNT/testfile.dest
32 BSIZE=`_get_block_size $SCRATCH_MNT`
33 length=$(($BLOCKS * $BSIZE))
36 _do "$XFS_IO_PROG -f -c \"pwrite 0 $length\" -c fsync $src"
38 extent_before=`_count_extents $dest`
40 # Insert alternate blocks
41 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
42 offset=$((($j*$BSIZE)*2))
43 _do "$XFS_IO_PROG -c \"finsert $offset $BSIZE\" $dest"
46 # Check if 50 extents are present, allowing some slop for file systems
47 # that don't have ideal allocation behavior
48 num_extents=`_count_extents $dest`
49 _within_tolerance "Extent count after inserts" $num_extents 50 0 6% -v
57 # Collapse alternate blocks
58 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
59 offset=$((($j*$BSIZE)))
60 _do "$XFS_IO_PROG -c \"fcollapse $offset $BSIZE\" $dest"
63 extent_after=`_count_extents $dest`
64 if [ $extent_before -ne $extent_after ]; then
65 echo "extents mismatched before = $extent_before after = $extent_after"
68 # compare original file and test file.
69 cmp $src $dest || _fail "file bytes check failed"