xfstests: don't assume that falloc_punch implies falloc in test 255
[xfstests-dev.git] / 214
1 #! /bin/bash
2 # FS QA Test No. 214
3 #
4 # Basic unwritten extent sanity checks
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2009 Red Hat, Inc. 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 # creator
25 owner=sandeen@sandeen.net
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 _cleanup()
31 {
32         rm -f $TEST_DIR/ouch*
33         cd /
34         rm -f $tmp.*
35 }
36
37 here=`pwd`
38 tmp=$TEST_DIR/$$
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15
41
42 # get standard environment, filters and checks
43 . ./common.rc
44 . ./common.filter
45
46 # real QA test starts here
47 # generic, but xfs_io's fallocate must work
48 _supported_fs generic
49 # only Linux supports fallocate
50 _supported_os Linux
51
52 [ -n "$XFS_IO_PROG" ] || _notrun "xfs_io executable not found"
53
54 rm -f $seq.full
55 rm -f $TEST_DIR/ouch*
56
57 _require_xfs_io_falloc
58
59 # Ok, off we go.
60
61 # We don't remove files after they are written to check
62 # for subsequent fs corruption at the end
63 rm -f $TEST_DIR/test214-*
64
65 # Super-trivial; preallocate a region and read it; get 0s.
66 echo "=== falloc & read  ==="
67 $XFS_IO_PROG -F -f              \
68         -c 'falloc 0 4096'      \
69         -c 'pread -v 0 4096'    \
70         $TEST_DIR/test214-1 | _filter_xfs_io_unique
71
72 # Preallocate a chunk, write 1 byte, read it all back.
73 # Should get no stale data.  Early ext4 bug.
74
75 echo "=== falloc, write beginning, read ==="
76 $XFS_IO_PROG -F -f              \
77         -c 'falloc 0 512'       \
78         -c 'pwrite 0 1'         \
79         -c 'pread -v 0 512'     \
80         $TEST_DIR/test214-2 | _filter_xfs_io_unique
81
82 # Same but write in the middle of the region
83 echo "=== falloc, write middle, read ==="
84 $XFS_IO_PROG -F -f              \
85         -c 'falloc 0 512'       \
86         -c 'pwrite 256 1'       \
87         -c 'pread -v 0 512'     \
88         $TEST_DIR/test214-3 | _filter_xfs_io_unique
89
90 # Same but write the end of the region
91 echo "=== falloc, write end, read ==="
92 $XFS_IO_PROG -F -f              \
93         -c 'falloc 0 512'       \
94         -c 'pwrite 511 1'       \
95         -c 'pread -v 0 512'     \
96         $TEST_DIR/test214-4 | _filter_xfs_io_unique
97
98 # Reported by IBM on ext4.
99 #
100 # Fixed by commit a41f20716975910d9beb90b7efc61107901492b8
101 #
102 # The file was previously preallocated, and then initialized the middle of
103 # the preallocation area using Direct IO write, then overwrite part of
104 # initialized area. Later after truncate the file (to the middle of the
105 # initialized data), the initialized data *before* the new file size was
106 # gone after remount the filesystem.
107
108 echo "=== falloc, write, sync, truncate, read ==="
109 # Allocate, write, sync, truncate (buffered)
110 $XFS_IO_PROG -F -f                              \
111         -c 'falloc         0x0     0x65C00'     \
112         -c 'pwrite -S 0xAA 0x12000 0x10000'     \
113         -c 'fsync'                              \
114         -c 'truncate 0x16000'                   \
115         $TEST_DIR/test214-5 | _filter_xfs_io_unique
116
117 # now do a direct read and see what's on-disk
118 $XFS_IO_PROG -F -f -d                           \
119         -c 'pread -v 0 0x16000'                 \
120         $TEST_DIR/test214-5 | _filter_xfs_io_unique
121
122 # Reported by Ted Ts'o on linux-ext4, 12/31/2009
123 # double-allocation on ext4 when fallocating over delalloc blocks
124 # Regression due to d21cd8f163ac44b15c465aab7306db931c606908
125
126 echo "=== delalloc write 16k; fallocate same range ==="
127 # delalloc write 16k, fallocate same range.
128 # Should get caught on fsck when we're done.
129
130 $XFS_IO_PROG -F -f                              \
131         -c "pwrite 0 16k"                       \
132         -c "falloc 0 16k"                       \
133         -c "fsync"                              \
134         $TEST_DIR/test214-6 | _filter_xfs_io_unique
135
136 # Another ext4 failure
137
138 echo "=== ext4 testcase 2 ==="
139
140 $XFS_IO_PROG -F -f \
141         -c "fsync"              \
142         -c "pwrite 551917 41182"        \
143         -c "falloc 917633 392230"       \
144         -c "pwrite 285771 77718"        \
145         -c "pwrite 1136718 104115"      \
146         $TEST_DIR/test214-7 | _filter_xfs_io_unique
147
148
149 # success, all done
150 status=0
151 exit