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