92a8ed34041e6d0a8045341b0535ba439cf199f6
[xfstests-dev.git] / tests / xfs / 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
24 seqfull=$0
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 seqres=$RESULT_DIR/$seq
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30 rm -f $seqres.full
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35
36 _cleanup()
37 {
38     cd /
39     rm -f $tmp.*
40     umount $SCRATCH_DEV 2>/dev/null
41 }
42 trap "_cleanup; exit \$status" 0 1 2 3 15
43
44 # get standard environment, filters and checks
45 . ./common/rc
46 . ./common/filter
47
48 bitsperlong=`src/feature -w`
49 # link correct .out file
50 rm -f $seqfull.out
51 if [ "$bitsperlong" -eq 32 ]; then
52         ln -s $seq.out.32 $seqfull.out
53 else
54         ln -s $seq.out.64 $seqfull.out
55 fi
56
57 _filter_io()
58 {
59     sed -e "s/$dbsize/1FSB/g" -e '/.* ops; /d'
60 }
61
62 _filter_off()
63 {
64     sed -e "s/$1/<OFFSET>/g" | _filter_io
65 }
66
67 _filter_pwrite()
68 {
69         sed -e "s/pwrite64: Invalid argument/pwrite64: File too large/g"
70 }
71
72 _filter_pread()
73 {
74         sed -e "s/pread64: Invalid argument/read 0\/$bytes bytes at offset <OFFSET>/g" | _filter_io
75 }
76
77 write_block()
78 {
79     location=$1
80     words=$2
81     offset=$3
82     bytes=$4
83     direct=$5
84
85     [ `$direct` ] && flags=-d
86
87     echo "Writing $bytes bytes, offset is $words (direct=$direct)" | _filter_io
88     echo "Writing $bytes bytes at $location $words (direct=$direct)" >>$seqres.full
89     $XFS_IO_PROG -c "pwrite $offset 512" $flags $SCRATCH_MNT/$seq \
90         2>&1 | _filter_off $offset | tee -a $seqres.full | _filter_pwrite
91     xfs_bmap -v $SCRATCH_MNT/$seq >>$seqres.full
92
93     echo "Reading $bytes bytes (direct=$direct)" | _filter_io
94     echo "Reading $bytes bytes at $location (direct=$direct)" >>$seqres.full
95     $XFS_IO_PROG -c "pread $offset $bytes" $flags $SCRATCH_MNT/$seq \
96         2>&1 | _filter_off $offset | tee -a $seqres.full | _filter_pread
97
98     $XFS_IO_PROG -c "pread -v $offset $bytes" $flags $SCRATCH_MNT/$seq >>$seqres.full 2>&1
99
100     echo | tee -a $seqres.full
101 }
102
103 # real QA test starts here
104 _supported_fs xfs
105 _supported_os IRIX Linux
106
107 [ -n "$XFS_IO_PROG" ] || _notrun "xfs_io executable not found"
108
109 _require_scratch
110 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
111 . $tmp.mkfs
112 echo
113 _scratch_mount
114
115 # Okay... filesize limit depends on blocksize, bits per long and
116 # also if large block device patch is enabled (can't dynamically
117 # check that, so use env var USE_LBD_PATCH to override default).
118 #
119 # Note:
120 # We check from 1Tb below our guessed limit to 1Tb above it, and
121 # see what happens for each 1Tb increment along the way (first
122 # half should succeed, second half should fail to create a file).
123 # So, number calculated here is not the actual limit, its a ways
124 # above that, hopefully.
125
126 if [ "$bitsperlong" -eq 32 ]; then
127     upperbound=`expr $dbsize / 512`
128     # which is 8(TB) for 4K, 4(TB) for 2k, ... etc.
129     [ "$USE_LBD_PATCH" = yes ] && upperbound=16
130     # limited by page cache index when LBD patch onboard.
131 else
132     upperbound=`echo 8 \* 1024 \* 1024 | bc`
133     # 8 exabytes (working in TBs below)
134 fi
135
136 # Step from (upperbound-1)(Tb) through (upperbound+1(Tb), &
137 # seeks/writes/reads on each boundary (using holey files) -
138 # 1byte back from the boundary, and 1FSB back from the same
139 # boundary (and stash xfs_bmap output), before moving onto
140 # each new test point.
141
142 $XFS_IO_PROG -c "truncate 0" -f $SCRATCH_MNT/$seq
143
144 oneTB=`echo 1024 \* 1024 \* 1024 \* 1024 | bc`
145 count=`expr $upperbound - 1`
146 upperbound=`expr $upperbound + 1`
147
148 while [ $count -le $upperbound ]
149 do
150     # buffered IO
151     offset=`echo $oneTB \* $count | bc`
152     write_block $count "+0" $offset 512 false
153     offset=`echo $oneTB \* $count \- 1 | bc`
154     write_block $count "minus 1 byte" $offset 512 false
155     offset=`echo $oneTB \* $count \- $dbsize | bc`
156     write_block $count "minus 1FSB" $offset 512 false
157     write_block $count "minus 1FSB" $offset 1 false
158
159     # direct IO
160     offset=`echo $oneTB \* $count | bc`
161     write_block $count "+0" $offset $dbsize true
162     offset=`echo $oneTB \* $count \- 1 | bc`
163     write_block $count "minus 1FSB" $offset $dbsize true
164
165     echo === Iterating, `expr $upperbound - $count` remains
166     echo
167     echo
168     let count=$count+1
169 done
170
171 # success, all done
172 status=0
173 exit