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 [ -x /usr/bin/quota ] || _notrun "Quota user tools not installed"
30 if [ $FSTYP = "xfs" ]; then
31 [ -f /proc/fs/xfs/xqmstat ] || _notrun "Installed kernel does not support XFS quota"
32 elif [ $FSTYP != "gfs2" ]; then
33 [ -d /proc/sys/fs/quota ] || _notrun "Installed kernel does not support quota"
38 # checks that the XFS quota support in the kernel is enabled
39 # and that we have valid quota user tools installed.
43 src/feature -q $TEST_DEV
44 [ $? -ne 0 ] && _notrun "Installed kernel does not support XFS quota"
45 [ -x /usr/sbin/xfs_quota ] || _notrun "XFS quota user tools not installed"
49 # checks that the XFS project quota support in the kernel is enabled.
53 src/feature -p $TEST_DEV
54 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
58 # checks for user nobody in /etc/passwd and /etc/group.
62 grep -q '^nobody' /etc/passwd
63 [ $? -ne 0 ] && _notrun "/etc/passwd does not contain user nobody."
65 egrep -q '^no(body|group)' /etc/group
66 [ $? -ne 0 ] && _notrun "/etc/group does not contain nobody/nogroup."
69 # create a file as a specific user (uid)
70 # takes filename, id, type (u/g/p), blocksize, blockcount
74 [ $# != 5 ] && _notrun "broken call to _file_as_id in test $seq"
78 echo PARENT: xfs_io -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full
79 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full 2>&1
80 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
82 magik='$>' # perlspeak for effective uid
84 magik='$)' # perlspeak for effective gid
86 _notrun "broken type in call to _file_as_id in test $seq"
89 perl <<EOF >>$seq.full 2>&1
96 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
97 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
100 # for debugging the above euid change, try... [need write in cwd]
101 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seq.full 2>&1";
104 echo PARENT: xfs_io -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full
105 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full 2>&1
111 grep '^nobody' /etc/passwd | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
116 egrep '^no(body|group)' /etc/group | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
121 if [ "X$projid_file" == "X" ]; then
122 projid_file=/etc/projid
124 if [ ! -f $projid_file ]; then
128 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
134 umount $SCRATCH_DEV >/dev/null 2>&1
135 _scratch_mount || _fail "qmount failed"
136 chmod ugo+rwx $SCRATCH_MNT
141 # setup exactly what it is we'll be testing
143 if src/feature -u $SCRATCH_DEV
147 [ ! -f $seq.out ] && ln -s $seq.usrquota $seq.out
148 elif src/feature -g $SCRATCH_DEV
152 [ ! -f $seq.out ] && ln -s $seq.grpquota $seq.out
153 elif src/feature -p $SCRATCH_DEV
157 [ ! -f $seq.out ] && ln -s $seq.prjquota $seq.out
158 elif src/feature -U $SCRATCH_DEV
162 [ ! -f $seq.out ] && ln -s $seq.uqnoenforce $seq.out
164 elif src/feature -G $SCRATCH_DEV
168 [ ! -f $seq.out ] && ln -s $seq.gqnoenforce $seq.out
170 elif src/feature -P $SCRATCH_DEV
174 [ ! -f $seq.out ] && ln -s $seq.pqnoenforce $seq.out
177 _notrun "No quota support at mount time"
180 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
181 echo "and using type=$type id=$id" >>$seq.full
185 # Ensures only the given quota mount option is used
189 # Replace any user defined quota options
190 # with the quota option that we want.
191 # Simplest to do this rather than delete existing ones first because
192 # of the variety of commas and spaces and multiple -o's
193 # that we'd have to cater for. Doesn't matter if we have duplicates.
194 # Use "QUOTA" string so that we don't have any substring confusion
195 # thanks to "quota" which will match with "uquota" and "gquota" etc.
196 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
197 | sed -e 's/uquota/QUOTA/g' \
198 -e 's/usrquota/QUOTA/g' \
199 -e 's/gquota/QUOTA/g' \
200 -e 's/grpquota/QUOTA/g' \
201 -e 's/pquota/QUOTA/g' \
202 -e 's/quota/QUOTA/g' \
203 -e 's/uqnoenforce/QUOTA/g' \
204 -e 's/gqnoenforce/QUOTA/g' \
205 -e 's/pqnoenforce/QUOTA/g' \
206 -e 's/qnoenforce/QUOTA/g' \
209 # Ensure we have the given quota option - duplicates are fine
210 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
211 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seq.full
216 # Sync to get delalloc to disk
219 if [ $FSTYP = "ext2" -o $FSTYP = "ext3" -o $FSTYP = "ext4" -o $FSTYP = "reiserfs" ]; then
221 quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
223 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
225 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
226 sort >$tmp.group.orig
227 if [ $VFS_QUOTA -eq 1 ]; then
228 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
230 # use XFS method to force quotacheck
231 mount -o remount,noquota $SCRATCH_DEV
232 mount -o remount,usrquota,grpquota $SCRATCH_DEV
234 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
235 sort >$tmp.user.checked
236 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
237 sort >$tmp.group.checked
238 if [ $VFS_QUOTA -eq 1 ]; then
239 quotaon -u -g $SCRATCH_MNT 2>/dev/null
242 echo "Comparing user usage"
243 diff $tmp.user.orig $tmp.user.checked
245 echo "Comparing group usage"
246 diff $tmp.group.orig $tmp.group.checked
250 # make sure this script returns success