generic/402: Drop useless fail message
[xfstests-dev.git] / tests / generic / 315
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2013 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 315
6 #
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.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=0        # success is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # real QA test starts here
32
33 # Modify as appropriate.
34 _supported_fs generic
35 _require_test
36 _require_xfs_io_command "falloc" "-k"
37
38 rm -f $seqres.full
39
40 echo "Slience is golden"
41
42 # Check the current avaliable disk space on $TEST_DIR.
43 # 1024KiB at least
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)"
46
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
49 # test file system.
50 $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
51         $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
52
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)"
56
57 # Truncate the file size back to 0
58 truncate -s 0 $TEST_DIR/testfile.$seq
59 sync
60
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)"
65
66 # success, all done
67 exit