2 # FS QA Test No. generic/064
4 # Test multiple fallocate insert/collapse range calls on same file.
5 # Call insert range on alternate blocks multiple times until the file
6 # is left with 50 extents and as many holes. Then call collapse range
7 # on the previously inserted ranges to test merge code of collapse
8 # range. Also check for data integrity and file system consistency.
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2015 Samsung Electronics. All Rights Reserved.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
34 status=1 # failure is the default!
35 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
37 # get standard environment, filters and checks
41 # real QA test starts here
46 _require_xfs_io_command "fiemap"
47 _require_xfs_io_command "finsert"
48 _require_xfs_io_command "fcollapse"
52 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
53 _scratch_mount || _fail "mount failed"
55 src=$SCRATCH_MNT/testfile
56 dest=$SCRATCH_MNT/testfile.dest
58 BSIZE=`_get_block_size $SCRATCH_MNT`
59 length=$(($BLOCKS * $BSIZE))
62 _do "$XFS_IO_PROG -f -c \"pwrite 0 $length\" -c fsync $src"
64 extent_before=`_count_extents $dest`
66 # Insert alternate blocks
67 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
68 offset=$((($j*$BSIZE)*2))
69 _do "$XFS_IO_PROG -c \"finsert $offset $BSIZE\" $dest"
72 # Check if 50 extents are present, allowing some slop for file systems
73 # that don't have ideal allocation behavior
74 num_extents=`_count_extents $dest`
75 _within_tolerance "Extent count after inserts" $num_extents 50 0 6% -v
83 # Collapse alternate blocks
84 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
85 offset=$((($j*$BSIZE)))
86 _do "$XFS_IO_PROG -c \"fcollapse $offset $BSIZE\" $dest"
89 extent_after=`_count_extents $dest`
90 if [ $extent_before -ne $extent_after ]; then
91 echo "extents mismatched before = $extent_before after = $extent_after"
94 # compare original file and test file.
95 cmp $src $dest || _fail "file bytes check failed"