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_idmapped_mounts
43 _require_test_program "idmapped-mounts/mount-idmapped"
45 _scratch_mkfs >/dev/null 2>&1
47 bsize=$(_get_file_block_size $SCRATCH_MNT)
50 bsoft=$(( 200 * $bsize ))
51 bhard=$(( 1000 * $bsize ))
55 # The actual point at which limit enforcement takes place for the
56 # hard block limit is variable depending on filesystem blocksize,
57 # and iosize. What we want to test is that the limit is enforced
58 # (ie. blksize less than limit but not unduly less - ~85% is kind)
59 # nowadays we actually get much closer to the limit before EDQUOT.
61 _filter_and_check_blks()
64 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
66 $minimum = '$bhard' * 85/100;
68 if (($used < $minimum || $used > $maximum) && '$noextsz') {
69 printf(" URK %d: %d is out of range! [%d,%d]\n",
70 '$id', $used, $minimum, $maximum);
72 s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
74 ' | _filter_quota_report
79 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
80 cat $tmp.mkfs >>$seqres.full
82 # keep the blocksize and data size for dd later
87 # Figure out whether we're doing large allocations
88 # (bail out if they're so large they stuff the test up)
89 _test_inode_flag extsz-inherit $SCRATCH_MNT
91 extsize=`_test_inode_extsz $SCRATCH_MNT`
92 [ $extsize -ge 512000 ] && \
93 _notrun "Extent size hint is too large ($extsize bytes)"
97 echo "Using type=$type id=$id" >>$seqres.full
99 $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
102 echo "*** report no quota settings" | tee -a $seqres.full
103 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
104 -c "repquota -birnN -$type" $SCRATCH_DEV |
105 _filter_quota_report | LC_COLLATE=POSIX sort -ru
108 echo "*** report initial settings" | tee -a $seqres.full
109 _scratch_mount_idmapped $type $id
110 _file_as_id $SCRATCH_MNT/initme 0 $type 1024 0
111 _scratch_umount_idmapped
112 echo "ls -l $SCRATCH_MNT" >>$seqres.full
113 ls -l $SCRATCH_MNT >>$seqres.full
114 $XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
115 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
116 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
118 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
119 -c "repquota -birnN -$type" $SCRATCH_DEV |
120 _filter_quota_report | LC_COLLATE=POSIX sort -ru
123 echo "*** push past the soft inode limit" | tee -a $seqres.full
124 _scratch_mount_idmapped $type $id
125 _file_as_id $SCRATCH_MNT/softie1 0 $type 1024 0
126 _file_as_id $SCRATCH_MNT/softie2 0 $type 1024 0
127 _file_as_id $SCRATCH_MNT/softie3 0 $type 1024 0
128 _file_as_id $SCRATCH_MNT/softie4 0 $type 1024 0
129 _scratch_umount_idmapped
131 $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
132 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
133 -c "repquota -birnN -$type" $SCRATCH_DEV |
134 _filter_quota_report | LC_COLLATE=POSIX sort -ru
137 echo "*** push past the soft block limit" | tee -a $seqres.full
138 _scratch_mount_idmapped $type $id
139 _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 300
140 _scratch_umount_idmapped
142 $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
143 -c "warn -b -$type 0 $id" $SCRATCH_DEV
144 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
145 -c "repquota -birnN -$type" $SCRATCH_DEV |
146 _filter_quota_report | LC_COLLATE=POSIX sort -ru
149 # Note: for quota accounting (not enforcement), EDQUOT is not expected
150 echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
151 for i in 1 2 3 4 5 6 7 8 9 10 11 12
153 _scratch_mount_idmapped $type $id
154 _file_as_id $SCRATCH_MNT/hard$i 0 $type 1024 0
155 _scratch_umount_idmapped
158 $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" \
159 -c "warn -i -$type 0 $id" $SCRATCH_DEV
160 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
161 -c "repquota -birnN -$type" $SCRATCH_DEV |
162 _filter_quota_report | LC_COLLATE=POSIX sort -ru
165 # Note: for quota accounting (not enforcement), EDQUOT is not expected
166 echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
167 _scratch_mount_idmapped $type $id
168 _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 1200
169 _scratch_umount_idmapped
170 echo "ls -l $SCRATCH_MNT" >>$seqres.full
171 ls -l $SCRATCH_MNT >>$seqres.full
173 $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
174 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
175 -c "repquota -birnN -$type" $SCRATCH_DEV |
176 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
184 cat >$tmp.projects <<EOF
188 cat >$tmp.projid <<EOF
193 projid_file="$tmp.projid"
196 _qmount_option "uquota"
200 _qmount_option "gquota"
203 echo "*** uqnoenforce"
204 _qmount_option "uqnoenforce"
207 echo "*** gqnoenforce"
208 _qmount_option "gqnoenforce"