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"
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 [ -n $XFS_QUOTA_PROG ] || _notrun "XFS quota user tools not installed"
49 # checks that the XFS project quota support in the kernel is enabled.
53 [ -n "$1" ] && _dev="$1" || _dev="$TEST_DEV"
55 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
59 # checks for user nobody in /etc/passwd and /etc/group.
63 _cat_passwd | grep -q '^nobody'
64 [ $? -ne 0 ] && _notrun "password file does not contain user nobody."
66 _cat_group | egrep -q '^no(body|group)'
67 [ $? -ne 0 ] && _notrun "group file does not contain nobody/nogroup."
70 # create a file as a specific user (uid)
71 # takes filename, id, type (u/g/p), blocksize, blockcount
75 [ $# != 5 ] && _notrun "broken call to _file_as_id in test $seq"
79 echo PARENT: xfs_io -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full
80 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full 2>&1
81 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
83 magik='$>' # perlspeak for effective uid
85 magik='$)' # perlspeak for effective gid
87 _notrun "broken type in call to _file_as_id in test $seq"
90 perl <<EOF >>$seq.full 2>&1
97 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
98 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
101 # for debugging the above euid change, try... [need write in cwd]
102 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seq.full 2>&1";
105 echo PARENT: xfs_io -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full
106 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full 2>&1
112 _cat_passwd | grep '^nobody' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
117 _cat_group | egrep '^no(body|group)' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
122 if [ "X$projid_file" == "X" ]; then
123 projid_file=/etc/projid
125 if [ ! -f $projid_file ]; then
129 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
135 umount $SCRATCH_DEV >/dev/null 2>&1
136 _scratch_mount || _fail "qmount failed"
137 chmod ugo+rwx $SCRATCH_MNT
142 # setup exactly what it is we'll be testing
144 if src/feature -u $SCRATCH_DEV
148 [ ! -f $seq.out ] && ln -s $seq.usrquota $seq.out
149 elif src/feature -g $SCRATCH_DEV
153 [ ! -f $seq.out ] && ln -s $seq.grpquota $seq.out
154 elif src/feature -p $SCRATCH_DEV
158 [ ! -f $seq.out ] && ln -s $seq.prjquota $seq.out
159 elif src/feature -U $SCRATCH_DEV
163 [ ! -f $seq.out ] && ln -s $seq.uqnoenforce $seq.out
165 elif src/feature -G $SCRATCH_DEV
169 [ ! -f $seq.out ] && ln -s $seq.gqnoenforce $seq.out
171 elif src/feature -P $SCRATCH_DEV
175 [ ! -f $seq.out ] && ln -s $seq.pqnoenforce $seq.out
178 _notrun "No quota support at mount time"
181 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
182 echo "and using type=$type id=$id" >>$seq.full
186 # Ensures only the given quota mount option is used
190 # Replace any user defined quota options
191 # with the quota option that we want.
192 # Simplest to do this rather than delete existing ones first because
193 # of the variety of commas and spaces and multiple -o's
194 # that we'd have to cater for. Doesn't matter if we have duplicates.
195 # Use "QUOTA" string so that we don't have any substring confusion
196 # thanks to "quota" which will match with "uquota" and "gquota" etc.
197 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
198 | sed -e 's/uquota/QUOTA/g' \
199 -e 's/usrquota/QUOTA/g' \
200 -e 's/gquota/QUOTA/g' \
201 -e 's/grpquota/QUOTA/g' \
202 -e 's/pquota/QUOTA/g' \
203 -e 's/quota/QUOTA/g' \
204 -e 's/uqnoenforce/QUOTA/g' \
205 -e 's/gqnoenforce/QUOTA/g' \
206 -e 's/pqnoenforce/QUOTA/g' \
207 -e 's/qnoenforce/QUOTA/g' \
210 # Ensure we have the given quota option - duplicates are fine
211 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
212 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seq.full
217 # Sync to get delalloc to disk
220 if [ $FSTYP = "ext2" -o $FSTYP = "ext3" -o $FSTYP = "ext4" -o $FSTYP = "reiserfs" ]; then
222 quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
224 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
226 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
227 sort >$tmp.group.orig
228 if [ $VFS_QUOTA -eq 1 ]; then
229 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
231 # use XFS method to force quotacheck
232 mount -o remount,noquota $SCRATCH_DEV
233 mount -o remount,usrquota,grpquota $SCRATCH_DEV
235 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
236 sort >$tmp.user.checked
237 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
238 sort >$tmp.group.checked
239 if [ $VFS_QUOTA -eq 1 ]; then
240 quotaon -u -g $SCRATCH_MNT 2>/dev/null
243 echo "Comparing user usage"
244 diff $tmp.user.orig $tmp.user.checked
246 echo "Comparing group usage"
247 diff $tmp.group.orig $tmp.group.checked
251 # make sure this script returns success