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 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
24 umount "${SCRATCH_MNT}/idmapped" >/dev/null 2>&1
25 _scratch_unmount >/dev/null 2>&1
35 # get standard environment, filters and checks
40 # remove previous $seqres.full before test
43 # real QA test starts here
45 _require_idmapped_mounts
46 _require_test_program "idmapped-mounts/mount-idmapped"
54 _scratch_mkfs_xfs >>$seqres.full 2>&1
63 cat >$tmp.projects <<EOF
67 cat >$tmp.projid <<EOF
72 create_files_unmapped()
77 echo "Using type=$type id=$id" >> $seqres.full
79 for ((i=0; i<$((inum-1)); i++)); do
80 _file_as_id $SCRATCH_MNT/unmapped/inode$i $id $type 1024 0
83 _file_as_id $SCRATCH_MNT/unmapped/block $id $type $bs 1
86 create_files_idmapped()
91 echo "Using type=$type id=$id2" >> $seqres.full
93 for ((i=0; i<$((inum-1)); i++)); do
94 _file_as_id $SCRATCH_MNT/idmapped/inode$i $id2 $type 1024 0
97 _file_as_id $SCRATCH_MNT/idmapped/block $id2 $type $bs 1
102 rm -rf $SCRATCH_MNT/unmapped 2>/dev/null
103 rm -rf $SCRATCH_MNT/idmapped 2>/dev/null
104 rm -rf $tmp.quot 2>/dev/null
105 rm -rf $tmp.quota 2>/dev/null
110 _filter_quota | grep -v "root \|\#0 " \
111 | sed -e '/#[0-9]*/s/#[0-9]*/#ID/g'
116 _filter_quota | grep -v "^root \|^\#0 " \
117 | sed -e '/^#[0-9]*/s/^#[0-9]*/#ID/g'
122 _filter_quota | sed -e "/Disk quotas for/s/([0-9]*)/(ID)/g" \
123 -e "/Disk quotas for/s/#[0-9]*/#ID/g"
128 _filter_quota | sed -e "s/Inode: #[0-9]* (0 blocks, 0 extents)/Inode: #[INO] (0 blocks, 0 extents)/g" \
129 -e "s/Inode: #[0-9]* ([0-9]* blocks, [0-9]* extents)/Inode: #[INO] (X blocks, Y extents)/g" \
130 -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" \
131 -e '/max warnings:/d'
138 echo "checking quot command (type=$type)"
139 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
140 -c "quot -$type $opt -bi" $SCRATCH_MNT | filter_quot
147 echo "checking report command (type=$type)"
148 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
149 -c "report -$type $opt -bi" \
150 $SCRATCH_MNT | filter_report
157 echo "checking quota command (type=$type)"
158 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
159 -c "quota -$type $opt -bi $id" \
160 $SCRATCH_MNT | filter_quota
170 echo "checking limit command (type=$type, bsoft=$bs, bhard=$bh, isoft=$is, ihard=$ih)"
171 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
172 -c "limit -$type bsoft=$bs bhard=$bh fsgqa" \
173 -c "limit -$type isoft=$is ihard=$ih fsgqa" \
176 # let the timer day transition happen
182 echo "checking timer command (type=$type)"
183 # set 3days+1h for time won't become 2days soon
184 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
185 -c "timer -$type -bi 73h" \
186 $SCRATCH_MNT | _filter_scratch
191 echo "checking disable command (type=$type)"
192 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
193 -c "disable -$type -v" \
194 $SCRATCH_MNT | filter_state
199 echo "checking enable command (type=$type)"
200 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
201 -c "enable -$type -v" $SCRATCH_MNT | filter_state
206 echo "checking off command (type=$type)"
207 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
208 -c "off -$type -v" $SCRATCH_MNT | _filter_scratch
213 echo "checking remove command (type=$type)"
214 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
215 -c "remove -$type -v" \
216 $SCRATCH_MNT | _filter_scratch
221 echo "checking state command (type=$type)"
222 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
223 -c "state -$type" $SCRATCH_MNT | filter_state
228 echo "checking dump command (type=$type)"
229 rm -f $tmp.backup 2>>/dev/null
230 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
231 -c "dump -$type -f $tmp.backup" \
232 $SCRATCH_MNT | _filter_scratch
237 echo "checking restore command (type=$type)"
238 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
239 -c "restore -$type -f $tmp.backup" \
240 $SCRATCH_MNT | _filter_scratch
246 _scratch_mkfs_xfs >>$seqres.full 2>&1
252 _try_scratch_mount || _fail "qmount failed"
254 mkdir -p "${SCRATCH_MNT}/unmapped"
255 mkdir -p "${SCRATCH_MNT}/idmapped"
257 $here/src/idmapped-mounts/mount-idmapped \
258 --map-mount b:$id:$id2:1 \
259 --map-mount b:0:0:1 \
260 "$SCRATCH_MNT/unmapped" "$SCRATCH_MNT/idmapped" || _fail "mount-idmapped failed"
262 chmod ugo+rwx $SCRATCH_MNT
263 chmod ugo+rwx $SCRATCH_MNT/unmapped
264 chmod ugo+rwx $SCRATCH_MNT/idmapped
270 echo "init quota limit and timer, and dump it"
271 if [ "$idmapped" -eq 1 ]; then
272 echo "create_files_idmapped 1024k 15"; create_files_idmapped 1024k 15
274 echo "create_files_unmapped 1024k 15"; create_files_unmapped 1024k 15
276 echo "quota remount"; qmount_idmapped
279 echo ; test_limit 512k 2048k 10 20
282 # report options test
283 echo "report options test"
285 echo "-N option"; test_report -N
286 echo "-L -U options"; test_report -L $id -U $id
287 echo "-t option"; test_report -t
288 echo "-n option"; test_report -n
289 echo "-h option"; test_report -h
292 echo "quot options test"
294 echo "-f option"; test_quot -f $tmp.quot
295 cat $tmp.quot | filter_quot
296 echo "-n option"; test_quot -n
300 echo "-f option"; test_quota -f $tmp.quota
301 cat $tmp.quota | filter_quota
302 echo "-N option"; test_quota -N
303 echo "-n option"; test_quota -n
304 echo "-h option"; test_quota -h
306 # disable/enable test
309 echo ; test_report -N
310 echo "expect a remove error at here"; test_remove
312 echo ; test_report -N
314 # off and remove test
315 echo "off and remove test"
316 echo ; test_limit 100m 100m 100 100
321 echo ; test_report -N
322 echo "quota remount"; qmount_idmapped
323 echo ; test_report -N
328 echo ; test_report -N
330 echo "cleanup files"; clean_files
333 echo "----------------------- uquota,sync,unmapped ---------------------------"
335 _qmount_option "uquota,sync"
343 echo "----------------------- uquota,sync,idmapped ---------------------------"
345 _qmount_option "uquota,sync"
353 echo "----------------------- gquota,sync,unmapped ---------------------------"
355 _qmount_option "gquota,sync"
363 echo "----------------------- gquota,sync,idmapped ---------------------------"
365 _qmount_option "gquota,sync"