xfstests: optionally run all tests under quota
[xfstests-dev.git] / 071
1 #! /bin/bash
2 # FS QA Test No. 071
3 #
4 # Exercise IO at large file offsets.
5 #-----------------------------------------------------------------------
6 # Copyright (c) 2000-2003 Silicon Graphics, Inc.  All Rights Reserved.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it would be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write the Free Software Foundation,
19 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 #
21 #-----------------------------------------------------------------------
22 #
23 # creator
24 owner=nathans@sgi.com
25
26 seq=`basename $0`
27 echo "QA output created by $seq"
28 rm -f $seq.full
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33
34 _cleanup()
35 {
36     cd /
37     rm -f $tmp.*
38     umount $SCRATCH_DEV 2>/dev/null
39 }
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 # get standard environment, filters and checks
43 . ./common.rc
44 . ./common.filter
45
46 bitsperlong=`src/feature -w`
47 # link correct .out file
48 rm -f $seq.out
49 if [ "$bitsperlong" -eq 32 ]; then
50         ln -s $seq.out.32 $seq.out
51 else
52         ln -s $seq.out.64 $seq.out
53 fi
54
55 _filter_io()
56 {
57     sed -e "s/$dbsize/1FSB/g" -e '/.* ops; /d'
58 }
59
60 _filter_off()
61 {
62     sed -e "s/$1/<OFFSET>/g" | _filter_io
63 }
64
65 _filter_pwrite()
66 {
67         sed -e "s/pwrite64: Invalid argument/pwrite64: File too large/g"
68 }
69
70 _filter_pread()
71 {
72         sed -e "s/pread64: Invalid argument/read 0\/$bytes bytes at offset <OFFSET>/g" | _filter_io
73 }
74
75 write_block()
76 {
77     location=$1
78     words=$2
79     offset=$3
80     bytes=$4
81     direct=$5
82
83     [ `$direct` ] && flags=-d
84
85     echo "Writing $bytes bytes, offset is $words (direct=$direct)" | _filter_io
86     echo "Writing $bytes bytes at $location $words (direct=$direct)" >>$seq.full
87     $XFS_IO_PROG -c "pwrite $offset 512" $flags $SCRATCH_MNT/$seq \
88         2>&1 | _filter_off $offset | tee -a $seq.full | _filter_pwrite
89     xfs_bmap -v $SCRATCH_MNT/$seq >>$seq.full
90
91     echo "Reading $bytes bytes (direct=$direct)" | _filter_io
92     echo "Reading $bytes bytes at $location (direct=$direct)" >>$seq.full
93     $XFS_IO_PROG -c "pread $offset $bytes" $flags $SCRATCH_MNT/$seq \
94         2>&1 | _filter_off $offset | tee -a $seq.full | _filter_pread
95
96     $XFS_IO_PROG -c "pread -v $offset $bytes" $flags $SCRATCH_MNT/$seq >>$seq.full 2>&1
97
98     echo | tee -a $seq.full
99 }
100
101 # real QA test starts here
102 _supported_fs xfs
103 _supported_os IRIX Linux
104
105 [ -n "$XFS_IO_PROG" ] || _notrun "xfs_io executable not found"
106
107 _require_scratch
108 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
109 . $tmp.mkfs
110 echo
111 _scratch_mount
112
113 # Okay... filesize limit depends on blocksize, bits per long and
114 # also if large block device patch is enabled (can't dynamically
115 # check that, so use env var USE_LBD_PATCH to override default).
116 #
117 # Note:
118 # We check from 1Tb below our guessed limit to 1Tb above it, and
119 # see what happens for each 1Tb increment along the way (first
120 # half should succeed, second half should fail to create a file).
121 # So, number calculated here is not the actual limit, its a ways
122 # above that, hopefully.
123
124 if [ "$bitsperlong" -eq 32 ]; then
125     upperbound=`expr $dbsize / 512`
126     # which is 8(TB) for 4K, 4(TB) for 2k, ... etc.
127     [ "$USE_LBD_PATCH" = yes ] && upperbound=16
128     # limited by page cache index when LBD patch onboard.
129 else
130     upperbound=`echo 8 \* 1024 \* 1024 | bc`
131     # 8 exabytes (working in TBs below)
132 fi
133
134 # Step from (upperbound-1)(Tb) through (upperbound+1(Tb), &
135 # seeks/writes/reads on each boundary (using holey files) -
136 # 1byte back from the boundary, and 1FSB back from the same
137 # boundary (and stash xfs_bmap output), before moving onto
138 # each new test point.
139
140 $XFS_IO_PROG -c "truncate 0" -f $SCRATCH_MNT/$seq
141
142 oneTB=`echo 1024 \* 1024 \* 1024 \* 1024 | bc`
143 count=`expr $upperbound - 1`
144 upperbound=`expr $upperbound + 1`
145
146 while [ $count -le $upperbound ]
147 do
148     # buffered IO
149     offset=`echo $oneTB \* $count | bc`
150     write_block $count "+0" $offset 512 false
151     offset=`echo $oneTB \* $count \- 1 | bc`
152     write_block $count "minus 1 byte" $offset 512 false
153     offset=`echo $oneTB \* $count \- $dbsize | bc`
154     write_block $count "minus 1FSB" $offset 512 false
155     write_block $count "minus 1FSB" $offset 1 false
156
157     # direct IO
158     offset=`echo $oneTB \* $count | bc`
159     write_block $count "+0" $offset $dbsize true
160     offset=`echo $oneTB \* $count \- 1 | bc`
161     write_block $count "minus 1FSB" $offset $dbsize true
162
163     echo === Iterating, `expr $upperbound - $count` remains
164     echo
165     echo
166     let count=$count+1
167 done
168
169 # success, all done
170 status=0
171 exit