generic/228: set vars for early _cleanup
[xfstests-dev.git] / tests / generic / 228
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2010 IBM Corporation. All Rights Reserved.
4 #
5 # FS QA Test No. 228
6 #
7 # Check if fallocate respects RLIMIT_FSIZE
8 #
9 . ./common/preamble
10 _begin_fstest rw auto prealloc quick
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15         cd /
16         rm -f $tmp.*
17         sysctl -w kernel.core_pattern="$core_pattern" &>/dev/null
18         ulimit -c $ulimit_c
19 }
20
21 tmp=$TEST_DIR/$$
22 core_pattern=`sysctl -n kernel.core_pattern`
23 ulimit_c=`ulimit -c`
24 _register_cleanup "_cleanup" 25
25
26 # Import common functions.
27
28 # real QA test starts here
29 # generic, but xfs_io's fallocate must work
30 _supported_fs generic
31 # only Linux supports fallocate
32 _require_test
33
34 [ -n "$XFS_IO_PROG" ] || _notrun "xfs_io executable not found"
35
36 # Sanity check to see if fallocate works
37 _require_xfs_io_command "falloc"
38
39 # Check if we have good enough space available
40 avail=`df -P $TEST_DIR | awk 'END {print $4}'`
41 [ "$avail" -ge 104000 ] || _notrun "Test device is too small ($avail KiB)"
42
43 # Suppress core dumped messages
44 sysctl -w kernel.core_pattern=core &>/dev/null
45 ulimit -c 0
46
47 # Set the FSIZE ulimit to 100MB and check
48 ulimit -f 102400
49 flim=`ulimit -f`
50 [ "$flim" != "unlimited" ] || _notrun "Unable to set FSIZE ulimit"
51 [ "$flim" -eq 102400 ] || _notrun "FSIZE ulimit is not correct (100 MB)"
52
53 echo "File size limit is now set to 100 MB."
54 echo "Let us try to preallocate 101 MB. This should fail."
55 $XFS_IO_PROG -f -c 'falloc 0 101m' $TEST_DIR/ouch
56 rm -f $TEST_DIR/ouch
57
58 echo "Let us now try to preallocate 50 MB. This should succeed."
59 $XFS_IO_PROG -f -c 'falloc 0 50m' $TEST_DIR/ouch
60 rm -f $TEST_DIR/ouch
61
62 echo "Test over."
63 # success, all done
64 status=0
65 exit