2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2010 Google, Inc. All Rights Reserved.
5 # FS QA Test No. ext4/002
7 # Test to ensure that the EOFBLOCK_FL gets set/unset correctly.
9 # As found by Theodore Ts'o:
10 # If a 128K file is falloc'ed using the KEEP_SIZE flag, and then
11 # write exactly 128K, the EOFBLOCK_FL doesn't get cleared correctly.
12 # This is bad since it forces e2fsck to complain about that inode.
13 # If you have a large number of inodes that are written with fallocate
14 # using KEEP_SIZE, and then fill them up to their expected size,
15 # e2fsck will potentially complain about a _huge_ number of inodes.
16 # This would also cause a huge increase in the time taken by e2fsck
17 # to complete its check.
19 # Test scenarios covered:
20 # 1. Fallocating X bytes and writing Y (Y<X) (buffered and direct io)
21 # 2. Fallocating X bytes and writing Y (Y=X) (buffered and direct io)
22 # 3. Fallocating X bytes and writing Y (Y>X) (buffered and direct io)
24 # These test cases exercise the normal and edge case conditions using
25 # falloc (and KEEP_SIZE).
27 # Ref: http://thread.gmane.org/gmane.comp.file-systems.ext4/20682
30 seqres=$RESULT_DIR/$seq
31 echo "QA output created by $seq"
35 status=1 # failure is the default!
36 trap "_cleanup; exit \$status" 0 1 2 3 15
38 # Test specific macros.
39 BIT_NOT_SET=0 # inode flag - 0x400000 bit is not set.
40 BIT_SET=1 # inode flag - 0x400000 bit is set.
42 # Generic test cleanup function.
49 # Ext4 uses the EOFBLOCKS_FL bit when fallocating blocks with KEEP_SIZE
50 # enabled. The only time this bit should be set is when extending the allocated
51 # blocks further than what the i_size represents. In the situations wherein the
52 # i_size covers all allocated blocks, this bit should be cleared.
54 # Checks the state of the sample file in the filesystem and returns whether
55 # the inode flag 0x400000 is set or not.
56 _check_ext4_eof_flag()
58 # Check whether EOFBLOCK_FL is set.
59 # For ext4 filesystems: use debugfs to check if EOFBLOCKS_FL is set.
60 # Other filesystems: do nothing. The default fsck at the end of the test
61 # should catch any potential errors.
62 if [ "${FSTYP}" == "ext4" ]; then
65 # Unmount the ${TEST_DEV}
68 # Run debugfs to gather file_parameters - specifically iflags.
69 file_params=`debugfs ${TEST_DEV} -R "stat ${1}" 2>&1 | grep -e Flags:`
70 iflags=${file_params#*Flags: }
72 # Ensure that the iflags value was parsed correctly.
73 if [ -z ${iflags} ]; then
74 echo "iFlags value was not parsed successfully." >> $seqres.full
79 # Check if EOFBLOCKS_FL is set.
80 if ((${iflags} & 0x400000)); then
81 echo "EOFBLOCK_FL bit is set." >> $seqres.full
84 echo "EOFBLOCK_FL bit is not set." >> $seqres.full
88 # Check current bit state to expected value.
89 if [ ${bit_set} -ne ${2} ]; then
90 echo "Error: Current bit state incorrect." >> $seqres.full
95 # Mount the ${TEST_DEV}
96 mount ${TEST_DEV} -t ${FSTYP} ${TEST_DIR}
100 # Get standard environment, filters and checks.
104 # Prerequisites for the test run.
107 _require_xfs_io_command "falloc"
110 # Real QA test starts here.
113 # Remove any leftover files from last run.
114 rm -f ${TEST_DIR}/test_?
117 echo "Test 1: Fallocate 40960 bytes and write 4096 bytes (buffered io)." \
120 -c 'falloc -k 0 40960' \
122 ${TEST_DIR}/test_1 | _filter_xfs_io_unique
123 _check_ext4_eof_flag test_1 ${BIT_SET}
125 echo "Test 2: Fallocate 40960 bytes and write 4096 bytes (direct io)." \
127 ${XFS_IO_PROG} -f -d \
128 -c 'falloc -k 0 40960' \
130 ${TEST_DIR}/test_2 | _filter_xfs_io_unique
131 _check_ext4_eof_flag test_2 ${BIT_SET}
133 echo "Test 3: Fallocate 40960 bytes and write 40960 bytes (buffered io)." \
136 -c 'falloc -k 0 40960' \
137 -c 'pwrite 0 40960' \
138 ${TEST_DIR}/test_3 | _filter_xfs_io_unique
139 _check_ext4_eof_flag test_3 ${BIT_NOT_SET}
141 echo "Test 4: Fallocate 40960 bytes and write 40960 bytes (direct io)." \
143 ${XFS_IO_PROG} -f -d \
144 -c 'falloc -k 0 40960' \
145 -c 'pwrite 0 40960' \
146 ${TEST_DIR}/test_4 | _filter_xfs_io_unique
147 _check_ext4_eof_flag test_4 ${BIT_NOT_SET}
149 echo "Test 5: Fallocate 128k, seek 256k and write 4k block (buffered io)." \
152 -c 'falloc -k 0 128k' \
153 -c 'pwrite 256k 4k' \
154 ${TEST_DIR}/test_5 | _filter_xfs_io_unique
155 _check_ext4_eof_flag test_5 ${BIT_NOT_SET}
157 echo "Test 6: Fallocate 128k, seek to 256k and write a 4k block (direct io)." \
159 ${XFS_IO_PROG} -f -d \
160 -c 'falloc -k 0 128k' \
161 -c 'pwrite 256k 4k' \
162 ${TEST_DIR}/test_6 | _filter_xfs_io_unique
163 _check_ext4_eof_flag test_6 ${BIT_NOT_SET}