mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
6b06a9bb6f
This commit changes the script to operate on FS blocks by obtaining the block size from the underlying filesystem and using it to perform I/O in units of block sizes. This commit also uses $SCRATCH_MNT rather than $TEST_DIR for holding the test files since the FS on $TEST_DIR might be created with a different block size than the one specified in $MKFS_OPTIONS. Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com> Reviewed-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
169 lines
5.3 KiB
Bash
Executable File
169 lines
5.3 KiB
Bash
Executable File
#! /bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# Copyright (c) 2010 Google, Inc. All Rights Reserved.
|
|
#
|
|
# FS QA Test No. ext4/002
|
|
#
|
|
# Test to ensure that the EOFBLOCK_FL gets set/unset correctly.
|
|
#
|
|
# As found by Theodore Ts'o:
|
|
# If a 128K file is falloc'ed using the KEEP_SIZE flag, and then
|
|
# write exactly 128K, the EOFBLOCK_FL doesn't get cleared correctly.
|
|
# This is bad since it forces e2fsck to complain about that inode.
|
|
# If you have a large number of inodes that are written with fallocate
|
|
# using KEEP_SIZE, and then fill them up to their expected size,
|
|
# e2fsck will potentially complain about a _huge_ number of inodes.
|
|
# This would also cause a huge increase in the time taken by e2fsck
|
|
# to complete its check.
|
|
#
|
|
# Test scenarios covered:
|
|
# 1. Fallocating X bytes and writing Y (Y<X) (buffered and direct io)
|
|
# 2. Fallocating X bytes and writing Y (Y=X) (buffered and direct io)
|
|
# 3. Fallocating X bytes and writing Y (Y>X) (buffered and direct io)
|
|
#
|
|
# These test cases exercise the normal and edge case conditions using
|
|
# falloc (and KEEP_SIZE).
|
|
#
|
|
# Ref: http://thread.gmane.org/gmane.comp.file-systems.ext4/20682
|
|
#
|
|
seq=`basename $0`
|
|
seqres=$RESULT_DIR/$seq
|
|
echo "QA output created by $seq"
|
|
|
|
here=`pwd`
|
|
tmp=/tmp/$$
|
|
status=1 # failure is the default!
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
# Test specific macros.
|
|
BIT_NOT_SET=0 # inode flag - 0x400000 bit is not set.
|
|
BIT_SET=1 # inode flag - 0x400000 bit is set.
|
|
|
|
# Generic test cleanup function.
|
|
_cleanup()
|
|
{
|
|
cd /
|
|
rm -f $tmp.*
|
|
}
|
|
|
|
# Ext4 uses the EOFBLOCKS_FL bit when fallocating blocks with KEEP_SIZE
|
|
# enabled. The only time this bit should be set is when extending the allocated
|
|
# blocks further than what the i_size represents. In the situations wherein the
|
|
# i_size covers all allocated blocks, this bit should be cleared.
|
|
|
|
# Checks the state of the sample file in the filesystem and returns whether
|
|
# the inode flag 0x400000 is set or not.
|
|
_check_ext4_eof_flag()
|
|
{
|
|
# Check whether EOFBLOCK_FL is set.
|
|
# For ext4 filesystems: use debugfs to check if EOFBLOCKS_FL is set.
|
|
# Other filesystems: do nothing. The default fsck at the end of the test
|
|
# should catch any potential errors.
|
|
if [ "${FSTYP}" == "ext4" ]; then
|
|
bit_set=1
|
|
|
|
# Unmount the ${TEST_DEV}
|
|
_test_unmount
|
|
|
|
# Run debugfs to gather file_parameters - specifically iflags.
|
|
file_params=`debugfs ${TEST_DEV} -R "stat ${1}" 2>&1 | grep -e Flags:`
|
|
iflags=${file_params#*Flags: }
|
|
|
|
# Ensure that the iflags value was parsed correctly.
|
|
if [ -z ${iflags} ]; then
|
|
echo "iFlags value was not parsed successfully." >> $seqres.full
|
|
status=1
|
|
exit ${status}
|
|
fi
|
|
|
|
# Check if EOFBLOCKS_FL is set.
|
|
if ((${iflags} & 0x400000)); then
|
|
echo "EOFBLOCK_FL bit is set." >> $seqres.full
|
|
bit_set=1
|
|
else
|
|
echo "EOFBLOCK_FL bit is not set." >> $seqres.full
|
|
bit_set=0
|
|
fi
|
|
|
|
# Check current bit state to expected value.
|
|
if [ ${bit_set} -ne ${2} ]; then
|
|
echo "Error: Current bit state incorrect." >> $seqres.full
|
|
status=1
|
|
exit ${status}
|
|
fi
|
|
|
|
# Mount the ${TEST_DEV}
|
|
mount ${TEST_DEV} -t ${FSTYP} ${TEST_DIR}
|
|
fi
|
|
}
|
|
|
|
# Get standard environment, filters and checks.
|
|
. ./common/rc
|
|
. ./common/filter
|
|
|
|
# Prerequisites for the test run.
|
|
_supported_fs ext4
|
|
_supported_os Linux
|
|
_require_xfs_io_command "falloc"
|
|
_require_scratch
|
|
|
|
# Real QA test starts here.
|
|
rm -f $seqres.full
|
|
|
|
_scratch_mkfs >> $seqres.full 2>&1
|
|
_scratch_mount
|
|
|
|
BLOCK_SIZE=$(_get_block_size $SCRATCH_MNT)
|
|
|
|
# Begin test cases.
|
|
echo "Test 1: Fallocate 10 blocks and write 1 block (buffered io)." \
|
|
>> $seqres.full
|
|
${XFS_IO_PROG} -f \
|
|
-c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
|
|
-c "pwrite 0 $BLOCK_SIZE" \
|
|
${SCRATCH_MNT}/test_1 | _filter_xfs_io_blocks_modified
|
|
_check_ext4_eof_flag test_1 ${BIT_SET}
|
|
|
|
echo "Test 2: Fallocate 10 blocks and write 1 block (direct io)." \
|
|
>> $seqres.full
|
|
${XFS_IO_PROG} -f -d \
|
|
-c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
|
|
-c "pwrite 0 $BLOCK_SIZE" \
|
|
${SCRATCH_MNT}/test_2 | _filter_xfs_io_blocks_modified
|
|
_check_ext4_eof_flag test_2 ${BIT_SET}
|
|
|
|
echo "Test 3: Fallocate 10 blocks and write 10 blocks (buffered io)." \
|
|
>> $seqres.full
|
|
${XFS_IO_PROG} -f \
|
|
-c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
|
|
-c "pwrite 0 $((10 * $BLOCK_SIZE))" \
|
|
${SCRATCH_MNT}/test_3 | _filter_xfs_io_blocks_modified
|
|
_check_ext4_eof_flag test_3 ${BIT_NOT_SET}
|
|
|
|
echo "Test 4: Fallocate 10 blocks and write 10 blocks (direct io)." \
|
|
>> $seqres.full
|
|
${XFS_IO_PROG} -f -d \
|
|
-c "falloc -k 0 $((10 * $BLOCK_SIZE))" \
|
|
-c "pwrite 0 $((10 * $BLOCK_SIZE))" \
|
|
${SCRATCH_MNT}/test_4 | _filter_xfs_io_blocks_modified
|
|
_check_ext4_eof_flag test_4 ${BIT_NOT_SET}
|
|
|
|
echo "Test 5: Fallocate 32 blocks, seek 64 blocks and write 1 block (buffered io)." \
|
|
>> $seqres.full
|
|
${XFS_IO_PROG} -f \
|
|
-c "falloc -k 0 $((32 * $BLOCK_SIZE))" \
|
|
-c "pwrite $((64 * $BLOCK_SIZE)) $BLOCK_SIZE" \
|
|
${SCRATCH_MNT}/test_5 | _filter_xfs_io_blocks_modified
|
|
_check_ext4_eof_flag test_5 ${BIT_NOT_SET}
|
|
|
|
echo "Test 6: Fallocate 32 blocks, seek to 64 blocks and write 1 block (direct io)." \
|
|
>> $seqres.full
|
|
${XFS_IO_PROG} -f -d \
|
|
-c "falloc -k 0 $((32 * $BLOCK_SIZE))" \
|
|
-c "pwrite $((64 * $BLOCK_SIZE)) $BLOCK_SIZE" \
|
|
${SCRATCH_MNT}/test_6 | _filter_xfs_io_blocks_modified
|
|
_check_ext4_eof_flag test_6 ${BIT_NOT_SET}
|
|
|
|
status=0
|
|
exit ${status}
|