235: do smaller test IO
[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 _filter_io()
47 {
48     sed -e "s/$dbsize/1FSB/g" -e '/.* ops; /d'
49 }
50
51 _filter_off()
52 {
53     sed -e "s/$1/<OFFSET>/g" | _filter_io
54 }
55
56 write_block()
57 {
58     location=$1
59     words=$2
60     offset=$3
61     bytes=$4
62     direct=$5
63
64     [ `$direct` ] && flags=-d
65
66     echo "Writing $bytes bytes, offset is $words (direct=$direct)" | _filter_io
67     echo "Writing $bytes bytes at $location $words (direct=$direct)" >>$seq.full
68     $XFS_IO_PROG -c "pwrite $offset 512" $flags $SCRATCH_MNT/$seq \
69         2>&1 | _filter_off $offset | _filter_xfs_io | tee -a $seq.full
70     xfs_bmap -v $SCRATCH_MNT/$seq >>$seq.full
71
72     echo "Reading $bytes bytes (direct=$direct)" | _filter_io
73     echo "Reading $bytes bytes at $location (direct=$direct)" >>$seq.full
74     $XFS_IO_PROG -c "pread $offset $bytes" $flags $SCRATCH_MNT/$seq \
75         2>&1 | _filter_off $offset | _filter_xfs_io | tee -a $seq.full
76
77     $XFS_IO_PROG -c "pread -v $offset $bytes" $flags $SCRATCH_MNT/$seq >>$seq.full
78
79     echo | tee -a $seq.full
80 }
81
82 # real QA test starts here
83 _supported_fs xfs
84 _supported_os IRIX Linux
85
86 [ -n "$XFS_IO_PROG" ] || _notrun "xfs_io executable not found"
87
88 _require_scratch
89 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
90 . $tmp.mkfs
91 echo
92 _scratch_mount
93
94 # Okay... filesize limit depends on blocksize, bits per long and
95 # also if large block device patch is enabled (can't dynamically
96 # check that, so use env var USE_LBD_PATCH to override default).
97
98 # Note:
99 # We check from 1Tb below our guessed limit to 1Tb above it, and
100 # see what happens for each 1Tb increment along the way (first
101 # half should succeed, second half should fail to create a file).
102 # So, number calculated here is not the actual limit, its a ways
103 # above that, hopefully.
104
105 bitsperlong=`src/feature -w`
106 if [ "$bitsperlong" -eq 32 ]; then
107     upperbound=`expr $dbsize / 512`
108     # which is 8(TB) for 4K, 4(TB) for 2k, ... etc.
109     [ "$USE_LBD_PATCH" = yes ] && upperbound=16
110     # limited by page cache index when LBD patch onboard.
111 else
112     upperbound=`echo 8 \* 1024 \* 1024 | bc` 
113     # 8 exabytes (working in TBs below)
114 fi
115
116 # Step from (upperbound-1)(Tb) through (upperbound+1(Tb), &
117 # seeks/writes/reads on each boundary (using holey files) -
118 # 1byte back from the boundary, and 1FSB back from the same
119 # boundary (and stash xfs_bmap output), before moving onto
120 # each new test point.
121
122 $XFS_IO_PROG -c "truncate 0" -f $SCRATCH_MNT/$seq
123
124 oneTB=`echo 1024 \* 1024 \* 1024 \* 1024 | bc`
125 count=`expr $upperbound - 1`
126 upperbound=`expr $upperbound + 1`
127
128 while [ $count -le $upperbound ]
129 do
130     # buffered IO
131     offset=`echo $oneTB \* $count | bc`
132     write_block $count "+0" $offset 512 false
133     offset=`echo $oneTB \* $count \- 1 | bc`
134     write_block $count "minus 1 byte" $offset 512 false
135     offset=`echo $oneTB \* $count \- $dbsize | bc`
136     write_block $count "minus 1FSB" $offset 512 false
137     write_block $count "minus 1FSB" $offset 1 false
138
139     # direct IO
140     offset=`echo $oneTB \* $count | bc`
141     write_block $count "+0" $offset $dbsize true
142     offset=`echo $oneTB \* $count \- 1 | bc`
143     write_block $count "minus 1FSB" $offset $dbsize true
144
145     echo === Iterating, `expr $upperbound - $count` remains
146     echo
147     echo
148     let count=$count+1
149 done
150
151 # success, all done
152 status=0
153 exit