2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2005 Silicon Graphics, Inc. All Rights Reserved.
7 # Exercise basic xfs_quota functionality (user/group/project quota)
8 # Use of "sync" mount option here is an attempt to get deterministic
12 _begin_fstest auto quick quota
14 # Import common functions.
18 # real QA test starts here
25 _scratch_mkfs_xfs >>$seqres.full 2>&1
30 cat >$tmp.projects <<EOF
34 cat >$tmp.projid <<EOF
44 echo "Using type=$type id=$id" >> $seqres.full
46 for ((i=0; i<$((inum-1)); i++)); do
47 _file_as_id $SCRATCH_MNT/inode$i $id $type 1024 0
50 _file_as_id $SCRATCH_MNT/block $id $type $bs 1
55 rm -rf $SCRATCH_MNT/* 2>/dev/null
56 rm -rf $tmp.quot 2>/dev/null
57 rm -rf $tmp.quota 2>/dev/null
62 _filter_quota | grep -v "root \|\#0 " \
63 | sed -e '/#[0-9]*/s/#[0-9]*/#ID/g'
68 _filter_quota | grep -v "^root \|^\#0 " \
69 | sed -e '/^#[0-9]*/s/^#[0-9]*/#ID/g'
74 _filter_quota | sed -e "/Disk quotas for/s/([0-9]*)/(ID)/g" \
75 -e "/Disk quotas for/s/#[0-9]*/#ID/g"
80 _filter_quota | sed -e "s/Inode: #[0-9]* (0 blocks, 0 extents)/Inode: #[INO] (0 blocks, 0 extents)/g" \
81 -e "s/Inode: #[0-9]* ([0-9]* blocks, [0-9]* extents)/Inode: #[INO] (X blocks, Y extents)/g" \
82 -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" \
90 echo "checking quot command (type=$type)"
91 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
92 -c "quot -$type $opt -bi" $SCRATCH_MNT | filter_quot
99 echo "checking report command (type=$type)"
100 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
101 -c "report -$type $opt -bi" \
102 $SCRATCH_MNT | filter_report
109 echo "checking quota command (type=$type)"
110 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
111 -c "quota -$type $opt -bi $id" \
112 $SCRATCH_MNT | filter_quota
122 echo "checking limit command (type=$type, bsoft=$bs, bhard=$bh, isoft=$is, ihard=$ih)"
123 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
124 -c "limit -$type bsoft=$bs bhard=$bh fsgqa" \
125 -c "limit -$type isoft=$is ihard=$ih fsgqa" \
128 # let the timer day transition happen
134 echo "checking timer command (type=$type)"
135 # set 3days+1h for time won't become 2days soon
136 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
137 -c "timer -$type -bi 73h" \
138 $SCRATCH_MNT | _filter_scratch
143 echo "checking disable command (type=$type)"
144 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
145 -c "disable -$type -v" \
146 $SCRATCH_MNT | filter_state
151 echo "checking enable command (type=$type)"
152 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
153 -c "enable -$type -v" $SCRATCH_MNT | filter_state
158 echo "turning quota off by remounting"
166 echo "checking remove command (type=$type)"
167 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
168 -c "remove -$type -v" \
169 $SCRATCH_MNT | _filter_scratch
174 echo "checking state command (type=$type)"
175 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
176 -c "state -$type" $SCRATCH_MNT | filter_state
181 echo "checking dump command (type=$type)"
182 rm -f $tmp.backup 2>>/dev/null
183 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
184 -c "dump -$type -f $tmp.backup" \
185 $SCRATCH_MNT | _filter_scratch
190 echo "checking restore command (type=$type)"
191 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
192 -c "restore -$type -f $tmp.backup" \
193 $SCRATCH_MNT | _filter_scratch
201 if [ $type == "p" ]; then
202 _require_prjquota $SCRATCH_DEV
203 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
204 -c "project -s $id" $SCRATCH_MNT > /dev/null
208 echo "init quota limit and timer, and dump it"
209 echo "create_files 1024k 15"; create_files 1024k 15
210 echo "quota remount"; _qmount
213 echo ; test_limit 512k 2048k 10 20
216 # report options test
217 echo "report options test"
219 echo "-N option"; test_report -N
220 echo "-L -U options"; test_report -L $id -U $id
221 echo "-t option"; test_report -t
222 echo "-n option"; test_report -n
223 echo "-h option"; test_report -h
226 echo "quot options test"
228 echo "-f option"; test_quot -f $tmp.quot
229 cat $tmp.quot | filter_quot
230 echo "-n option"; test_quot -n
234 echo "-f option"; test_quota -f $tmp.quota
235 cat $tmp.quota | filter_quota
236 echo "-N option"; test_quota -N
237 echo "-n option"; test_quota -n
238 echo "-h option"; test_quota -h
240 # disable/enable test
243 echo ; test_report -N
244 echo "expect a remove error at here"; test_remove
246 echo ; test_report -N
248 # off and remove test
249 echo "disable and remove test"
250 echo ; test_limit 100m 100m 100 100
256 echo ; test_report -N
259 echo "quota remount";
262 echo ; test_report -N
267 echo ; test_report -N
269 echo "cleanup files"; clean_files
272 echo "----------------------- uquota,sync ---------------------------"
275 test_xfs_quota "uquota,sync"
277 echo "----------------------- gquota,sync ---------------------------"
280 test_xfs_quota "gquota,sync"
282 echo "----------------------- pquota,sync ---------------------------"
283 # Need to clean the group quota before test project quota, because
284 # V4 xfs doesn't support separate project inode. So mkfs at here.
286 _scratch_mkfs_xfs >>$seqres.full 2>&1
289 test_xfs_quota "pquota,sync"