2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 IBM Corporation. All Rights Reserved.
7 # Test Full File System Hole Punching
10 _begin_fstest auto quick punch
12 # Import common functions.
17 # real QA test starts here
20 _require_xfs_io_command "fpunch"
25 testfile=$TEST_DIR/256.$$
27 # _test_full_fs_punch()
29 # This function will test that a hole may be punched
30 # even when the file system is full. Reserved blocks
31 # should be used to allow a punch hole to proceed even
32 # when there is not enough blocks to further fragment the
33 # file. To test this, this function will fragment the file
34 # system by punching holes in regular intervals and filling
35 # the file system between punches.
39 local hole_len=$1 # The length of the holes to punch
40 local hole_interval=$2 # The interval between the holes
41 local iterations=$3 # The number of holes to punch
42 local file_name=$4 # File to punch holes in
43 local block_size=$5 # File system block size
44 local file_len=$(( $(( $hole_len + $hole_interval )) * $iterations ))
45 local path=`dirname $file_name`
50 echo "USAGE: _test_full_fs_punch hole_len hole_interval iterations file_name block_size"
54 rm -f $file_name &> /dev/null
56 $XFS_IO_PROG -f -c "pwrite 0 $file_len" \
57 -c "fsync" $file_name &> /dev/null
60 # All files are created as a non root user to prevent reserved blocks
61 # from being consumed.
62 _fill_fs $(( 1024 * 1024 * 1024 )) $path/fill $block_size 1 \
65 for (( i=0; i<$iterations; i++ ))
67 # This part must not be done as root in order to
68 # test that reserved blocks are used when needed
69 _user_do "$XFS_IO_PROG -f -c \"fpunch $hole_offset $hole_len\" $file_name"
71 if [ $? -ne 0 ] ; then
72 echo Punch hole failed
76 hole_offset=$(( $hole_offset + $hole_len + $hole_interval ))
78 _fill_fs $hole_len $path/fill.$i $block_size 1 > /dev/null 2>&1
83 # Make a small file system to fill
84 _scratch_unmount &> /dev/null
85 _scratch_mkfs_sized $(( 1536 * 1024 * 1024 )) &> /dev/null
87 # Test must be able to write files with non-root permissions
88 chmod 777 $SCRATCH_MNT
90 block_size=`_get_block_size $SCRATCH_MNT`
91 _test_full_fs_punch $(( $block_size * 2 )) $block_size 500 $SCRATCH_MNT/252.$$ $block_size