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