8cd31b3c7a60d3db2986e7154114bd4ab874f4f1
[xfstests-dev.git] / tests / generic / 064
1 #! /bin/bash
2 # FS QA Test No. generic/064
3 #
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.
11 #
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.
15 #
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.
20 #
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
24 #
25 #-----------------------------------------------------------------------
26 #
27
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35 trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40
41 # real QA test starts here
42 _supported_fs generic
43 _supported_os Linux
44
45 _require_scratch
46 _require_xfs_io_command "fiemap"
47 _require_xfs_io_command "finsert"
48 _require_xfs_io_command "fcollapse"
49 src=$SCRATCH_MNT/testfile
50 dest=$SCRATCH_MNT/testfile.dest
51 BLOCKS=100
52 BSIZE=`_get_block_size $SCRATCH_MNT`
53 rm -f $seqres.full
54
55 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
56 _scratch_mount || _fail "mount failed"
57 length=$(($BLOCKS * $BSIZE))
58
59 # Write file
60 _do "$XFS_IO_PROG -f -c \"pwrite 0 $length\" -c fsync $src"
61 cp $src $dest
62 extent_before=`_count_extents $dest`
63
64 # Insert alternate blocks
65 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
66         offset=$((($j*$BSIZE)*2))
67         _do "$XFS_IO_PROG -c \"finsert $offset $BSIZE\" $dest"
68 done
69
70 # Check if 50 extents are present, allowing some slop for file systems
71 # that don't have ideal allocation behavior
72 num_extents=`_count_extents $dest`
73 _within_tolerance "Extent count after inserts" $num_extents 50 0 6% -v
74
75 _check_scratch_fs
76 if [ $? -ne 0 ]; then
77         status=1
78         exit
79 fi
80
81 # Collapse alternate blocks
82 for (( j=0; j < $(($BLOCKS/2)); j++ )); do
83         offset=$((($j*$BSIZE)))
84         _do "$XFS_IO_PROG -c \"fcollapse $offset $BSIZE\" $dest"
85 done
86
87 extent_after=`_count_extents $dest`
88 if [ $extent_before -ne $extent_after ]; then
89         echo "extents mismatched before = $extent_before after = $extent_after"
90 fi
91
92 # compare original file and test file.
93 cmp $src $dest || _fail "file bytes check failed"
94
95 # success, all done
96 status=0
97 exit