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"
55 # SELinux adds extra xattrs which can mess up our expected output.
56 # So, mount with a context, and they won't be created
57 # nfs_t is a "liberal" context so we can use it.
58 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
59 export SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
64 # checks that the XFS quota support in the kernel is enabled
65 # and that we have valid quota user tools installed.
69 src/feature -q $TEST_DEV
70 [ $? -ne 0 ] && _notrun "Installed kernel does not support XFS quota"
71 if [ "$USE_EXTERNAL" = yes -a ! -z "$TEST_RTDEV" ]; then
72 _notrun "Quotas not supported on realtime test device"
74 if [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ]; then
75 _notrun "Quotas not supported on realtime scratch device"
77 [ -n "$XFS_QUOTA_PROG" ] || _notrun "XFS quota user tools not installed"
81 # checks that xfs_quota can operate on foreign (non-xfs) filesystems
82 # Skips check on xfs filesystems, old xfs_quota is fine there.
83 # Appends "-f" to enable foreign behavior on non-xfs filesystems if available.
85 _require_xfs_quota_foreign()
87 if [ "$FSTYP" != "xfs" ]; then
88 $XFS_QUOTA_PROG -f -V &>/dev/null || \
89 _notrun "xfs_quota binary does not support foreign filesystems"
90 XFS_QUOTA_PROG="$XFS_QUOTA_PROG -f"
95 # checks that the XFS project quota support in the kernel is enabled.
99 [ -n "$1" ] && _dev="$1" || _dev="$TEST_DEV"
101 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
102 if [ "$USE_EXTERNAL" = yes -a ! -z "$_dev" ]; then
103 _notrun "Project quotas not supported on realtime filesystem"
108 # checks for user nobody in /etc/passwd and /etc/group.
112 _cat_passwd | grep -q '^nobody'
113 [ $? -ne 0 ] && _notrun "password file does not contain user nobody."
115 _cat_group | egrep -q '^no(body|group)'
116 [ $? -ne 0 ] && _notrun "group file does not contain nobody/nogroup."
119 # create a file as a specific user (uid)
120 # takes filename, id, type (u/g/p), blocksize, blockcount
124 [ $# != 5 ] && _fail "broken call to _file_as_id in test $seq"
128 echo PARENT: xfs_io -r -c "chproj $2" -c "chattr +P" $parent >>$seqres.full
129 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seqres.full 2>&1
130 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
131 elif [ $3 = u ]; then
132 magik='$>' # perlspeak for effective uid
133 elif [ $3 = g ]; then
134 magik='$)' # perlspeak for effective gid
136 _notrun "broken type in call to _file_as_id in test $seq"
139 perl <<EOF >>$seqres.full 2>&1
146 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
147 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
150 # for debugging the above euid change, try... [need write in cwd]
151 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seqres.full 2>&1";
154 echo PARENT: xfs_io -r -c "chproj 0" -c "chattr -P" $parent >>$seqres.full
155 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seqres.full 2>&1
161 _cat_passwd | grep '^nobody' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
166 _cat_group | egrep '^no(body|group)' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
171 if [ "X$projid_file" == "X" ]; then
172 projid_file=/etc/projid
174 if [ ! -f $projid_file ]; then
178 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
184 _scratch_unmount >/dev/null 2>&1
185 _scratch_mount || _fail "qmount failed"
186 # xfs doesn't need these setups and quotacheck even fails on xfs
187 # redirect the output to $seqres.full for debug purpose and ignore results
188 if [ "$FSTYP" != "xfs" ]; then
189 quotacheck -ug $SCRATCH_MNT >>$seqres.full 2>&1
190 quotaon -ug $SCRATCH_MNT >>$seqres.full 2>&1
192 chmod ugo+rwx $SCRATCH_MNT
196 # Ensures only the given quota mount option is used
200 # Replace any user defined quota options
201 # with the quota option that we want.
202 # Simplest to do this rather than delete existing ones first because
203 # of the variety of commas and spaces and multiple -o's
204 # that we'd have to cater for. Doesn't matter if we have duplicates.
205 # Use "QUOTA" string so that we don't have any substring confusion
206 # thanks to "quota" which will match with "uquota" and "gquota" etc.
207 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
208 | sed -e 's/uquota/QUOTA/g' \
209 -e 's/usrquota/QUOTA/g' \
210 -e 's/gquota/QUOTA/g' \
211 -e 's/grpquota/QUOTA/g' \
212 -e 's/pquota/QUOTA/g' \
213 -e 's/prjquota/QUOTA/g' \
214 -e 's/quota/QUOTA/g' \
215 -e 's/uqnoenforce/QUOTA/g' \
216 -e 's/gqnoenforce/QUOTA/g' \
217 -e 's/pqnoenforce/QUOTA/g' \
218 -e 's/qnoenforce/QUOTA/g' \
221 # Ensure we have the given quota option - duplicates are fine
222 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
223 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seqres.full
228 # Sync to get delalloc to disk
231 # kill caches to guarantee removal speculative delalloc
232 # XXX: really need an ioctl instead of this big hammer
233 echo 3 > /proc/sys/vm/drop_caches
237 ext2|ext3|ext4|ext4dev|reiserfs|gfs2)
239 quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
244 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
246 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
247 sort >$tmp.group.orig
248 if [ $VFS_QUOTA -eq 1 ]; then
249 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
251 # use XFS method to force quotacheck
252 xfs_quota -x -c "off -ug" $SCRATCH_MNT
254 _scratch_mount "-o usrquota,grpquota"
256 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
257 sort >$tmp.user.checked
258 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
259 sort >$tmp.group.checked
260 if [ $VFS_QUOTA -eq 1 ]; then
261 quotaon -u -g $SCRATCH_MNT 2>/dev/null
264 echo "Comparing user usage"
265 diff $tmp.user.orig $tmp.user.checked
267 echo "Comparing group usage"
268 diff $tmp.group.orig $tmp.group.checked
272 # make sure this script returns success