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|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"
45 _notrun "disk quotas not supported by this filesystem type: $FSTYP"
51 # checks that the XFS quota support in the kernel is enabled
52 # and that we have valid quota user tools installed.
56 src/feature -q $TEST_DEV
57 [ $? -ne 0 ] && _notrun "Installed kernel does not support XFS quota"
58 [ -n $XFS_QUOTA_PROG ] || _notrun "XFS quota user tools not installed"
62 # checks that the XFS project quota support in the kernel is enabled.
66 [ -n "$1" ] && _dev="$1" || _dev="$TEST_DEV"
68 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
72 # checks for user nobody in /etc/passwd and /etc/group.
76 _cat_passwd | grep -q '^nobody'
77 [ $? -ne 0 ] && _notrun "password file does not contain user nobody."
79 _cat_group | egrep -q '^no(body|group)'
80 [ $? -ne 0 ] && _notrun "group file does not contain nobody/nogroup."
83 # create a file as a specific user (uid)
84 # takes filename, id, type (u/g/p), blocksize, blockcount
88 [ $# != 5 ] && _notrun "broken call to _file_as_id in test $seq"
92 echo PARENT: xfs_io -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full
93 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full 2>&1
94 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
96 magik='$>' # perlspeak for effective uid
98 magik='$)' # perlspeak for effective gid
100 _notrun "broken type in call to _file_as_id in test $seq"
103 perl <<EOF >>$seq.full 2>&1
110 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
111 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
114 # for debugging the above euid change, try... [need write in cwd]
115 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seq.full 2>&1";
118 echo PARENT: xfs_io -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full
119 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full 2>&1
125 _cat_passwd | grep '^nobody' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
130 _cat_group | egrep '^no(body|group)' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
135 if [ "X$projid_file" == "X" ]; then
136 projid_file=/etc/projid
138 if [ ! -f $projid_file ]; then
142 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
148 umount $SCRATCH_DEV >/dev/null 2>&1
149 _scratch_mount || _fail "qmount failed"
150 chmod ugo+rwx $SCRATCH_MNT
155 # setup exactly what it is we'll be testing
157 if src/feature -u $SCRATCH_DEV
161 [ ! -f $seq.out ] && ln -s $seq.usrquota $seq.out
162 elif src/feature -g $SCRATCH_DEV
166 [ ! -f $seq.out ] && ln -s $seq.grpquota $seq.out
167 elif src/feature -p $SCRATCH_DEV
171 [ ! -f $seq.out ] && ln -s $seq.prjquota $seq.out
172 elif src/feature -U $SCRATCH_DEV
176 [ ! -f $seq.out ] && ln -s $seq.uqnoenforce $seq.out
178 elif src/feature -G $SCRATCH_DEV
182 [ ! -f $seq.out ] && ln -s $seq.gqnoenforce $seq.out
184 elif src/feature -P $SCRATCH_DEV
188 [ ! -f $seq.out ] && ln -s $seq.pqnoenforce $seq.out
191 _notrun "No quota support at mount time"
194 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
195 echo "and using type=$type id=$id" >>$seq.full
199 # Ensures only the given quota mount option is used
203 # Replace any user defined quota options
204 # with the quota option that we want.
205 # Simplest to do this rather than delete existing ones first because
206 # of the variety of commas and spaces and multiple -o's
207 # that we'd have to cater for. Doesn't matter if we have duplicates.
208 # Use "QUOTA" string so that we don't have any substring confusion
209 # thanks to "quota" which will match with "uquota" and "gquota" etc.
210 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
211 | sed -e 's/uquota/QUOTA/g' \
212 -e 's/usrquota/QUOTA/g' \
213 -e 's/gquota/QUOTA/g' \
214 -e 's/grpquota/QUOTA/g' \
215 -e 's/pquota/QUOTA/g' \
216 -e 's/quota/QUOTA/g' \
217 -e 's/uqnoenforce/QUOTA/g' \
218 -e 's/gqnoenforce/QUOTA/g' \
219 -e 's/pqnoenforce/QUOTA/g' \
220 -e 's/qnoenforce/QUOTA/g' \
223 # Ensure we have the given quota option - duplicates are fine
224 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
225 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seq.full
230 # Sync to get delalloc to disk
233 if [ $FSTYP = "ext2" -o $FSTYP = "ext3" -o $FSTYP = "ext4" -o $FSTYP = "reiserfs" ]; then
235 quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
237 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
239 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
240 sort >$tmp.group.orig
241 if [ $VFS_QUOTA -eq 1 ]; then
242 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
244 # use XFS method to force quotacheck
245 mount -o remount,noquota $SCRATCH_DEV
246 mount -o remount,usrquota,grpquota $SCRATCH_DEV
248 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
249 sort >$tmp.user.checked
250 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | filter_scratch |
251 sort >$tmp.group.checked
252 if [ $VFS_QUOTA -eq 1 ]; then
253 quotaon -u -g $SCRATCH_MNT 2>/dev/null
256 echo "Comparing user usage"
257 diff $tmp.user.orig $tmp.user.checked
259 echo "Comparing group usage"
260 diff $tmp.group.orig $tmp.group.checked
264 # make sure this script returns success