1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2008 Eric Sandeen. All Rights Reserved.
#
# FS QA Test No. 194
#
# Test mapping around/over holes for sub-page blocks
#
. ./common/preamble
_begin_fstest rw auto
# Override the default cleanup function.
_cleanup()
{
cd /
# Unmount the V4 filesystem we forcibly created to run this test so that
# the post-test wrapup checks won't try to remount the filesystem with
# different MOUNT_OPTIONS (specifically, the ones that get screened out by
# _force_xfsv4_mount_options) and fail.
_scratch_unmount
rm -f $tmp.*
}
# Import common functions.
. ./common/filter
# only xfs supported due to use of xfs_bmap
_supported_fs xfs
# real QA test starts here
_require_scratch
#
# This currently forces nocrc because only that can support 512 byte block size
# and thus block size = 1/8 page size on 4k page size systems.
# In theory we could run it on systems with larger page size with CRCs, or hope
# that large folios would trigger the same issue.
# But for now that is left as an exercise for the reader.
#
_require_xfs_nocrc
_scratch_mkfs_xfs >/dev/null 2>&1
# For this test we use block size = 1/8 page size
pgsize=`$here/src/feature -s`
blksize=`expr $pgsize / 8`
secsize=`_min_dio_alignment $SCRATCH_DEV`
if [ $secsize -gt $blksize ];then
_notrun "sector size($secsize) too large for platform page size($pgsize)"
fi
# Filter out file mountpoint and physical location info
# Input:
# EXT: FILE-OFFSET BLOCK-RANGE AG AG-OFFSET TOTAL
# 0: [0..63]: 160..223 0 (160..223) 64
# 1: [64..127]: hole 64
# Output:
# SCRATCH_MNT/testfile4: TYPE
# EXT: TYPE TOTAL
# 0: blocks 1
# 1: hole 1
_filter_bmap()
{
tee -a $seqres.full | \
sed "s#$SCRATCH_MNT#SCRATCH_MNT#g" | \
awk \
'$3 ~ /hole/ { print $1 "\t" $3 "\t" ($4 * 512) / blksize; next }
$1 ~ /^[0-9]/ { print $1 "\tblocks\t" ($6 * 512) / blksize; next }
$1 ~ /^SCRATCH/ { print $1; next }
{ print $1 "\tTYPE\t" $6 }' blksize=$blksize
}
# Filter out offsets, which vary by blocksize
_filter_od()
{
tee -a $seqres.full | \
sed -e "s/^[0-9A-Fa-f ]\{7,8\}//"
}
unset MKFS_OPTIONS
unset XFS_MKFS_OPTIONS
# we need 512 byte block size, so crc's are turned off
_scratch_mkfs_xfs -m crc=0 -b size=$blksize >/dev/null 2>&1
_scratch_mount
test "$(_get_block_size $SCRATCH_MNT)" = $blksize || \
_notrun "Could not get $blksize-byte blocks"
# 512b block / 4k page example:
#
#1) Write 1k of data (buffered):
#
# |1111|1111|
#
# 2) ftruncate back to 256 bytes:
#
# |1100|
#
# 3) ftruncate out to 4k: ("H" means hole (expected))
#
# |1100|HHHH|HHHH|HHHH|HHHH|HHHH|HHHH|HHHH|
#
# So we should have 1 block of data/0, 7 blocks of holes.
#
# 4) check what's there with a direct IO read
#
# In fact what I get is 1 block of data/0, 1 block of 0's, and 7 blocks of
# garbage:
#
# |1100|0000|GGGG|GGGG|GGGG|GGGG|GGGG|GGGG|
#
# The garbage is in fact stale data from the disk.
#
# Check that we don't get stale data and that the hole is a hole:
echo "== Test 1 =="
# Write, truncate in, truncate out
xfs_io \
-c "pwrite -S 0x11 -b `expr $pgsize / 2` 0 `expr $pgsize / 2`" \
-c "truncate `expr $blksize / 2`" \
-c "truncate $pgsize" \
-t -f $SCRATCH_MNT/testfile1 >> $seqres.full
# directio read of entire file
xfs_io \
-c "pread 0 $pgsize" \
-d $SCRATCH_MNT/testfile1 >> $seqres.full
xfs_bmap -v $SCRATCH_MNT/testfile1 | _filter_bmap
od -x $SCRATCH_MNT/testfile1 | _filter_od
# Similar but write another block to create block/hole/block/hole
echo "== Test 2 =="
# Write, truncate in, truncate out, write to middle
xfs_io \
-c "pwrite -S 0x11 -b `expr $pgsize / 2` 0 `expr $pgsize / 2`" \
-c "truncate `expr $blksize / 2`" \
-c "truncate $pgsize" \
-c "pwrite -S 0x22 -b $blksize `expr $blksize \* 4` $blksize" \
-t -f $SCRATCH_MNT/testfile2 >> $seqres.full
# directio read of entire file
xfs_io \
-c "pread 0 $pgsize" \
-d $SCRATCH_MNT/testfile2 >> $seqres.full
xfs_bmap -v $SCRATCH_MNT/testfile2 | _filter_bmap
od -x $SCRATCH_MNT/testfile2 | _filter_od
# 512 byte block / 4k page example:
# direct write 1 page (8 blocks) of "0x11" to 0x1000
# map read 1 block, 512 (0x200) at 0
# truncate to half a block, 256 (0x100)
# truncate to block+1, 513 (0x201)
# direct write "0x22" for 1 block at offset 2048 (0x800)
# |1111|1111|1111|1111|1111|1111|1111|1111| Write 1's
# |MRMR|1111|1111|1111|1111|1111|1111|1111| mapread
# |11--| truncate down
# |1100|0---| truncate up, block+1
# | | |HHHH|HHHH|2222| Write 2's (extending)
# |uptodate?|
# |1100|0000|1111|1111|2222|----|----|----| <- potential badness
# We're looking for this badness due to mapping over a hole:
# Exposes stale data from 0x400 (1024) through 0x800 (2048)
# 00000000 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 |................|
# *
# 00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
# *
# 00000400 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 |................| <- BAD
# *
# 00000800 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22 |""""""""""""""""|
# *
# 00000a00
# We *should* get:
# |1100|HHHH|HHHH|HHHH|2222|----|----|----|
echo "== Test 3 =="
xfs_io \
-c "pwrite -S 0x11 -b $pgsize 0 $pgsize" \
-c "mmap -r 0 $blksize" -c "mread 0 $blksize" -c "munmap" \
-c "truncate `expr $blksize / 2`" \
-c "truncate `expr $blksize + 1`" \
-c "pwrite -S 0x22 -b $blksize `expr $pgsize / 2` $blksize" \
-t -d -f $SCRATCH_MNT/testfile3 >> $seqres.full
xfs_bmap -v $SCRATCH_MNT/testfile3 | _filter_bmap
od -x $SCRATCH_MNT/testfile3 | _filter_od
# Now try the same thing but write a sector in the middle of that hole
# If things go badly stale data will be exposed either side.
# This is most interesting for block size > 512 (page size > 4096)
# We *should* get:
# |1100|HHHH|33HH|HHHH|2222|----|----|----|
echo "== Test 4 =="
xfs_io \
-c "pwrite -S 0x11 -b $pgsize 0 $pgsize" \
-c "mmap -r 0 $blksize" -c "mread 0 $blksize" -c "munmap" \
-c "truncate `expr $blksize / 2`" \
-c "truncate `expr $blksize + 1`" \
-c "pwrite -S 0x22 -b $blksize `expr $pgsize / 2` $blksize" \
-c "pwrite -S 0x33 -b $secsize `expr $blksize \* 2` $secsize" \
-t -d -f $SCRATCH_MNT/testfile4 >> $seqres.full
xfs_bmap -v $SCRATCH_MNT/testfile4 | _filter_bmap
od -x $SCRATCH_MNT/testfile4 | _filter_od
# success, all done
status=0
exit
|