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 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=0 # success is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
31 # real QA test starts here
33 # Modify as appropriate.
36 _require_xfs_io_command "falloc" "-k"
40 echo "Slience is golden"
42 # Check the current avaliable disk space on $TEST_DIR.
44 avail_begin=`df -P $TEST_DIR | awk 'END {print $4}'`
45 [ "$avail_begin" -ge 1024 ] || _notrun "Test device is too small ($avail_begin KiB)"
47 # Preallocate half size of the available disk space to a file
48 # starts from offset 0 with FALLOC_FL_KEEP_SIZE option on the
50 $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
51 $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
53 # Verify the file size, it should keep unchanged as 0 in this case
54 fsize=`_get_filesize $TEST_DIR/testfile.$seq`
55 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
57 # Truncate the file size back to 0
58 truncate -s 0 $TEST_DIR/testfile.$seq
61 # Preallocated disk space should be released
62 avail_done=`df -P $TEST_DIR | awk 'END {print $4}'`
63 _within_tolerance "df" $avail_done $avail_begin 1%
64 [ $? -eq 0 ] || _fail "Available disk space ($avail_done KiB) wanted ($avail_begin KiB)"