xfstests: kill useless test owner fields
[xfstests-dev.git] / 194
1 #! /bin/bash
2 # FS QA Test No. 194
3 #
4 # Test mapping around/over holes for sub-page blocks
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2008 Eric Sandeen.  All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #-----------------------------------------------------------------------
22 #
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 tmp=/tmp/$$
29 status=1        # failure is the default!
30 trap "_cleanup; exit \$status" 0 1 2 3 15
31
32 _cleanup()
33 {
34     cd /
35     rm -f $tmp.*
36 }
37
38 # get standard environment, filters and checks
39 . ./common.rc
40 . ./common.filter
41
42 # only xfs supported due to use of xfs_bmap
43 _supported_fs xfs
44 _supported_os IRIX Linux
45
46 # real QA test starts here
47 rm -f $seq.full
48
49 # For this test we use block size = 1/8 page size
50 pgsize=`$here/src/feature -s`
51 blksize=`expr $pgsize / 8`
52
53 # Filter out file mountpoint and physical location info
54 # Input:
55 #  EXT: FILE-OFFSET      BLOCK-RANGE      AG AG-OFFSET        TOTAL
56 #  0: [0..63]:         160..223          0 (160..223)          64
57 #  1: [64..127]:       hole                                    64
58 # Output:
59 #  SCRATCH_MNT/testfile4:       TYPE
60 #  EXT: TYPE    TOTAL
61 #  0:   blocks  1
62 #  1:   hole    1
63
64 _filter_bmap()
65 {
66     tee -a $seq.full | \
67     sed "s#$SCRATCH_MNT#SCRATCH_MNT#g" | \
68     awk \
69         '$3 ~ /hole/     { print $1 "\t" $3 "\t" ($4 * 512) / blksize; next }
70          $1 ~ /^[0-9]/   { print $1 "\tblocks\t" ($6 * 512) / blksize; next }
71          $1 ~ /^SCRATCH/ { print $1; next }
72                          { print $1 "\tTYPE\t" $6 }' blksize=$blksize
73 }
74
75 # Filter out offsets, which vary by blocksize
76 _filter_od()
77 {
78     tee -a $seq.full | \
79     sed -e "s/^[0-9A-Fa-f ]\{7,8\}//"
80 }
81
82 _require_scratch
83 unset MKFS_OPTIONS
84 unset XFS_MKFS_OPTIONS
85 _scratch_mkfs_xfs -b size=$blksize >/dev/null 2>&1
86 _scratch_mount
87
88 # 512b block / 4k page example:
89 #
90 #1) Write 1k of data (buffered):
91 #
92 # |1111|1111|
93 #
94 # 2) ftruncate back to 256 bytes:
95 #
96 # |1100|
97 #
98 # 3) ftruncate out to 4k: ("H" means hole (expected))
99 #
100 # |1100|HHHH|HHHH|HHHH|HHHH|HHHH|HHHH|HHHH|
101 #
102 # So we should have 1 block of data/0, 7 blocks of holes.
103 #
104 # 4) check what's there with a direct IO read
105 #
106 # In fact what I get is 1 block of data/0, 1 block of 0's, and 7 blocks of
107 # garbage:
108 #
109 # |1100|0000|GGGG|GGGG|GGGG|GGGG|GGGG|GGGG|
110 #
111 # The garbage is in fact stale data from the disk.
112 #
113 # Check that we don't get stale data and that the hole is a hole:
114
115 echo "== Test 1 =="
116 # Write, truncate in, truncate out
117 xfs_io \
118 -c "pwrite -S 0x11 -b `expr $pgsize / 2`  0 `expr $pgsize / 2`" \
119 -c "truncate `expr $blksize / 2`" \
120 -c "truncate $pgsize" \
121 -t -f $SCRATCH_MNT/testfile1 >> $seq.full
122
123 # directio read of entire file
124 xfs_io \
125 -c "pread 0 $pgsize" \
126 -d $SCRATCH_MNT/testfile1 >> $seq.full
127
128 xfs_bmap -v $SCRATCH_MNT/testfile1 | _filter_bmap
129 od -x $SCRATCH_MNT/testfile1 | _filter_od
130
131 # Similar but write another block to create block/hole/block/hole
132
133 echo "== Test 2 =="
134 # Write, truncate in, truncate out, write to middle
135 xfs_io \
136 -c "pwrite -S 0x11 -b `expr $pgsize / 2`  0 `expr $pgsize / 2`" \
137 -c "truncate `expr $blksize / 2`" \
138 -c "truncate $pgsize" \
139 -c "pwrite -S 0x22 -b $blksize `expr $blksize \* 4` $blksize" \
140 -t -f $SCRATCH_MNT/testfile2 >> $seq.full
141
142 # directio read of entire file
143 xfs_io \
144 -c "pread 0 $pgsize" \
145 -d $SCRATCH_MNT/testfile2 >> $seq.full
146
147 xfs_bmap -v $SCRATCH_MNT/testfile2 | _filter_bmap
148 od -x $SCRATCH_MNT/testfile2 | _filter_od
149
150 # 512 byte block / 4k page example:
151
152 # direct write 1 page (8 blocks) of "0x11" to 0x1000
153 # map read 1 block, 512 (0x200) at 0
154 # truncate to half a block, 256 (0x100)
155 # truncate to block+1, 513 (0x201)
156 # direct write "0x22" for 1 block at offset 2048 (0x800)
157
158 # |1111|1111|1111|1111|1111|1111|1111|1111|     Write 1's
159 # |MRMR|1111|1111|1111|1111|1111|1111|1111|     mapread
160 # |11--|                                        truncate down
161 # |1100|0---|                                   truncate up, block+1
162 # |    |    |HHHH|HHHH|2222|                    Write 2's (extending)
163
164 #           |uptodate?|
165 # |1100|0000|1111|1111|2222|----|----|----|     <- potential badness
166
167 # We're looking for this badness due to mapping over a hole:
168 # Exposes stale data from 0x400 (1024) through 0x800 (2048)
169
170 # 00000000  11 11 11 11 11 11 11 11  11 11 11 11 11 11 11 11  |................|
171 # *
172 # 00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
173 # *
174 # 00000400  11 11 11 11 11 11 11 11  11 11 11 11 11 11 11 11  |................| <- BAD
175 # *
176 # 00000800  22 22 22 22 22 22 22 22  22 22 22 22 22 22 22 22  |""""""""""""""""|
177 # *
178 # 00000a00
179
180 # We *should* get:
181 # |1100|HHHH|HHHH|HHHH|2222|----|----|----|
182
183 echo "== Test 3 =="
184 xfs_io \
185 -c "pwrite -S 0x11 -b $pgsize 0 $pgsize" \
186 -c "mmap -r 0 $blksize" -c "mread 0 $blksize" -c "munmap" \
187 -c "truncate `expr $blksize / 2`" \
188 -c "truncate `expr $blksize + 1`" \
189 -c "pwrite -S 0x22 -b $blksize `expr $pgsize / 2` $blksize" \
190 -t -d -f $SCRATCH_MNT/testfile3 >> $seq.full
191
192 xfs_bmap -v $SCRATCH_MNT/testfile3 | _filter_bmap
193 od -x $SCRATCH_MNT/testfile3 | _filter_od
194
195 # Now try the same thing but write a sector in the middle of that hole
196 # If things go badly stale data will be exposed either side.
197 # This is most interesting for block size > 512 (page size > 4096)
198
199 # We *should* get:
200 # |1100|HHHH|33HH|HHHH|2222|----|----|----|
201
202 echo "== Test 4 =="
203 xfs_io \
204 -c "pwrite -S 0x11 -b $pgsize 0 $pgsize" \
205 -c "mmap -r 0 $blksize" -c "mread 0 $blksize" -c "munmap" \
206 -c "truncate `expr $blksize / 2`" \
207 -c "truncate `expr $blksize + 1`" \
208 -c "pwrite -S 0x22 -b $blksize `expr $pgsize / 2` $blksize" \
209 -c "pwrite -S 0x33 -b 512 `expr $blksize \* 2` 512" \
210 -t -d -f $SCRATCH_MNT/testfile4 >> $seq.full
211
212 xfs_bmap -v $SCRATCH_MNT/testfile4 | _filter_bmap
213 od -x $SCRATCH_MNT/testfile4 | _filter_od
214
215 # success, all done
216 status=0
217 exit