b011827f2a90100f648122de923c7682c6b48fc4
[xfstests-dev.git] / 190
1 #! /bin/sh
2 #
3 #-----------------------------------------------------------------------
4 # Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 #
19 #-----------------------------------------------------------------------
20 #
21 # FSQA Test No. 190
22 #
23 # This test uses xfs_io to unreserve space in a file at various different
24 # offsets and sizes. The script then verifies the holes are in the correct
25 # location.
26 #
27 # PV 985792
28 #
29 # creator
30 owner=pleckie@sgi.com
31
32 #This is the list of holes to punch in the file limited to $filesize
33 #NOTE holes cannot overlap or this script will fail.
34 holes="4096:4096 303104:4096 1048576:512 1051648:8192 1065984:8192 1085440:7168"
35 #filesize in MB
36 filesize=10
37 #Name of file to perform the test on
38 filename=test-190
39
40 seq=`basename $0`
41 echo "QA output created by $seq"
42
43 here=`pwd`
44 tmp=/tmp/$$
45 status=0    # success is the default!
46 rm -f $seq.full
47
48 # get standard environment, filters and checks
49 . ./common.rc
50 . ./common.filter
51
52 # real QA test starts here
53 _supported_fs xfs
54 _supported_os Linux
55
56 _require_scratch
57 _scratch_mkfs_xfs >/dev/null 2>&1
58 _scratch_mount
59 fsblocksize=`xfs_info $SCRATCH_MNT|sed 's/=/ /g'|awk '/^data / { print $3 }'`
60
61 dd if=/dev/zero of=$SCRATCH_MNT/$filename bs=1024k count=10 >> $seq.full 2>&1
62
63 # run DMAPI test using verbose output
64 echo Punching holes in file
65 echo Punching holes in file >> $seq.full
66 for i in $holes ; do
67         echo xfs_io -c "unresvsp `echo $i |$SED_PROG 's/:/ /g'`" $SCRATCH_MNT/$filename >> $seq.full
68         xfs_io -c "unresvsp `echo $i |$SED_PROG 's/:/ /g'`" $SCRATCH_MNT/$filename ;
69 done
70
71 echo Verifying holes are in the correct spots:
72
73 xfs_bmap=`xfs_bmap $SCRATCH_MNT/$filename`
74 xfs_bmap $SCRATCH_MNT/$filename >> $seq.full
75 for i in $holes ; do
76         holeStart=$[`echo $i|$SED_PROG 's/:/ /g'|awk '{print $1}'`];
77         holeEnd=$[`echo $i|$SED_PROG 's/:/ /g'|awk '{print $2}'`];
78
79         #Round hole size down to a multiple of $fsblocksize
80         holeEnd=$[(($holeStart+$holeEnd)/$fsblocksize)*$fsblocksize]
81
82         #Round hole start up to a multiple of $fsblocksize
83         if [ $[$holeStart % $fsblocksize] -gt 0 ] ; then
84                 holeStart=$[($holeStart/$fsblocksize +1) * $fsblocksize]
85         fi
86         #xfs_bmap prints holes in the following format
87         #                1: [8..15]: hole
88         bmap="\[$[$holeStart/512]..$[($holeEnd/512) -1]\]";
89         echo $bmap >> $seq.full
90         if [ $holeEnd == $holeStart ] ; then
91                 continue #there is no hole
92         fi
93         if ! echo $xfs_bmap|grep -q $bmap; then
94                 echo Offset $holeStart to $holeEnd  basic blocks failed;
95                 status=1;
96         fi
97 done
98 if [ $status == 0 ] ; then
99         echo Test $seq Passed.
100 fi
101
102 exit