generic: shutdown fs after log recovery
[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 _require_xfs_io_command "falloc"
53
54 rm -f $seqres.full
55
56 echo "Slience is golden"
57
58 # Check the current avaliable disk space on $TEST_DIR.
59 # 1024KiB at least
60 avail_begin=`df -P $TEST_DIR | awk 'END {print $4}'`
61 [ "$avail_begin" -ge 1024 ] || _notrun "Test device is too small ($avail_begin KiB)"
62
63 # Preallocate half size of the available disk space to a file
64 # starts from offset 0 with FALLOC_FL_KEEP_SIZE option on the
65 # test file system.
66 $XFS_IO_PROG -f -c 'falloc -k 0 $(($avail_begin/2))' \
67         $TEST_DIR/testfile.$seq >>$seqres.full 2>&1
68
69 # Verify the file size, it should keep unchanged as 0 in this case
70 fsize=`ls -l $TEST_DIR/testfile.$seq | awk '{print $5}'`
71 [ "$fsize" -eq 0 ] || _fail "File size is changed to ($fsize Bytes)"
72
73 # Truncate the file size back to 0
74 truncate -s 0 $TEST_DIR/testfile.$seq
75 sync
76
77 # Preallocated disk space should be released
78 avail_done=`df -P $TEST_DIR | awk 'END {print $4}'`
79 _within_tolerance "df" $avail_done $avail_begin 1%
80 [ $? -eq 0 ] || _fail "Available disk space ($avail_done KiB) wanted ($avail_begin KiB)"
81
82 # success, all done
83 exit