2 # SPDX-License-Identifier: GPL-2.0+
4 # Copyright (c) 2021 Christian Brauner <christian.brauner@ubuntu.com>
9 # Exercise basic xfs_quota functionality (user/group/project quota)
10 # Use of "sync" mount option here is an attempt to get deterministic
11 # allocator behaviour.
14 _begin_fstest auto quick quota idmapped
18 umount "${SCRATCH_MNT}/idmapped" >/dev/null 2>&1
19 _scratch_unmount >/dev/null 2>&1
22 # Override the default cleanup function.
30 # Import common functions.
34 # real QA test starts here
36 _require_idmapped_mounts
37 _require_test_program "idmapped-mounts/mount-idmapped"
45 _scratch_mkfs_xfs >>$seqres.full 2>&1
54 cat >$tmp.projects <<EOF
58 cat >$tmp.projid <<EOF
63 create_files_unmapped()
68 echo "Using type=$type id=$id" >> $seqres.full
70 for ((i=0; i<$((inum-1)); i++)); do
71 _file_as_id $SCRATCH_MNT/unmapped/inode$i $id $type 1024 0
74 _file_as_id $SCRATCH_MNT/unmapped/block $id $type $bs 1
77 create_files_idmapped()
82 echo "Using type=$type id=$id2" >> $seqres.full
84 for ((i=0; i<$((inum-1)); i++)); do
85 _file_as_id $SCRATCH_MNT/idmapped/inode$i $id2 $type 1024 0
88 _file_as_id $SCRATCH_MNT/idmapped/block $id2 $type $bs 1
93 rm -rf $SCRATCH_MNT/unmapped 2>/dev/null
94 rm -rf $SCRATCH_MNT/idmapped 2>/dev/null
95 rm -rf $tmp.quot 2>/dev/null
96 rm -rf $tmp.quota 2>/dev/null
101 _filter_quota | grep -v "root \|\#0 " \
102 | sed -e '/#[0-9]*/s/#[0-9]*/#ID/g'
107 _filter_quota | grep -v "^root \|^\#0 " \
108 | sed -e '/^#[0-9]*/s/^#[0-9]*/#ID/g'
113 _filter_quota | sed -e "/Disk quotas for/s/([0-9]*)/(ID)/g" \
114 -e "/Disk quotas for/s/#[0-9]*/#ID/g"
119 _filter_quota | sed -e "s/Inode: #[0-9]* (0 blocks, 0 extents)/Inode: #[INO] (0 blocks, 0 extents)/g" \
120 -e "s/Inode: #[0-9]* ([0-9]* blocks, [0-9]* extents)/Inode: #[INO] (X blocks, Y extents)/g" \
121 -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" \
122 -e '/max warnings:/d'
129 echo "checking quot command (type=$type)"
130 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
131 -c "quot -$type $opt -bi" $SCRATCH_MNT | filter_quot
138 echo "checking report command (type=$type)"
139 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
140 -c "report -$type $opt -bi" \
141 $SCRATCH_MNT | filter_report
148 echo "checking quota command (type=$type)"
149 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
150 -c "quota -$type $opt -bi $id" \
151 $SCRATCH_MNT | filter_quota
161 echo "checking limit command (type=$type, bsoft=$bs, bhard=$bh, isoft=$is, ihard=$ih)"
162 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
163 -c "limit -$type bsoft=$bs bhard=$bh fsgqa" \
164 -c "limit -$type isoft=$is ihard=$ih fsgqa" \
167 # let the timer day transition happen
173 echo "checking timer command (type=$type)"
174 # set 3days+1h for time won't become 2days soon
175 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
176 -c "timer -$type -bi 73h" \
177 $SCRATCH_MNT | _filter_scratch
182 echo "checking disable command (type=$type)"
183 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
184 -c "disable -$type -v" \
185 $SCRATCH_MNT | filter_state
190 echo "checking enable command (type=$type)"
191 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
192 -c "enable -$type -v" $SCRATCH_MNT | filter_state
197 echo "checking off command (type=$type)"
205 echo "checking remove command (type=$type)"
206 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
207 -c "remove -$type -v" \
208 $SCRATCH_MNT | _filter_scratch
213 echo "checking state command (type=$type)"
214 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
215 -c "state -$type" $SCRATCH_MNT | filter_state
220 echo "checking dump command (type=$type)"
221 rm -f $tmp.backup 2>>/dev/null
222 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
223 -c "dump -$type -f $tmp.backup" \
224 $SCRATCH_MNT | _filter_scratch
229 echo "checking restore command (type=$type)"
230 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
231 -c "restore -$type -f $tmp.backup" \
232 $SCRATCH_MNT | _filter_scratch
238 _scratch_mkfs_xfs >>$seqres.full 2>&1
244 _try_scratch_mount || _fail "qmount failed"
246 mkdir -p "${SCRATCH_MNT}/unmapped"
247 mkdir -p "${SCRATCH_MNT}/idmapped"
249 $here/src/idmapped-mounts/mount-idmapped \
250 --map-mount b:$id:$id2:1 \
251 --map-mount b:0:0:1 \
252 "$SCRATCH_MNT/unmapped" "$SCRATCH_MNT/idmapped" || _fail "mount-idmapped failed"
254 chmod ugo+rwx $SCRATCH_MNT
255 chmod ugo+rwx $SCRATCH_MNT/unmapped
256 chmod ugo+rwx $SCRATCH_MNT/idmapped
261 local quota_options="$1"
264 echo "init quota limit and timer, and dump it"
265 if [ "$idmapped" -eq 1 ]; then
266 echo "create_files_idmapped 1024k 15"; create_files_idmapped 1024k 15
268 echo "create_files_unmapped 1024k 15"; create_files_unmapped 1024k 15
270 echo "quota remount"; qmount_idmapped
273 echo ; test_limit 512k 2048k 10 20
276 # report options test
277 echo "report options test"
279 echo "-N option"; test_report -N
280 echo "-L -U options"; test_report -L $id -U $id
281 echo "-t option"; test_report -t
282 echo "-n option"; test_report -n
283 echo "-h option"; test_report -h
286 echo "quot options test"
288 echo "-f option"; test_quot -f $tmp.quot
289 cat $tmp.quot | filter_quot
290 echo "-n option"; test_quot -n
294 echo "-f option"; test_quota -f $tmp.quota
295 cat $tmp.quota | filter_quota
296 echo "-N option"; test_quota -N
297 echo "-n option"; test_quota -n
298 echo "-h option"; test_quota -h
300 # disable/enable test
303 echo ; test_report -N
304 echo "expect a remove error at here"; test_remove
306 echo ; test_report -N
308 # off and remove test
309 echo "off and remove test"
310 echo ; test_limit 100m 100m 100 100
315 echo ; test_report -N
317 _qmount_option "$quota_options"
320 echo ; test_report -N
325 echo ; test_report -N
327 echo "cleanup files"; clean_files
330 echo "----------------------- uquota,sync,unmapped ---------------------------"
332 _qmount_option "uquota,sync"
338 test_xfs_quota "uquota,sync"
340 echo "----------------------- uquota,sync,idmapped ---------------------------"
342 _qmount_option "uquota,sync"
348 test_xfs_quota "uquota,sync"
350 echo "----------------------- gquota,sync,unmapped ---------------------------"
352 _qmount_option "gquota,sync"
358 test_xfs_quota "gquota,sync"
360 echo "----------------------- gquota,sync,idmapped ---------------------------"
362 _qmount_option "gquota,sync"
368 test_xfs_quota "gquota,sync"