common: Check fs consistency on TEST_DEV only when needed
[xfstests-dev.git] / tests / generic / 315
1 #! /bin/bash
2 # FS QA Test No. 315
3 #
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
7 # failed in this case.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2013 Oracle, Inc.  All Rights Reserved.
11 #
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.
15 #
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.
20 #
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 #-----------------------------------------------------------------------
25 #
26
27 seq=`basename $0`
28 seqres=$RESULT_DIR/$seq
29 echo "QA output created by $seq"
30
31 here=`pwd`
32 tmp=/tmp/$$
33 status=0        # success is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 _cleanup()
37 {
38     cd /
39     rm -f $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # real QA test starts here
47
48 # Modify as appropriate.
49 _supported_fs generic
50 _supported_os Linux
51 _require_test
52
53 rm -f $seqres.full
54
55 echo "Slience is golden"
56
57 # Check the current avaliable disk space on $TEST_DIR.
58 # 1024KiB at least
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)"
61
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
64 # test file system.
65 fallocate -n -o 0 -l $(($avail_begin/2)) $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
66
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)"
70
71 # Truncate the file size back to 0
72 truncate -s 0 $TEST_DIR/testfile.$seq
73 sync
74
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)"
79
80 # success, all done
81 exit