c5995cc5d6ab6e9cf92a2707052e81720d2ac304
[xfstests-dev.git] / tests / xfs / 144
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle.  All Rights Reserved.
4 #
5 # FS QA Test No. 144
6 #
7 # Check that quota softlimit warnings work the way they should.  This means
8 # that we can disobey the softlimit up to warnlimit times before it turns into
9 # hard(er) enforcement.  This is a functional test for quota warnings, but
10 # since the functionality has been broken for decades, this is also a
11 # regression test for commit 4b8628d57b72 ("xfs: actually bump warning counts
12 # when we send warnings").
13
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1    # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27 }
28
29 # get standard environment, filters and checks
30 . ./common/rc
31 . ./common/filter
32 . ./common/quota
33
34 # real QA test starts here
35 _supported_fs xfs
36 _require_xfs_quota
37 _require_scratch
38
39 rm -f $seqres.full
40
41 qsetup()
42 {
43         opt=$1
44         enforce=0
45         if [ $opt = "u" -o $opt = "uno" ]; then
46                 type=u
47                 eval `_choose_uid`
48         elif [ $opt = "g" -o $opt = "gno" ]; then
49                 type=g
50                 eval `_choose_gid`
51         elif [ $opt = "p" -o $opt = "pno" ]; then
52                 type=p
53                 eval `_choose_prid`
54         fi
55         [ $opt = "u" -o $opt = "g" -o $opt = "p" ] && enforce=1
56
57         echo "Using type=$type id=$id" >> $seqres.full
58 }
59
60 exercise() {
61         _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
62         cat $tmp.mkfs >>$seqres.full
63
64         # keep the blocksize and data size for dd later
65         . $tmp.mkfs
66
67         _qmount
68
69         qsetup $1
70
71         echo "Using type=$type id=$id" >>$seqres.full
72
73         echo
74         echo "*** report initial settings" | tee -a $seqres.full
75         $XFS_QUOTA_PROG -x \
76                 -c "limit -$type isoft=3 ihard=500000 $id" \
77                 -c "warn -$type -i -d 13" \
78                 $SCRATCH_DEV
79         $XFS_QUOTA_PROG -x \
80                 -c "state -$type" >> $seqres.full
81         $XFS_QUOTA_PROG -x \
82                 -c "repquota -birnN -$type" $SCRATCH_DEV |
83                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
84
85         echo
86         echo "*** push past the soft inode limit" | tee -a $seqres.full
87         _file_as_id $SCRATCH_MNT/softok1 $id $type $bsize 0
88         _file_as_id $SCRATCH_MNT/softok2 $id $type $bsize 0
89         _file_as_id $SCRATCH_MNT/softok3 $id $type $bsize 0
90         _file_as_id $SCRATCH_MNT/softwarn1 $id $type $bsize 0
91         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
92                 -c "repquota -birnN -$type" $SCRATCH_DEV |
93                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
94
95         echo
96         echo "*** push further past the soft inode limit" | tee -a $seqres.full
97         for warn_nr in $(seq 2 5); do
98                 _file_as_id $SCRATCH_MNT/softwarn$warn_nr $id $type $bsize 0
99         done
100         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
101                 -c "repquota -birnN -$type" $SCRATCH_DEV |
102                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
103
104         echo
105         echo "*** push past the soft inode warning limit" | tee -a $seqres.full
106         for warn_nr in $(seq 6 15); do
107                 _file_as_id $SCRATCH_MNT/softwarn$warn_nr $id $type $bsize 0
108         done
109         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
110                 -c "repquota -birnN -$type" $SCRATCH_DEV |
111                 _filter_quota_report | LC_COLLATE=POSIX sort -ru
112
113         echo
114         echo "*** unmount"
115         _scratch_unmount
116 }
117
118 _scratch_mkfs > $seqres.full
119 _scratch_mount >> $seqres.full
120
121 chmod a+rwx $SCRATCH_MNT $seqres.full   # arbitrary users will write here
122 bsize=$(_get_file_block_size $SCRATCH_MNT)
123 _scratch_unmount
124
125 cat >$tmp.projects <<EOF
126 1:$SCRATCH_MNT
127 EOF
128
129 cat >$tmp.projid <<EOF
130 root:0
131 scratch:1
132 EOF
133
134 projid_file="$tmp.projid"
135
136 echo "*** user"
137 _qmount_option "uquota"
138 exercise u
139
140 echo "*** group"
141 _qmount_option "gquota"
142 exercise g
143
144 echo "*** uqnoenforce"
145 _qmount_option "uqnoenforce"
146 exercise uno
147
148 echo "*** gqnoenforce"
149 _qmount_option "gqnoenforce"
150 exercise gno
151
152 echo "*** pquota"
153 _qmount_option "pquota"
154 exercise p
155
156 echo "*** pqnoenforce"
157 _qmount_option "pqnoenforce"
158 exercise pno
159
160 # success, all done
161 status=0
162 exit