4 # fallocate/truncate tests with FALLOC_FL_KEEP_SIZE option.
5 # Verify if the disk space is released after truncating a file back
6 # to the old smaller size. Before Linux 3.10, Btrfs/OCFS2 are test
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2013 Oracle, Inc. All Rights Reserved.
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #-----------------------------------------------------------------------
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
33 status=0 # success is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
42 # get standard environment, filters and checks
46 # real QA test starts here
48 # Modify as appropriate.
55 echo "Slience is golden"
57 # Check the current avaliable disk space on $TEST_DIR.
59 avail_begin=`df -P $TEST_DIR | awk 'END {print $4}'`
60 [ "$avail_begin" -ge 1024 ] || _notrun "Test device is too small ($avail_begin KiB)"
62 # Preallocate half size of the available disk space to a file
63 # starts from offset 0 with FALLOC_FL_KEEP_SIZE option on the
65 fallocate -n -o 0 -l $(($avail_begin/2)) $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
67 # Verify the file size, it should keep unchanged as 0 in this case
68 fsize=`ls -l $TEST_DIR/testfile.$seq | awk '{print $5}'`
69 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
71 # Truncate the file size back to 0
72 truncate -s 0 $TEST_DIR/testfile.$seq
75 # Preallocated disk space should be released
76 avail_done=`df -P $TEST_DIR | awk 'END {print $4}'`
77 _within_tolerance "df" $avail_done $avail_begin 1%
78 [ $? -eq 0 ] || _fail "Available disk space ($avail_done KiB) wanted ($avail_begin KiB)"