3 # Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation.
10 # This program is distributed in the hope that it would be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 # Functions useful for quota tests
24 # checks that the generic quota support in the kernel is enabled
25 # and that we have valid quota user tools installed.
29 [ -n "$QUOTA_PROG" ] || _notrun "Quota user tools not installed"
32 ext2|ext3|ext4|ext4dev|reiserfs)
33 if [ ! -d /proc/sys/fs/quota ]; then
34 _notrun "Installed kernel does not support quotas"
40 if [ ! -f /proc/fs/xfs/xqmstat ]; then
41 _notrun "Installed kernel does not support XFS quotas"
43 if [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ]; then
44 _notrun "Quotas not supported on realtime test device"
46 if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ]; then
47 _notrun "Quotas not supported on realtime scratch device"
51 _notrun "disk quotas not supported by this filesystem type: $FSTYP"
57 # checks that the XFS quota support in the kernel is enabled
58 # and that we have valid quota user tools installed.
62 src/feature -q $TEST_DEV
63 [ $? -ne 0 ] && _notrun "Installed kernel does not support XFS quota"
64 if [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ]; then
65 _notrun "Quotas not supported on realtime test device"
67 if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ]; then
68 _notrun "Quotas not supported on realtime scratch device"
70 [ -n "$XFS_QUOTA_PROG" ] || _notrun "XFS quota user tools not installed"
74 # checks that xfs_quota can operate on foreign (non-xfs) filesystems
75 # Skips check on xfs filesystems, old xfs_quota is fine there.
76 # Appends "-f" to enable foreign behavior on non-xfs filesystems if available.
78 _require_xfs_quota_foreign()
80 if [ "$FSTYP" != "xfs" ]; then
81 $XFS_QUOTA_PROG -f -V &>/dev/null || \
82 _notrun "xfs_quota binary does not support foreign filesystems"
83 XFS_QUOTA_PROG="$XFS_QUOTA_PROG -f"
88 # checks that the project quota support in the kernel is enabled.
92 [ -n "$1" ] && _dev="$1" || _dev="$TEST_DEV"
93 if [[ "$FSTYP" == ext[234] ]]; then
94 dumpe2fs -h $_dev 2>&1 | grep -qw project || \
95 _notrun "Project quota not available on this $FSTYP"
98 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
99 if [ "$USE_EXTERNAL" = yes -a ! -z "$_dev" ]; then
100 _notrun "Project quotas not supported on realtime filesystem"
105 # Do we have GETNEXTQUOTA? Querying ID 0 should work.
107 _require_getnextquota()
109 _require_test_program "test-nextquota"
110 $here/src/test-nextquota -i 0 -u -d $SCRATCH_DEV &> $seqres.full || \
111 _notrun "No GETNEXTQUOTA support"
115 # ext4 (for now) is unique in that we must enable the project quota feature
116 # prior to mount. This is a relatively new feature ...
117 _scratch_enable_pquota()
119 [[ "$FSTYP" != ext[234] ]] && return
121 tune2fs -O quota,project $SCRATCH_DEV >>$seqres.full 2>&1
122 _try_scratch_mount >/dev/null 2>&1 \
123 || _notrun "kernel doesn't support project feature on $FSTYP"
128 # checks for user nobody in /etc/passwd and /etc/group.
132 _cat_passwd | grep -q '^nobody'
133 [ $? -ne 0 ] && _notrun "password file does not contain user nobody."
135 _cat_group | egrep -q '^no(body|group)'
136 [ $? -ne 0 ] && _notrun "group file does not contain nobody/nogroup."
139 # create a file as a specific user (uid)
140 # takes filename, id, type (u/g/p), blocksize, blockcount
144 [ $# != 5 ] && _fail "broken call to _file_as_id in test $seq"
148 echo PARENT: $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seqres.full
149 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seqres.full 2>&1
150 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
151 elif [ $3 = u ]; then
152 magik='$>' # perlspeak for effective uid
153 elif [ $3 = g ]; then
154 magik='$)' # perlspeak for effective gid
156 _notrun "broken type in call to _file_as_id in test $seq"
159 perl <<EOF >>$seqres.full 2>&1
166 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
167 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
170 # for debugging the above euid change, try... [need write in cwd]
171 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seqres.full 2>&1";
174 echo PARENT: $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seqres.full
175 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seqres.full 2>&1
181 _cat_passwd | grep '^nobody' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
186 _cat_group | egrep '^no(body|group)' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
191 if [ "X$projid_file" == "X" ]; then
192 projid_file=/etc/projid
194 if [ ! -f $projid_file ]; then
198 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
204 _scratch_unmount >/dev/null 2>&1
205 _try_scratch_mount || _fail "qmount failed"
206 # xfs doesn't need these setups and quotacheck even fails on xfs
207 # redirect the output to $seqres.full for debug purpose and ignore results
208 if [ "$FSTYP" != "xfs" ]; then
209 quotacheck -ug $SCRATCH_MNT >>$seqres.full 2>&1
210 quotaon -ug $SCRATCH_MNT >>$seqres.full 2>&1
212 chmod ugo+rwx $SCRATCH_MNT
216 # Ensures only the given quota mount option is used
222 # Replace any user defined quota options
223 # with the quota option that we want.
224 # Simplest to do this rather than delete existing ones first because
225 # of the variety of commas and spaces and multiple -o's
226 # that we'd have to cater for. Doesn't matter if we have duplicates.
227 # Use "QUOTA" string so that we don't have any substring confusion
228 # thanks to "quota" which will match with "uquota" and "gquota" etc.
229 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
230 | sed -e 's/uquota/QUOTA/g' \
231 -e 's/usrquota/QUOTA/g' \
232 -e 's/gquota/QUOTA/g' \
233 -e 's/grpquota/QUOTA/g' \
234 -e 's/\bpquota/QUOTA/g' \
235 -e 's/prjquota/QUOTA/g' \
236 -e 's/quota/QUOTA/g' \
237 -e 's/uqnoenforce/QUOTA/g' \
238 -e 's/gqnoenforce/QUOTA/g' \
239 -e 's/pqnoenforce/QUOTA/g' \
240 -e 's/qnoenforce/QUOTA/g' \
241 -e "s/QUOTA/$OPTS/g"`
243 # ext4 doesn't _do_ "-o pquota/prjquota" because reasons
244 # Switch it to "quota" to enable mkfs-time pquota
245 if [[ "$FSTYP" == ext[234] ]]; then
247 | sed -e 's/\bpquota/quota/g' \
248 -e 's/prjquota/quota/g'`
250 # Ensure we have the given quota option - duplicates are fine
251 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $OPTS"
252 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seqres.full
257 # Sync to get delalloc to disk
260 # kill caches to guarantee removal speculative delalloc
261 # XXX: really need an ioctl instead of this big hammer
262 echo 3 > /proc/sys/vm/drop_caches
266 ext2|ext3|ext4|ext4dev|reiserfs|gfs2)
268 quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
271 # Clear out speculative preallocations to eliminate them
272 # as a source of intermittent orig/checked differences.
273 test -x "$XFS_SPACEMAN_PROG" && \
274 "$XFS_SPACEMAN_PROG" -c 'prealloc -s' $SCRATCH_MNT
279 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
281 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
282 sort >$tmp.group.orig
283 if [ $VFS_QUOTA -eq 1 ]; then
284 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
286 # use XFS method to force quotacheck
287 xfs_quota -x -c "off -ug" $SCRATCH_MNT
289 _scratch_mount "-o usrquota,grpquota"
291 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
292 sort >$tmp.user.checked
293 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
294 sort >$tmp.group.checked
295 if [ $VFS_QUOTA -eq 1 ]; then
296 quotaon -u -g $SCRATCH_MNT 2>/dev/null
299 echo "Comparing user usage"
300 diff $tmp.user.orig $tmp.user.checked
302 echo "Comparing group usage"
303 diff $tmp.group.orig $tmp.group.checked
307 # Report the block usage of root, $qa_user, and nobody
308 _report_quota_blocks() {
309 repquota $1 | egrep "^($qa_user|root|nobody)" | awk '{print $1, $3, $4, $5}'
312 # Report the inode usage of root, $qa_user, and nobody
313 _report_quota_inodes() {
314 repquota $1 | egrep "^($qa_user|root|nobody)" | awk '{print $1, $6, $7, $8}'
317 # make sure this script returns success