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