2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Oracle, Inc. All Rights Reserved.
7 # fallocate/truncate tests with FALLOC_FL_KEEP_SIZE option.
8 # Verify if the disk space is released after truncating a file back
9 # to the old smaller size. Before Linux 3.10, Btrfs/OCFS2 are test
10 # failed in this case.
13 _begin_fstest auto quick rw prealloc
15 status=0 # success is the default!
17 # Import common functions.
20 # real QA test starts here
22 # Modify as appropriate.
25 _require_xfs_io_command "falloc" "-k"
27 echo "Slience is golden"
29 # Check the current avaliable disk space on $TEST_DIR.
31 avail_begin=`df -P $TEST_DIR | awk 'END {print $4}'`
32 [ "$avail_begin" -ge 1024 ] || _notrun "Test device is too small ($avail_begin KiB)"
34 # Preallocate half size of the available disk space to a file
35 # starts from offset 0 with FALLOC_FL_KEEP_SIZE option on the
37 $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
38 $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
40 # Verify the file size, it should keep unchanged as 0 in this case
41 fsize=`_get_filesize $TEST_DIR/testfile.$seq`
42 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
44 # Truncate the file size back to 0
45 truncate -s 0 $TEST_DIR/testfile.$seq
48 # Preallocated disk space should be released
49 avail_done=`df -P $TEST_DIR | awk 'END {print $4}'`
50 _within_tolerance "df" $avail_done $avail_begin 1%
51 [ $? -eq 0 ] || _fail "Available disk space ($avail_done KiB) wanted ($avail_begin KiB)"