generic/064: access SCRATCH_MNT after _scratch_mount
[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
50 rm -f $seqres.full
51
52 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
53 _scratch_mount || _fail "mount failed"
54
55 src=$SCRATCH_MNT/testfile
56 dest=$SCRATCH_MNT/testfile.dest
57 BLOCKS=100
58 BSIZE=`_get_block_size $SCRATCH_MNT`
59 length=$(($BLOCKS * $BSIZE))
60
61 # Write file
62 _do "$XFS_IO_PROG -f -c \"pwrite 0 $length\" -c fsync $src"
63 cp $src $dest
64 extent_before=`_count_extents $dest`
65
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"
70 done
71
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
76
77 _check_scratch_fs
78 if [ $? -ne 0 ]; then
79         status=1
80         exit
81 fi
82
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"
87 done
88
89 extent_after=`_count_extents $dest`
90 if [ $extent_before -ne $extent_after ]; then
91         echo "extents mismatched before = $extent_before after = $extent_after"
92 fi
93
94 # compare original file and test file.
95 cmp $src $dest || _fail "file bytes check failed"
96
97 # success, all done
98 status=0
99 exit