2 # FS QA Test No. ext4/002
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 #-----------------------------------------------------------------------
45 seqres=$RESULT_DIR/$seq
46 echo "QA output created by $seq"
50 status=1 # failure is the default!
51 trap "_cleanup; exit \$status" 0 1 2 3 15
53 # Test specific macros.
54 BIT_NOT_SET=0 # inode flag - 0x400000 bit is not set.
55 BIT_SET=1 # inode flag - 0x400000 bit is set.
57 # Generic test cleanup function.
64 # Ext4 uses the EOFBLOCKS_FL bit when fallocating blocks with KEEP_SIZE
65 # enabled. The only time this bit should be set is when extending the allocated
66 # blocks further than what the i_size represents. In the situations wherein the
67 # i_size covers all allocated blocks, this bit should be cleared.
69 # Checks the state of the sample file in the filesystem and returns whether
70 # the inode flag 0x400000 is set or not.
71 _check_ext4_eof_flag()
73 # Check whether EOFBLOCK_FL is set.
74 # For ext4 filesystems: use debugfs to check if EOFBLOCKS_FL is set.
75 # Other filesystems: do nothing. The default fsck at the end of the test
76 # should catch any potential errors.
77 if [ "${FSTYP}" == "ext4" ]; then
80 # Unmount the ${TEST_DEV}
83 # Run debugfs to gather file_parameters - specifically iflags.
84 file_params=`debugfs ${TEST_DEV} -R "stat ${1}" 2>&1 | grep -e Flags:`
85 iflags=${file_params#*Flags: }
87 # Ensure that the iflags value was parsed correctly.
88 if [ -z ${iflags} ]; then
89 echo "iFlags value was not parsed successfully." >> $seqres.full
94 # Check if EOFBLOCKS_FL is set.
95 if ((${iflags} & 0x400000)); then
96 echo "EOFBLOCK_FL bit is set." >> $seqres.full
99 echo "EOFBLOCK_FL bit is not set." >> $seqres.full
103 # Check current bit state to expected value.
104 if [ ${bit_set} -ne ${2} ]; then
105 echo "Error: Current bit state incorrect." >> $seqres.full
110 # Mount the ${TEST_DEV}
111 mount ${TEST_DEV} -t ${FSTYP} ${TEST_DIR}
115 # Get standard environment, filters and checks.
119 # Prerequisites for the test run.
122 _require_xfs_io_command "falloc"
125 # Real QA test starts here.
128 # Remove any leftover files from last run.
129 rm -f ${TEST_DIR}/test_?
132 echo "Test 1: Fallocate 40960 bytes and write 4096 bytes (buffered io)." \
135 -c 'falloc -k 0 40960' \
137 ${TEST_DIR}/test_1 | _filter_xfs_io_unique
138 _check_ext4_eof_flag test_1 ${BIT_SET}
140 echo "Test 2: Fallocate 40960 bytes and write 4096 bytes (direct io)." \
142 ${XFS_IO_PROG} -f -d \
143 -c 'falloc -k 0 40960' \
145 ${TEST_DIR}/test_2 | _filter_xfs_io_unique
146 _check_ext4_eof_flag test_2 ${BIT_SET}
148 echo "Test 3: Fallocate 40960 bytes and write 40960 bytes (buffered io)." \
151 -c 'falloc -k 0 40960' \
152 -c 'pwrite 0 40960' \
153 ${TEST_DIR}/test_3 | _filter_xfs_io_unique
154 _check_ext4_eof_flag test_3 ${BIT_NOT_SET}
156 echo "Test 4: Fallocate 40960 bytes and write 40960 bytes (direct io)." \
158 ${XFS_IO_PROG} -f -d \
159 -c 'falloc -k 0 40960' \
160 -c 'pwrite 0 40960' \
161 ${TEST_DIR}/test_4 | _filter_xfs_io_unique
162 _check_ext4_eof_flag test_4 ${BIT_NOT_SET}
164 echo "Test 5: Fallocate 128k, seek 256k and write 4k block (buffered io)." \
167 -c 'falloc -k 0 128k' \
168 -c 'pwrite 256k 4k' \
169 ${TEST_DIR}/test_5 | _filter_xfs_io_unique
170 _check_ext4_eof_flag test_5 ${BIT_NOT_SET}
172 echo "Test 6: Fallocate 128k, seek to 256k and write a 4k block (direct io)." \
174 ${XFS_IO_PROG} -f -d \
175 -c 'falloc -k 0 128k' \
176 -c 'pwrite 256k 4k' \
177 ${TEST_DIR}/test_6 | _filter_xfs_io_unique
178 _check_ext4_eof_flag test_6 ${BIT_NOT_SET}