xfs/007: fix regressions on V4 filesystems
[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
14 . ./common/preamble
15 _begin_fstest rw auto quick
16
17 status=0    # success is the default!
18
19 # Import common functions.
20 . ./common/filter
21
22 # real QA test starts here
23 _supported_fs xfs
24
25 _require_scratch
26 _scratch_mkfs_xfs >/dev/null 2>&1
27 _scratch_mount
28
29 fsblocksize=$(_get_file_block_size $SCRATCH_MNT)
30
31 #This is the list of holes to punch in the file limited to $filesize
32 #NOTE holes cannot overlap or this script will fail.
33 holes="$fsblocksize:$fsblocksize \
34 $(($fsblocksize * 74)):$fsblocksize \
35 $(($fsblocksize * 256)):$(($fsblocksize / 8)) \
36 $(echo scale=0\;$fsblocksize \* 256 \+ $fsblocksize \* 3 \/ 4 | bc):$(($fsblocksize * 2)) \
37 $(echo scale=0\;$fsblocksize \* 260 \+ $fsblocksize \* 1 \/ 4 | bc):$(($fsblocksize * 2)) \
38 $(($fsblocksize * 265)):$(echo scale=0\;$fsblocksize \+ $fsblocksize \* 3 \/ 4 | bc)"
39
40 #filesize
41 filesize=$(($fsblocksize * 2560))
42 #Name of file to perform the test on
43 filename=test-190
44
45 $XFS_IO_PROG -f -c "pwrite 0 $(($fsblocksize * 2560))" $SCRATCH_MNT/$filename >> $seqres.full 2>&1
46
47 # run DMAPI test using verbose output
48 echo Punching holes in file
49 echo Punching holes in file >> $seqres.full
50 for i in $holes ; do
51         echo $XFS_IO_PROG -c "unresvsp `echo $i |$SED_PROG 's/:/ /g'`" $SCRATCH_MNT/$filename >> $seqres.full
52         $XFS_IO_PROG -c "unresvsp `echo $i |$SED_PROG 's/:/ /g'`" $SCRATCH_MNT/$filename ;
53 done
54
55 echo Verifying holes are in the correct spots:
56
57 xfs_bmap=`xfs_bmap $SCRATCH_MNT/$filename`
58 xfs_bmap $SCRATCH_MNT/$filename >> $seqres.full
59 for i in $holes ; do
60         holeStart=$[`echo $i|$SED_PROG 's/:/ /g'|awk '{print $1}'`];
61         holeEnd=$[`echo $i|$SED_PROG 's/:/ /g'|awk '{print $2}'`];
62
63         #Round hole size down to a multiple of $fsblocksize
64         holeEnd=$[(($holeStart+$holeEnd)/$fsblocksize)*$fsblocksize]
65
66         #Round hole start up to a multiple of $fsblocksize
67         if [ $[$holeStart % $fsblocksize] -gt 0 ] ; then
68                 holeStart=$[($holeStart/$fsblocksize +1) * $fsblocksize]
69         fi
70         #xfs_bmap prints holes in the following format
71         #                1: [8..15]: hole
72         bmap="\[$[$holeStart/512]..$[($holeEnd/512) -1]\]";
73         echo $bmap >> $seqres.full
74         if [ $holeEnd == $holeStart ] ; then
75                 continue #there is no hole
76         fi
77         if ! echo $xfs_bmap|grep -q $bmap; then
78                 echo Offset $holeStart to $holeEnd  basic blocks failed;
79                 status=1;
80         fi
81 done
82 if [ $status == 0 ] ; then
83         echo Test $seq Passed.
84 fi
85
86 exit