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.
37 _require_xfs_io_command "falloc" "-k"
41 echo "Slience is golden"
43 # Check the current avaliable disk space on $TEST_DIR.
45 avail_begin=`df -P $TEST_DIR | awk 'END {print $4}'`
46 [ "$avail_begin" -ge 1024 ] || _notrun "Test device is too small ($avail_begin KiB)"
48 # Preallocate half size of the available disk space to a file
49 # starts from offset 0 with FALLOC_FL_KEEP_SIZE option on the
51 $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
52 $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
54 # Verify the file size, it should keep unchanged as 0 in this case
55 fsize=`_get_filesize $TEST_DIR/testfile.$seq`
56 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
58 # Truncate the file size back to 0
59 truncate -s 0 $TEST_DIR/testfile.$seq
62 # Preallocated disk space should be released
63 avail_done=`df -P $TEST_DIR | awk 'END {print $4}'`
64 _within_tolerance "df" $avail_done $avail_begin 1%
65 [ $? -eq 0 ] || _fail "Available disk space ($avail_done KiB) wanted ($avail_begin KiB)"