xfs/419: remove irrelevant swapfile test
[xfstests-dev.git] / tests / xfs / 106
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2005 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 106
6 #
7 # Exercise basic xfs_quota functionality (user/group/project quota)
8 # Use of "sync" mount option here is an attempt to get deterministic
9 # allocator behaviour.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/quota
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35 _supported_fs xfs
36 _require_scratch
37 _require_xfs_quota
38 _require_user
39 _require_group
40
41 _scratch_mkfs_xfs >>$seqres.full 2>&1
42
43 uqid=`id -u fsgqa`
44 gqid=`id -g fsgqa`
45 pqid=10
46 cat >$tmp.projects <<EOF
47 $pqid:$SCRATCH_MNT
48 EOF
49
50 cat >$tmp.projid <<EOF
51 root:0
52 fsgqa:$pqid
53 EOF
54
55 create_files()
56 {
57         local bs=$1
58         local inum=$2
59
60         echo "Using type=$type id=$id" >> $seqres.full
61
62         for ((i=0; i<$((inum-1)); i++)); do
63                 _file_as_id $SCRATCH_MNT/inode$i $id $type 1024 0
64         done
65
66         _file_as_id $SCRATCH_MNT/block $id $type $bs 1
67 }
68
69 clean_files()
70 {
71         rm -rf $SCRATCH_MNT/* 2>/dev/null
72         rm -rf $tmp.quot 2>/dev/null
73         rm -rf $tmp.quota 2>/dev/null
74 }
75
76 filter_quot()
77 {
78         _filter_quota | grep -v "root \|\#0 " \
79                 | sed -e '/#[0-9]*/s/#[0-9]*/#ID/g'
80 }
81
82 filter_report()
83 {
84         _filter_quota | grep -v "^root \|^\#0 " \
85                 | sed -e '/^#[0-9]*/s/^#[0-9]*/#ID/g'
86 }
87
88 filter_quota()
89 {
90         _filter_quota | sed -e "/Disk quotas for/s/([0-9]*)/(ID)/g" \
91                             -e "/Disk quotas for/s/#[0-9]*/#ID/g"
92 }
93
94 filter_state()
95 {
96         _filter_quota | sed -e "s/Inode: #[0-9]* (0 blocks, 0 extents)/Inode: #[INO] (0 blocks, 0 extents)/g" \
97                             -e "s/Inode: #[0-9]* ([0-9]* blocks, [0-9]* extents)/Inode: #[INO] (X blocks, Y extents)/g" \
98                             -e "/[0-9][0-9]:[0-9][0-9]:[0-9][0-9]/s/ [0-9][0-9]:[0-9][0-9]:[0-9][0-9]//g" \
99                             -e '/max warnings:/d'
100 }
101
102 test_quot()
103 {
104         local opt="$*"
105
106         echo "checking quot command (type=$type)"
107         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
108                         -c "quot -$type $opt -bi" $SCRATCH_MNT | filter_quot
109 }
110
111 test_report()
112 {
113         local opt="$*"
114
115         echo "checking report command (type=$type)"
116         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
117                         -c "report -$type $opt -bi" \
118                         $SCRATCH_MNT | filter_report
119 }
120
121 test_quota()
122 {
123         local opt="$*"
124
125         echo "checking quota command (type=$type)"
126         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
127                         -c "quota -$type $opt -bi $id" \
128                         $SCRATCH_MNT | filter_quota
129 }
130
131 test_limit()
132 {
133         local bs=$1
134         local bh=$2
135         local is=$3
136         local ih=$4
137
138         echo "checking limit command (type=$type, bsoft=$bs, bhard=$bh, isoft=$is, ihard=$ih)"
139         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
140                         -c "limit -$type bsoft=$bs bhard=$bh fsgqa" \
141                         -c "limit -$type isoft=$is ihard=$ih fsgqa" \
142                         $SCRATCH_MNT
143
144         # let the timer day transition happen
145         sleep 2
146 }
147
148 test_timer()
149 {
150         echo "checking timer command (type=$type)"
151         # set 3days+1h for time won't become 2days soon
152         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
153                         -c "timer -$type -bi 73h" \
154                         $SCRATCH_MNT | _filter_scratch
155 }
156
157 test_disable()
158 {
159         echo "checking disable command (type=$type)"
160         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
161                         -c "disable -$type -v" \
162                         $SCRATCH_MNT | filter_state
163 }
164
165 test_enable()
166 {
167         echo "checking enable command (type=$type)"
168         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
169                         -c "enable -$type -v" $SCRATCH_MNT | filter_state
170 }
171
172 test_off()
173 {
174         echo "checking off command (type=$type)"
175         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
176                         -c "off -$type -v" $SCRATCH_MNT | _filter_scratch
177 }
178
179 test_remove()
180 {
181         echo "checking remove command (type=$type)"
182         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
183                         -c "remove -$type -v" \
184                         $SCRATCH_MNT | _filter_scratch
185 }
186
187 test_state()
188 {
189         echo "checking state command (type=$type)"
190         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
191                         -c "state -$type" $SCRATCH_MNT | filter_state
192 }
193
194 test_dump()
195 {
196         echo "checking dump command (type=$type)"
197         rm -f $tmp.backup 2>>/dev/null
198         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
199                         -c "dump -$type -f $tmp.backup" \
200                         $SCRATCH_MNT | _filter_scratch
201 }
202
203 test_restore()
204 {
205         echo "checking restore command (type=$type)"
206         $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
207                         -c "restore -$type -f $tmp.backup" \
208                         $SCRATCH_MNT | _filter_scratch
209 }
210
211 test_xfs_quota()
212 {
213         # init quota
214         echo "init quota limit and timer, and dump it"
215         echo "create_files 1024k 15"; create_files 1024k 15
216         echo "quota remount"; _qmount
217         echo ; test_quot
218         echo ; test_timer
219         echo ; test_limit 512k 2048k 10 20
220         echo ; test_dump
221
222         # report options test
223         echo "report options test"
224         echo ; test_report
225         echo "-N option"; test_report -N
226         echo "-L -U options"; test_report -L $id -U $id
227         echo "-t option"; test_report -t
228         echo "-n option"; test_report -n
229         echo "-h option"; test_report -h
230
231         # quot options test
232         echo "quot options test"
233         echo ; test_quot
234         echo "-f option"; test_quot -f $tmp.quot
235         cat $tmp.quot | filter_quot
236         echo "-n option"; test_quot -n
237
238         # quota options test
239         echo ; test_quota
240         echo "-f option"; test_quota -f $tmp.quota
241         cat $tmp.quota | filter_quota
242         echo "-N option"; test_quota -N
243         echo "-n option"; test_quota -n
244         echo "-h option"; test_quota -h
245
246         # disable/enable test
247         echo "disable quota"
248         echo ; test_disable
249         echo ; test_report -N
250         echo "expect a remove error at here"; test_remove
251         echo ; test_enable
252         echo ; test_report -N
253
254         # off and remove test
255         echo "off and remove test"
256         echo ; test_limit 100m 100m 100 100
257         echo ; test_quota -N
258         echo ; test_off
259         echo ; test_state
260         echo ; test_remove
261         echo ; test_report -N
262         echo "quota remount"; _qmount
263         echo ; test_report -N
264
265         # restore test
266         echo "restore quota"
267         echo ; test_restore
268         echo ; test_report -N
269         echo ; test_state
270         echo "cleanup files"; clean_files
271 }
272
273 echo "----------------------- uquota,sync ---------------------------"
274 _qmount_option "uquota,sync"
275 _qmount
276 type=u
277 id=$uqid
278 test_xfs_quota
279
280 echo "----------------------- gquota,sync ---------------------------"
281 _qmount_option "gquota,sync"
282 _qmount
283 type=g
284 id=$gqid
285 test_xfs_quota
286
287 echo "----------------------- pquota,sync ---------------------------"
288 # Need to clean the group quota before test project quota, because
289 # V4 xfs doesn't support separate project inode. So mkfs at here.
290 _scratch_unmount
291 _scratch_mkfs_xfs >>$seqres.full 2>&1
292 _qmount_option "pquota,sync"
293 _qmount
294 type=p
295 id=$pqid
296 _require_prjquota $SCRATCH_DEV
297 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
298                 -c "project -s $id" \
299                 $SCRATCH_MNT > /dev/null
300 test_xfs_quota
301
302 _scratch_unmount
303 # success, all done
304 status=0
305 exit