reflink: ensure that we can handle reflinking a lot of extents
[xfstests-dev.git] / tests / generic / 017
1 #! /bin/bash
2 # FS QA Test No. generci/017
3 #
4 # Test multiple fallocate collapse range calls on same file.
5 # For different blocksizes, collapse a single alternate block multiple times
6 # until the file is left with 80 blocks and as much number of extents.
7 # Also check for file system consistency after completing this operation
8 # for each blocksize.
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2013 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 "fcollapse"
48 _do_die_on_error=y
49
50 _scratch_mkfs > /dev/null 2>&1
51 _scratch_mount
52
53 testfile=$SCRATCH_MNT/$seq.$$
54 BLOCKS=10240
55
56 BSIZE=`get_block_size $SCRATCH_MNT`
57
58 length=$(($BLOCKS * $BSIZE))
59
60 # Write file
61 $XFS_IO_PROG -f -c "pwrite 0 $length" -c fsync $testfile > /dev/null
62
63 # Collapse alternate blocks 
64 for (( i = 1; i <= 7; i++ )); do
65         for (( j=0; j < $(($BLOCKS/(2**$i))); j++ )); do
66                 offset=$(($j*$BSIZE))
67                 $XFS_IO_PROG -c "fcollapse $offset $BSIZE" $testfile > /dev/null
68         done
69 done
70
71 # Check if 80 extents are present
72 $XFS_IO_PROG -c "fiemap -v" $testfile | grep "^ *[0-9]*:" |wc -l
73
74 # success, all done
75 status=0
76 exit