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"
45 _notrun "disk quotas not supported by this filesystem type: $FSTYP"
49 # SELinux adds extra xattrs which can mess up our expected output.
50 # So, mount with a context, and they won't be created
51 # nfs_t is a "liberal" context so we can use it.
52 if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
53 export SELINUX_MOUNT_OPTIONS="-o context=system_u:object_r:nfs_t:s0"
58 # checks that the XFS quota support in the kernel is enabled
59 # and that we have valid quota user tools installed.
63 src/feature -q $TEST_DEV
64 [ $? -ne 0 ] && _notrun "Installed kernel does not support XFS quota"
65 [ -n $XFS_QUOTA_PROG ] || _notrun "XFS quota user tools not installed"
69 # checks that the XFS project quota support in the kernel is enabled.
73 [ -n "$1" ] && _dev="$1" || _dev="$TEST_DEV"
75 [ $? -ne 0 ] && _notrun "Installed kernel does not support project quotas"
79 # checks for user nobody in /etc/passwd and /etc/group.
83 _cat_passwd | grep -q '^nobody'
84 [ $? -ne 0 ] && _notrun "password file does not contain user nobody."
86 _cat_group | egrep -q '^no(body|group)'
87 [ $? -ne 0 ] && _notrun "group file does not contain nobody/nogroup."
90 # create a file as a specific user (uid)
91 # takes filename, id, type (u/g/p), blocksize, blockcount
95 [ $# != 5 ] && _notrun "broken call to _file_as_id in test $seq"
99 echo PARENT: xfs_io -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full
100 $XFS_IO_PROG -r -c "chproj $2" -c "chattr +P" $parent >>$seq.full 2>&1
101 magik='$>' # (irrelevent, above set projid-inherit-on-parent)
102 elif [ $3 = u ]; then
103 magik='$>' # perlspeak for effective uid
104 elif [ $3 = g ]; then
105 magik='$)' # perlspeak for effective gid
107 _notrun "broken type in call to _file_as_id in test $seq"
110 perl <<EOF >>$seq.full 2>&1
117 print "dd if=/dev/zero of=$1 bs=$4 count=$5";
118 exec "dd if=/dev/zero of=$1 bs=$4 count=$5";
121 # for debugging the above euid change, try... [need write in cwd]
122 # exec "dd if=/dev/zero of=$1 bs=$4 count=$5 >>$seq.full 2>&1";
125 echo PARENT: xfs_io -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full
126 $XFS_IO_PROG -r -c "chproj 0" -c "chattr -P" $parent >>$seq.full 2>&1
132 _cat_passwd | grep '^nobody' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
137 _cat_group | egrep '^no(body|group)' | perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[2],$a[0] }'
142 if [ "X$projid_file" == "X" ]; then
143 projid_file=/etc/projid
145 if [ ! -f $projid_file ]; then
149 perl -ne '@a = split(/:/); END { printf "id=%d name=%s\n", $a[1],$a[0] }' \
155 umount $SCRATCH_DEV >/dev/null 2>&1
156 _scratch_mount || _fail "qmount failed"
157 chmod ugo+rwx $SCRATCH_MNT
162 # setup exactly what it is we'll be testing
164 if src/feature -u $SCRATCH_DEV
168 [ ! -f $seq.out ] && ln -s $seq.usrquota $seq.out
169 elif src/feature -g $SCRATCH_DEV
173 [ ! -f $seq.out ] && ln -s $seq.grpquota $seq.out
174 elif src/feature -p $SCRATCH_DEV
178 [ ! -f $seq.out ] && ln -s $seq.prjquota $seq.out
179 elif src/feature -U $SCRATCH_DEV
183 [ ! -f $seq.out ] && ln -s $seq.uqnoenforce $seq.out
185 elif src/feature -G $SCRATCH_DEV
189 [ ! -f $seq.out ] && ln -s $seq.gqnoenforce $seq.out
191 elif src/feature -P $SCRATCH_DEV
195 [ ! -f $seq.out ] && ln -s $seq.pqnoenforce $seq.out
198 _notrun "No quota support at mount time"
201 echo "Using output from '" `ls -l $seq.out` "'" >>$seq.full
202 echo "and using type=$type id=$id" >>$seq.full
206 # Ensures only the given quota mount option is used
210 # Replace any user defined quota options
211 # with the quota option that we want.
212 # Simplest to do this rather than delete existing ones first because
213 # of the variety of commas and spaces and multiple -o's
214 # that we'd have to cater for. Doesn't matter if we have duplicates.
215 # Use "QUOTA" string so that we don't have any substring confusion
216 # thanks to "quota" which will match with "uquota" and "gquota" etc.
217 export MOUNT_OPTIONS=`echo $MOUNT_OPTIONS \
218 | sed -e 's/uquota/QUOTA/g' \
219 -e 's/usrquota/QUOTA/g' \
220 -e 's/gquota/QUOTA/g' \
221 -e 's/grpquota/QUOTA/g' \
222 -e 's/pquota/QUOTA/g' \
223 -e 's/quota/QUOTA/g' \
224 -e 's/uqnoenforce/QUOTA/g' \
225 -e 's/gqnoenforce/QUOTA/g' \
226 -e 's/pqnoenforce/QUOTA/g' \
227 -e 's/qnoenforce/QUOTA/g' \
230 # Ensure we have the given quota option - duplicates are fine
231 export MOUNT_OPTIONS="$MOUNT_OPTIONS -o $1"
232 echo "MOUNT_OPTIONS = $MOUNT_OPTIONS" >>$seq.full
237 # Sync to get delalloc to disk
241 ext2|ext3|ext4|ext4dev|reiserfs)
243 quotaon -f -u -g $SCRATCH_MNT 2>/dev/null
248 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
250 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
251 sort >$tmp.group.orig
252 if [ $VFS_QUOTA -eq 1 ]; then
253 quotacheck -u -g $SCRATCH_MNT 2>/dev/null
255 # use XFS method to force quotacheck
256 mount -o remount,noquota $SCRATCH_DEV
257 mount -o remount,usrquota,grpquota $SCRATCH_DEV
259 repquota -u -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
260 sort >$tmp.user.checked
261 repquota -g -n $SCRATCH_MNT | grep -v "^#0" | _filter_scratch |
262 sort >$tmp.group.checked
263 if [ $VFS_QUOTA -eq 1 ]; then
264 quotaon -u -g $SCRATCH_MNT 2>/dev/null
267 echo "Comparing user usage"
268 diff $tmp.user.orig $tmp.user.checked
270 echo "Comparing group usage"
271 diff $tmp.group.orig $tmp.group.checked
275 # make sure this script returns success