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