cb7252b98e46f5a38483a2f96d94f385237f500c
[xfstests-dev.git] / tests / generic / 015
1 #! /bin/bash
2 # FS QA Test No. 015
3 #
4 # check out-of-space behaviour
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  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 here=`pwd`
30 tmp=/tmp/$$
31 status=1        # success is the default!
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/filter
36
37 _cleanup()
38 {
39         _scratch_unmount
40 }
41
42 trap "_cleanup; exit \$status" 0 1 2 3 15
43
44 _free()
45 {
46     _df_dir $SCRATCH_MNT | $AWK_PROG '{ print $5 }'
47 }
48
49 # real QA test starts here
50 _supported_fs generic
51 _supported_os Linux
52
53 _require_scratch
54 _require_no_large_scratch_dev
55
56 # With filesystems less than 100mb btrfs is created in mixed mode
57 # which can lead to slight accounting errors of 1mb. Having the
58 # fs be at least 101 mb ensures those errors are within the error
59 # tolerance of 1%
60 _scratch_mkfs_sized `expr 101 \* 1024 \* 1024` >/dev/null 2>&1 \
61     || _fail "mkfs failed"
62 _scratch_mount
63 out=$SCRATCH_MNT/fillup.$$
64 rm -f $seqres.full
65
66 free0=`_free`
67 if [ -z "$free0" ]
68 then
69     echo "   *** failed to get free space (0)"
70     exit 1
71 fi
72 echo "free space at start $free0" >> $seqres.full
73
74 echo "fill disk:"       # well, filesystem really - not disk
75
76 POSIXLY_CORRECT=yes dd if=/dev/zero of=$out bs=1024k 2>&1 | _filter_dd
77
78 echo "check free space:"
79
80 free1=`_free`
81 if [ -z "$free1" ]
82 then
83     echo "   *** failed to get free space (1)"
84     exit 1
85 fi
86 echo "free space after fill $free1" >> $seqres.full
87
88 if [ ! -e $out ]
89 then
90     echo "   *** file not created"
91     exit 1
92 fi
93
94 if [ ! -s $out ]
95 then
96     echo "   *** file created with zero length"
97     ls -l $out
98     exit 1
99 fi
100
101 echo "delete fill:"
102
103 if ! rm $out
104 then
105     echo "   *** file not deleted"
106     exit 1
107 fi
108
109 if [ -e $out ]
110 then
111     echo "   *** file still exists"
112     ls -l $out
113     exit 1
114 fi
115
116 echo "check free space:"
117
118 sync
119
120 free2=`_free`
121 if [ -z "$free2" ]
122 then
123     echo "   *** failed to get free space (2)"
124     exit 1
125 fi
126 echo "free space after delete $free2" >> $seqres.full
127
128 echo -n "   !!! "
129 _within_tolerance "free space" $free2 $free0 1% -v
130
131 status=0
132 exit