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 ${SCRATCH_DEV}
68 # Run debugfs to gather file_parameters - specifically iflags.
69 file_params=`debugfs ${SCRATCH_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 ${SCRATCH_DEV}
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 _scratch_mkfs >> $seqres.full 2>&1
116 BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
119 echo "Test 1: Fallocate 10 blocks and write 1 block (buffered io)." \
122 -c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
123 -c "pwrite 0 $BLOCK_SIZE" \
124 ${SCRATCH_MNT}/test_1 | _filter_xfs_io_blocks_modified
125 _check_ext4_eof_flag test_1 ${BIT_SET}
127 echo "Test 2: Fallocate 10 blocks and write 1 block (direct io)." \
129 ${XFS_IO_PROG} -f -d \
130 -c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
131 -c "pwrite 0 $BLOCK_SIZE" \
132 ${SCRATCH_MNT}/test_2 | _filter_xfs_io_blocks_modified
133 _check_ext4_eof_flag test_2 ${BIT_SET}
135 echo "Test 3: Fallocate 10 blocks and write 10 blocks (buffered io)." \
138 -c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
139 -c "pwrite 0 $((10 * $BLOCK_SIZE))" \
140 ${SCRATCH_MNT}/test_3 | _filter_xfs_io_blocks_modified
141 _check_ext4_eof_flag test_3 ${BIT_NOT_SET}
143 echo "Test 4: Fallocate 10 blocks and write 10 blocks (direct io)." \
145 ${XFS_IO_PROG} -f -d \
146 -c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
147 -c "pwrite 0 $((10 * $BLOCK_SIZE))" \
148 ${SCRATCH_MNT}/test_4 | _filter_xfs_io_blocks_modified
149 _check_ext4_eof_flag test_4 ${BIT_NOT_SET}
151 echo "Test 5: Fallocate 32 blocks, seek 64 blocks and write 1 block (buffered io)." \
154 -c "falloc -k 0 $((32 * $BLOCK_SIZE))" \
155 -c "pwrite $((64 * $BLOCK_SIZE)) $BLOCK_SIZE" \
156 ${SCRATCH_MNT}/test_5 | _filter_xfs_io_blocks_modified
157 _check_ext4_eof_flag test_5 ${BIT_NOT_SET}
159 echo "Test 6: Fallocate 32 blocks, seek to 64 blocks and write 1 block (direct io)." \
161 ${XFS_IO_PROG} -f -d \
162 -c "falloc -k 0 $((32 * $BLOCK_SIZE))" \
163 -c "pwrite $((64 * $BLOCK_SIZE)) $BLOCK_SIZE" \
164 ${SCRATCH_MNT}/test_6 | _filter_xfs_io_blocks_modified
165 _check_ext4_eof_flag test_6 ${BIT_NOT_SET}