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
29 _require_xfs_io_command "fiemap"
30 _require_xfs_io_command "finsert"
31 _require_xfs_io_command "fcollapse"
35 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
38 src=$SCRATCH_MNT/testfile
39 dest=$SCRATCH_MNT/testfile.dest
41 BSIZE=`_get_block_size $SCRATCH_MNT`
42 length=$(($BLOCKS * $BSIZE))
45 _do "$XFS_IO_PROG -f -c \"pwrite 0 $length\" -c fsync $src"
47 extent_before=`_count_extents $dest`
49 # Insert alternate blocks
50 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
51 offset=$((($j*$BSIZE)*2))
52 _do "$XFS_IO_PROG -c \"finsert $offset $BSIZE\" $dest"
55 # Check if 50 extents are present, allowing some slop for file systems
56 # that don't have ideal allocation behavior
57 num_extents=`_count_extents $dest`
58 _within_tolerance "Extent count after inserts" $num_extents 50 0 6% -v
66 # Collapse alternate blocks
67 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
68 offset=$((($j*$BSIZE)))
69 _do "$XFS_IO_PROG -c \"fcollapse $offset $BSIZE\" $dest"
72 extent_after=`_count_extents $dest`
73 if [ $extent_before -ne $extent_after ]; then
74 echo "extents mismatched before = $extent_before after = $extent_after"
77 # compare original file and test file.
78 cmp $src $dest || _fail "file bytes check failed"