4 # Test to ensure that the EOFBLOCK_FL gets set/unset correctly.
6 # As found by Theodore Ts'o:
7 # If a 128K file is falloc'ed using the KEEP_SIZE flag, and then
8 # write exactly 128K, the EOFBLOCK_FL doesn't get cleared correctly.
9 # This is bad since it forces e2fsck to complain about that inode.
10 # If you have a large number of inodes that are written with fallocate
11 # using KEEP_SIZE, and then fill them up to their expected size,
12 # e2fsck will potentially complain about a _huge_ number of inodes.
13 # This would also cause a huge increase in the time taken by e2fsck
14 # to complete its check.
16 # Test scenarios covered:
17 # 1. Fallocating X bytes and writing Y (Y<X) (buffered and direct io)
18 # 2. Fallocating X bytes and writing Y (Y=X) (buffered and direct io)
19 # 3. Fallocating X bytes and writing Y (Y>X) (buffered and direct io)
21 # These test cases exercise the normal and edge case conditions using
22 # falloc (and KEEP_SIZE).
24 # Ref: http://thread.gmane.org/gmane.comp.file-systems.ext4/20682
26 #-----------------------------------------------------------------------
27 # Copyright (c) 2010 Google, Inc. All Rights Reserved.
29 # This program is free software; you can redistribute it and/or
30 # modify it under the terms of the GNU General Public License as
31 # published by the Free Software Foundation.
33 # This program is distributed in the hope that it would be useful,
34 # but WITHOUT ANY WARRANTY; without even the implied warranty of
35 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 # GNU General Public License for more details.
38 # You should have received a copy of the GNU General Public License
39 # along with this program; if not, write the Free Software Foundation,
40 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
41 #-----------------------------------------------------------------------
47 echo "QA output created by $seq"
51 status=1 # failure is the default!
52 trap "_cleanup; exit \$status" 0 1 2 3 15
54 # Test specific macros.
55 BIT_NOT_SET=0 # inode flag - 0x400000 bit is not set.
56 BIT_SET=1 # inode flag - 0x400000 bit is set.
58 # Generic test cleanup function.
65 # Ext4 uses the EOFBLOCKS_FL bit when fallocating blocks with KEEP_SIZE
66 # enabled. The only time this bit should be set is when extending the allocated
67 # blocks further than what the i_size represents. In the situations wherein the
68 # i_size covers all allocated blocks, this bit should be cleared.
70 # Checks the state of the sample file in the filesystem and returns whether
71 # the inode flag 0x400000 is set or not.
72 _check_ext4_eof_flag()
74 # Check whether EOFBLOCK_FL is set.
75 # For ext4 filesystems: use debugfs to check if EOFBLOCKS_FL is set.
76 # Other filesystems: do nothing. The default fsck at the end of the test
77 # should catch any potential errors.
78 if [ "${FSTYP}" == "ext4" ]; then
81 # Unmount the ${TEST_DEV}
84 # Run debugfs to gather file_parameters - specifically iflags.
85 file_params=`debugfs ${TEST_DEV} -R "stat ${1}" 2>&1 | grep -e Flags:`
86 iflags=${file_params#*Flags: }
88 # Ensure that the iflags value was parsed correctly.
89 if [ -z ${iflags} ]; then
90 echo "iFlags value was not parsed successfully." >> $seq.full
95 # Check if EOFBLOCKS_FL is set.
96 if ((${iflags} & 0x400000)); then
97 echo "EOFBLOCK_FL bit is set." >> $seq.full
100 echo "EOFBLOCK_FL bit is not set." >> $seq.full
104 # Check current bit state to expected value.
105 if [ ${bit_set} -ne ${2} ]; then
106 echo "Error: Current bit state incorrect." >> $seq.full
111 # Mount the ${TEST_DEV}
112 mount ${TEST_DEV} -t ${FSTYP} ${TEST_DIR}
116 # Get standard environment, filters and checks.
120 # Prerequisites for the test run.
121 _supported_fs ext4 xfs btrfs gfs2
123 _require_xfs_io_falloc
125 # Real QA test starts here.
129 echo "Test 1: Fallocate 40960 bytes and write 4096 bytes (buffered io)." \
131 ${XFS_IO_PROG} -F -f \
132 -c 'falloc -k 0 40960' \
134 ${TEST_DIR}/test_1 | _filter_xfs_io_unique
135 _check_ext4_eof_flag test_1 ${BIT_SET}
137 echo "Test 2: Fallocate 40960 bytes and write 4096 bytes (direct io)." \
139 ${XFS_IO_PROG} -F -f -d \
140 -c 'falloc -k 0 40960' \
142 ${TEST_DIR}/test_2 | _filter_xfs_io_unique
143 _check_ext4_eof_flag test_2 ${BIT_SET}
145 echo "Test 3: Fallocate 40960 bytes and write 40960 bytes (buffered io)." \
147 ${XFS_IO_PROG} -F -f \
148 -c 'falloc -k 0 40960' \
149 -c 'pwrite 0 40960' \
150 ${TEST_DIR}/test_3 | _filter_xfs_io_unique
151 _check_ext4_eof_flag test_3 ${BIT_NOT_SET}
153 echo "Test 4: Fallocate 40960 bytes and write 40960 bytes (direct io)." \
155 ${XFS_IO_PROG} -F -f -d \
156 -c 'falloc -k 0 40960' \
157 -c 'pwrite 0 40960' \
158 ${TEST_DIR}/test_4 | _filter_xfs_io_unique
159 _check_ext4_eof_flag test_4 ${BIT_NOT_SET}
161 echo "Test 5: Fallocate 128k, seek 256k and write 4k block (buffered io)." \
163 ${XFS_IO_PROG} -F -f \
164 -c 'falloc -k 0 128k' \
165 -c 'pwrite 256k 4k' \
166 ${TEST_DIR}/test_5 | _filter_xfs_io_unique
167 _check_ext4_eof_flag test_5 ${BIT_NOT_SET}
169 echo "Test 6: Fallocate 128k, seek to 256k and write a 4k block (direct io)." \
171 ${XFS_IO_PROG} -F -f -d \
172 -c 'falloc -k 0 128k' \
173 -c 'pwrite 256k 4k' \
174 ${TEST_DIR}/test_6 | _filter_xfs_io_unique
175 _check_ext4_eof_flag test_6 ${BIT_NOT_SET}