2 # SPDX-License-Identifier: GPL-2.0+
4 # Copyright (c) 2021 Christian Brauner <christian.brauner@ubuntu.com>
9 # Exercises basic XFS quota functionality
10 # uquota, gquota, uqnoenforce, gqnoenforce
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
20 # get standard environment, filters and checks
28 _scratch_unmount 2>/dev/null
31 trap "_cleanup; exit \$status" 0 1 2 3 15
33 # real QA test starts here
36 cp /dev/null $seqres.full
37 chmod a+rwx $seqres.full # arbitrary users will write here
42 _require_test_program "idmapped-mounts/mount-idmapped"
44 _scratch_mkfs >/dev/null 2>&1
46 bsize=$(_get_file_block_size $SCRATCH_MNT)
49 bsoft=$(( 200 * $bsize ))
50 bhard=$(( 1000 * $bsize ))
54 # The actual point at which limit enforcement takes place for the
55 # hard block limit is variable depending on filesystem blocksize,
56 # and iosize. What we want to test is that the limit is enforced
57 # (ie. blksize less than limit but not unduly less - ~85% is kind)
58 # nowadays we actually get much closer to the limit before EDQUOT.
60 _filter_and_check_blks()
63 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
65 $minimum = '$bhard' * 85/100;
67 if (($used < $minimum || $used > $maximum) && '$noextsz') {
68 printf(" URK %d: %d is out of range! [%d,%d]\n",
69 '$id', $used, $minimum, $maximum);
71 s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
73 ' | _filter_quota_report
78 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
79 cat $tmp.mkfs >>$seqres.full
81 # keep the blocksize and data size for dd later
86 # Figure out whether we're doing large allocations
87 # (bail out if they're so large they stuff the test up)
88 _test_inode_flag extsz-inherit $SCRATCH_MNT
90 extsize=`_test_inode_extsz $SCRATCH_MNT`
91 [ $extsize -ge 512000 ] && \
92 _notrun "Extent size hint is too large ($extsize bytes)"
96 echo "Using type=$type id=$id" >>$seqres.full
98 $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
101 echo "*** report no quota settings" | tee -a $seqres.full
102 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
103 -c "repquota -birnN -$type" $SCRATCH_DEV |
104 _filter_quota_report | LC_COLLATE=POSIX sort -ru
107 echo "*** report initial settings" | tee -a $seqres.full
108 _scratch_mount_idmapped $type $id
109 _file_as_id $SCRATCH_MNT/initme 0 $type 1024 0
110 _scratch_umount_idmapped
111 echo "ls -l $SCRATCH_MNT" >>$seqres.full
112 ls -l $SCRATCH_MNT >>$seqres.full
113 $XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
114 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
115 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
117 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
118 -c "repquota -birnN -$type" $SCRATCH_DEV |
119 _filter_quota_report | LC_COLLATE=POSIX sort -ru
122 echo "*** push past the soft inode limit" | tee -a $seqres.full
123 _scratch_mount_idmapped $type $id
124 _file_as_id $SCRATCH_MNT/softie1 0 $type 1024 0
125 _file_as_id $SCRATCH_MNT/softie2 0 $type 1024 0
126 _file_as_id $SCRATCH_MNT/softie3 0 $type 1024 0
127 _file_as_id $SCRATCH_MNT/softie4 0 $type 1024 0
128 _scratch_umount_idmapped
130 $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
131 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
132 -c "repquota -birnN -$type" $SCRATCH_DEV |
133 _filter_quota_report | LC_COLLATE=POSIX sort -ru
136 echo "*** push past the soft block limit" | tee -a $seqres.full
137 _scratch_mount_idmapped $type $id
138 _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 300
139 _scratch_umount_idmapped
141 $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
142 -c "warn -b -$type 0 $id" $SCRATCH_DEV
143 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
144 -c "repquota -birnN -$type" $SCRATCH_DEV |
145 _filter_quota_report | LC_COLLATE=POSIX sort -ru
148 # Note: for quota accounting (not enforcement), EDQUOT is not expected
149 echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
150 for i in 1 2 3 4 5 6 7 8 9 10 11 12
152 _scratch_mount_idmapped $type $id
153 _file_as_id $SCRATCH_MNT/hard$i 0 $type 1024 0
154 _scratch_umount_idmapped
157 $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" \
158 -c "warn -i -$type 0 $id" $SCRATCH_DEV
159 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
160 -c "repquota -birnN -$type" $SCRATCH_DEV |
161 _filter_quota_report | LC_COLLATE=POSIX sort -ru
164 # Note: for quota accounting (not enforcement), EDQUOT is not expected
165 echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
166 _scratch_mount_idmapped $type $id
167 _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 1200
168 _scratch_umount_idmapped
169 echo "ls -l $SCRATCH_MNT" >>$seqres.full
170 ls -l $SCRATCH_MNT >>$seqres.full
172 $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
173 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
174 -c "repquota -birnN -$type" $SCRATCH_DEV |
175 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
183 cat >$tmp.projects <<EOF
187 cat >$tmp.projid <<EOF
192 projid_file="$tmp.projid"
195 _qmount_option "uquota"
199 _qmount_option "gquota"
202 echo "*** uqnoenforce"
203 _qmount_option "uqnoenforce"
206 echo "*** gqnoenforce"
207 _qmount_option "gqnoenforce"