generic: Make some shared tests generic
[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_fiemap
47 _require_xfs_io_falloc_collapse
48 _do_die_on_error=y
49 testfile=$SCRATCH_MNT/$seq.$$
50 BLOCKS=10240
51
52 for (( BSIZE = 1024; BSIZE <= 4096; BSIZE *= 2 )); do
53
54         length=$(($BLOCKS * $BSIZE))
55         case $FSTYP in
56         xfs)
57         _scratch_mkfs -b size=$BSIZE >> $seqres.full 2>&1
58         ;;
59         ext4)
60         _scratch_mkfs -b $BSIZE >> $seqres.full 2>&1
61         ;;
62         esac
63         _scratch_mount >> $seqres.full 2>&1
64
65         # Write file
66         $XFS_IO_PROG -f -c "pwrite 0 $length" -c fsync $testfile > /dev/null
67
68         # Collapse alternate blocks 
69         for (( i = 1; i <= 7; i++ )); do
70                 for (( j=0; j < $(($BLOCKS/(2**$i))); j++ )); do
71                         offset=$(($j*$BSIZE))
72                         $XFS_IO_PROG -c "fcollapse $offset $BSIZE" $testfile > /dev/null
73                 done
74         done
75
76         # Check if 80 extents are present
77         $XFS_IO_PROG -c "fiemap -v" $testfile | grep "^ *[0-9]*:" |wc -l
78
79         _check_scratch_fs
80         if [ $? -ne 0 ]; then
81                 status=1
82                 exit
83         fi
84
85         umount $SCRATCH_MNT
86 done
87
88 # success, all done
89 status=0
90 exit