xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 190
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2008 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FSQA Test No. 190
6 #
7 # This test uses xfs_io to unreserve space in a file at various different
8 # offsets and sizes. The script then verifies the holes are in the correct
9 # location.
10 #
11 # PV 985792
12 #
13 #This is the list of holes to punch in the file limited to $filesize
14 #NOTE holes cannot overlap or this script will fail.
15 holes="4096:4096 303104:4096 1048576:512 1051648:8192 1065984:8192 1085440:7168"
16 #filesize in MB
17 filesize=10
18 #Name of file to perform the test on
19 filename=test-190
20
21 seq=`basename $0`
22 seqres=$RESULT_DIR/$seq
23 echo "QA output created by $seq"
24
25 here=`pwd`
26 tmp=/tmp/$$
27 status=0    # success is the default!
28 rm -f $seqres.full
29
30 # get standard environment, filters and checks
31 . ./common/rc
32 . ./common/filter
33
34 # real QA test starts here
35 _supported_fs xfs
36 _supported_os Linux
37
38 _require_scratch
39 _scratch_mkfs_xfs >/dev/null 2>&1
40 _scratch_mount
41 fsblocksize=`$XFS_INFO_PROG $SCRATCH_MNT|sed 's/=/ /g'|awk '/^data / { print $3 }'`
42
43 dd if=/dev/zero of=$SCRATCH_MNT/$filename bs=1024k count=10 >> $seqres.full 2>&1
44
45 # run DMAPI test using verbose output
46 echo Punching holes in file
47 echo Punching holes in file >> $seqres.full
48 for i in $holes ; do
49         echo $XFS_IO_PROG -c "unresvsp `echo $i |$SED_PROG 's/:/ /g'`" $SCRATCH_MNT/$filename >> $seqres.full
50         $XFS_IO_PROG -c "unresvsp `echo $i |$SED_PROG 's/:/ /g'`" $SCRATCH_MNT/$filename ;
51 done
52
53 echo Verifying holes are in the correct spots:
54
55 xfs_bmap=`xfs_bmap $SCRATCH_MNT/$filename`
56 xfs_bmap $SCRATCH_MNT/$filename >> $seqres.full
57 for i in $holes ; do
58         holeStart=$[`echo $i|$SED_PROG 's/:/ /g'|awk '{print $1}'`];
59         holeEnd=$[`echo $i|$SED_PROG 's/:/ /g'|awk '{print $2}'`];
60
61         #Round hole size down to a multiple of $fsblocksize
62         holeEnd=$[(($holeStart+$holeEnd)/$fsblocksize)*$fsblocksize]
63
64         #Round hole start up to a multiple of $fsblocksize
65         if [ $[$holeStart % $fsblocksize] -gt 0 ] ; then
66                 holeStart=$[($holeStart/$fsblocksize +1) * $fsblocksize]
67         fi
68         #xfs_bmap prints holes in the following format
69         #                1: [8..15]: hole
70         bmap="\[$[$holeStart/512]..$[($holeEnd/512) -1]\]";
71         echo $bmap >> $seqres.full
72         if [ $holeEnd == $holeStart ] ; then
73                 continue #there is no hole
74         fi
75         if ! echo $xfs_bmap|grep -q $bmap; then
76                 echo Offset $holeStart to $holeEnd  basic blocks failed;
77                 status=1;
78         fi
79 done
80 if [ $status == 0 ] ; then
81         echo Test $seq Passed.
82 fi
83
84 exit