03d4491fd6112f0f32770db15902d4043d90ca4c
[xfstests-dev.git] / tests / generic / 228
1 #! /bin/bash
2 # FS QA Test No. 228
3 #
4 # Check if fallocate respects RLIMIT_FSIZE
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2010 IBM Corporation. All Rights Reserved.
8 #
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation.
12 #
13 # This program is distributed in the hope that it would be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write the Free Software Foundation,
20 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 #
22 #-----------------------------------------------------------------------
23 #
24
25 seq=`basename $0`
26 seqres=$RESULT_DIR/$seq
27 echo "QA output created by $seq"
28
29 _cleanup()
30 {
31         cd /
32         rm -f $tmp.*
33         sysctl -w kernel.core_pattern="$core_pattern" &>/dev/null
34         ulimit -c $ulimit_c
35 }
36
37 here=`pwd`
38 tmp=$TEST_DIR/$$
39 status=1        # failure is the default!
40 trap "_cleanup; exit \$status" 0 1 2 3 15 25
41
42 # get standard environment, filters and checks
43 . ./common/rc
44
45 # real QA test starts here
46 # generic, but xfs_io's fallocate must work
47 _supported_fs generic
48 # only Linux supports fallocate
49 _supported_os Linux
50
51 [ -n "$XFS_IO_PROG" ] || _notrun "xfs_io executable not found"
52
53 rm -f $seqres.full
54
55 # Sanity check to see if fallocate works
56 _require_xfs_io_falloc
57
58 # Check if we have good enough space available
59 avail=`df -P $TEST_DIR | awk 'END {print $4}'`
60 [ "$avail" -ge 104000 ] || _notrun "Test device is too small ($avail KiB)"
61
62 # Suppress core dumped messages
63 core_pattern=`sysctl kernel.core_pattern | awk -F = '{print $NF}'`
64 ulimit_c=`ulimit -c`
65 sysctl -w kernel.core_pattern=core &>/dev/null
66 ulimit -c 0
67
68 # Set the FSIZE ulimit to 100MB and check
69 ulimit -f 102400
70 flim=`ulimit -f`
71 [ "$flim" != "unlimited" ] || _notrun "Unable to set FSIZE ulimit"
72 [ "$flim" -eq 102400 ] || _notrun "FSIZE ulimit is not correct (100 MB)"
73
74 echo "File size limit is now set to 100 MB."
75 echo "Let us try to preallocate 101 MB. This should fail."
76 $XFS_IO_PROG -f -c 'falloc 0 101m' $TEST_DIR/ouch
77 rm -f $TEST_DIR/ouch
78
79 echo "Let us now try to preallocate 50 MB. This should succeed."
80 $XFS_IO_PROG -f -c 'falloc 0 50m' $TEST_DIR/ouch
81 rm -f $TEST_DIR/ouch
82
83 echo "Test over."
84 # success, all done
85 status=0
86 exit