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