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 _begin_fstest auto quick quota idmapped
15 # Import common functions.
19 # Override the default cleanup function.
23 _scratch_unmount 2>/dev/null
27 # real QA test starts here
30 cp /dev/null $seqres.full
31 chmod a+rwx $seqres.full # arbitrary users will write here
36 _require_idmapped_mounts
37 _require_test_program "idmapped-mounts/mount-idmapped"
39 _scratch_mkfs >/dev/null 2>&1
41 bsize=$(_get_file_block_size $SCRATCH_MNT)
44 bsoft=$(( 200 * $bsize ))
45 bhard=$(( 1000 * $bsize ))
49 # The actual point at which limit enforcement takes place for the
50 # hard block limit is variable depending on filesystem blocksize,
51 # and iosize. What we want to test is that the limit is enforced
52 # (ie. blksize less than limit but not unduly less - ~85% is kind)
53 # nowadays we actually get much closer to the limit before EDQUOT.
55 _filter_and_check_blks()
58 if (/^\#'$id'\s+(\d+)/ && '$enforce') {
60 $minimum = '$bhard' * 85/100;
62 if (($used < $minimum || $used > $maximum) && '$noextsz') {
63 printf(" URK %d: %d is out of range! [%d,%d]\n",
64 '$id', $used, $minimum, $maximum);
66 s/^(\#'$id'\s+)(\d+)/\1 =OK=/g;
68 ' | _filter_quota_report
73 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
74 cat $tmp.mkfs >>$seqres.full
76 # keep the blocksize and data size for dd later
81 # Figure out whether we're doing large allocations
82 # (bail out if they're so large they stuff the test up)
83 _test_inode_flag extsz-inherit $SCRATCH_MNT
85 extsize=`_test_inode_extsz $SCRATCH_MNT`
86 [ $extsize -ge 512000 ] && \
87 _notrun "Extent size hint is too large ($extsize bytes)"
91 echo "Using type=$type id=$id" >>$seqres.full
93 $XFS_QUOTA_PROG -x -c "warn -$type 65535 -d" $SCRATCH_DEV
96 echo "*** report no quota settings" | tee -a $seqres.full
97 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
98 -c "repquota -birnN -$type" $SCRATCH_DEV |
99 _filter_quota_report | LC_COLLATE=POSIX sort -ru
102 echo "*** report initial settings" | tee -a $seqres.full
103 _scratch_mount_idmapped $type $id
104 _file_as_id $SCRATCH_MNT/initme 0 $type 1024 0
105 _scratch_umount_idmapped
106 echo "ls -l $SCRATCH_MNT" >>$seqres.full
107 ls -l $SCRATCH_MNT >>$seqres.full
108 $XFS_QUOTA_PROG -D $tmp.projects -P $temp.projid -x \
109 -c "limit -$type bsoft=${bsoft} bhard=${bhard} $id" \
110 -c "limit -$type isoft=$isoft ihard=$ihard $id" \
112 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
113 -c "repquota -birnN -$type" $SCRATCH_DEV |
114 _filter_quota_report | LC_COLLATE=POSIX sort -ru
117 echo "*** push past the soft inode limit" | tee -a $seqres.full
118 _scratch_mount_idmapped $type $id
119 _file_as_id $SCRATCH_MNT/softie1 0 $type 1024 0
120 _file_as_id $SCRATCH_MNT/softie2 0 $type 1024 0
121 _file_as_id $SCRATCH_MNT/softie3 0 $type 1024 0
122 _file_as_id $SCRATCH_MNT/softie4 0 $type 1024 0
123 _scratch_umount_idmapped
125 $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" $SCRATCH_DEV
126 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
127 -c "repquota -birnN -$type" $SCRATCH_DEV |
128 _filter_quota_report | LC_COLLATE=POSIX sort -ru
131 echo "*** push past the soft block limit" | tee -a $seqres.full
132 _scratch_mount_idmapped $type $id
133 _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 300
134 _scratch_umount_idmapped
136 $XFS_QUOTA_PROG -x -c "warn -i -$type 0 $id" \
137 -c "warn -b -$type 0 $id" $SCRATCH_DEV
138 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
139 -c "repquota -birnN -$type" $SCRATCH_DEV |
140 _filter_quota_report | LC_COLLATE=POSIX sort -ru
143 # Note: for quota accounting (not enforcement), EDQUOT is not expected
144 echo "*** push past the hard inode limit (expect EDQUOT)" | tee -a $seqres.full
145 for i in 1 2 3 4 5 6 7 8 9 10 11 12
147 _scratch_mount_idmapped $type $id
148 _file_as_id $SCRATCH_MNT/hard$i 0 $type 1024 0
149 _scratch_umount_idmapped
152 $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" \
153 -c "warn -i -$type 0 $id" $SCRATCH_DEV
154 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
155 -c "repquota -birnN -$type" $SCRATCH_DEV |
156 _filter_quota_report | LC_COLLATE=POSIX sort -ru
159 # Note: for quota accounting (not enforcement), EDQUOT is not expected
160 echo "*** push past the hard block limit (expect EDQUOT)" | tee -a $seqres.full
161 _scratch_mount_idmapped $type $id
162 _file_as_id $SCRATCH_MNT/softie 0 $type $bsize 1200
163 _scratch_umount_idmapped
164 echo "ls -l $SCRATCH_MNT" >>$seqres.full
165 ls -l $SCRATCH_MNT >>$seqres.full
167 $XFS_QUOTA_PROG -x -c "warn -b -$type 0 $id" $SCRATCH_DEV
168 $XFS_QUOTA_PROG -D $tmp.projects -P $tmp.projid -x \
169 -c "repquota -birnN -$type" $SCRATCH_DEV |
170 _filter_and_check_blks | LC_COLLATE=POSIX sort -ru
178 cat >$tmp.projects <<EOF
182 cat >$tmp.projid <<EOF
187 projid_file="$tmp.projid"
190 _qmount_option "uquota"
194 _qmount_option "gquota"
197 echo "*** uqnoenforce"
198 _qmount_option "uqnoenforce"
201 echo "*** gqnoenforce"
202 _qmount_option "gqnoenforce"