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