update lite test config
[xfstests-dev.git] / 052
1 #! /bin/sh
2 # FS QA Test No. 052
3 #
4 # Ensure that quota(1) displays blocksizes matching ondisk dquots.
5 #
6 # MOUNT_OPTIONS can be set to grpquota to test group quota,
7 # defaults to usrquota if MOUNT_OPTIONS is not set.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
11
12 # This program is free software; you can redistribute it and/or modify it
13 # under the terms of version 2 of the GNU General Public License as
14 # published by the Free Software Foundation.
15
16 # This program is distributed in the hope that it would be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20 # Further, this software is distributed without any warranty that it is
21 # free of the rightful claim of any third person regarding infringement
22 # or the like.  Any license provided herein, whether implied or
23 # otherwise, applies only to this software file.  Patent licenses, if
24 # any, provided herein do not apply to combinations of this program with
25 # other software, or any other product whatsoever.
26
27 # You should have received a copy of the GNU General Public License along
28 # with this program; if not, write the Free Software Foundation, Inc., 59
29 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
30
31 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
32 # Mountain View, CA  94043, or:
33
34 # http://www.sgi.com 
35
36 # For further information regarding this notice, see: 
37
38 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
39 #-----------------------------------------------------------------------
40 #
41 # creator
42 owner=nathans@sgi.com
43
44 seq=`basename $0`
45 echo "QA output created by $seq"
46
47 here=`pwd`
48 tmp=/tmp/$$
49 status=1        # failure is the default!
50
51 export MOUNT_OPTIONS=-ousrquota
52
53 # get standard environment, filters and checks
54 . ./common.rc
55 . ./common.filter
56 . ./common.quota
57
58 _cleanup()
59 {
60         cd /
61         umount $SCRATCH_MNT 2>/dev/null
62         rm -f $tmp.*
63 }
64 trap "_cleanup; exit \$status" 0 1 2 3 15
65
66 # real QA test starts here
67 _supported_fs xfs
68 _supported_os IRIX Linux
69
70 rm -f $seq.full
71
72 _require_scratch
73 _require_quota
74
75 # setup a default run
76 if [ -z "$MOUNT_OPTIONS" ]; then
77         MOUNT_OPTIONS="-o usrquota"; export MOUNT_OPTIONS
78 fi
79
80 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
81 cat $tmp.mkfs >>$seq.full
82 chmod a+w $seq.full     # arbitrary users will write here
83
84 # keep the blocksize from mkfs ($dbsize)
85 . $tmp.mkfs
86
87 _qmount
88
89 # setup user/group to test
90 if src/feature -U $SCRATCH_DEV ; then
91         type=u ; eval `_choose_uid`
92 elif src/feature -G $SCRATCH_DEV ; then
93         type=g ; eval `_choose_gid`
94 else
95         _notrun "No quota support at mount time"
96 fi
97
98 # create 100 (fs-blocksize) blocks
99 _file_as_id $SCRATCH_MNT/foo $id $type $dbsize 220
100 sync
101
102 # set limit at 1001 (1k) blocks
103 setquota -$type $id 1001 1001 10 10 $SCRATCH_DEV
104
105 # cross check blks, softblks, hardblks <-> quota, xfs_db
106 quota -$type $id | tee -a $seq.full | perl -ne '
107         if (m[^\s*'$SCRATCH_DEV'\s+(\d+)\s+(\d+)\s+(\d+)] ||
108                 ($next == 1 && m,^\s+(\d+)\s+(\d+)\s+(\d+),)) {
109                 print "used_blocks=", $1, "\n";
110                 print "soft_blocks=", $2, "\n";
111                 print "hard_blocks=", $3, "\n";
112                 $next = 0;
113         }
114         elsif (m[^\s*'$SCRATCH_DEV']) {         # devfs (long) names
115                 $next = 1;
116         }' | LC_COLLATE=POSIX sort >$tmp.quota
117
118 echo ===quota output >> $seq.full
119 cat $tmp.quota >> $seq.full
120 [ ! -s $tmp.quota ] && echo "warning: quota output file is empty"
121
122 umount $SCRATCH_MNT
123
124 # note - does (insitu) conversion from fs blocks to 1K blocks
125 xfs_db -rc "dquot -$type $id" -c p $SCRATCH_DEV | tee -a $seq.full | perl -ne '
126         if (/^diskdq.bcount = (\d+)$/) {
127                  print "used_blocks=", $1 * '$dbsize' / 1024, "\n";
128         }
129         elsif (/^diskdq.blk_hardlimit = (\d+)$/) {
130                  print "hard_blocks=", $1 * '$dbsize' / 1024, "\n";
131         }
132         elsif (/^diskdq.blk_softlimit = (\d+)$/) {
133                 print "soft_blocks=", $1 * '$dbsize' / 1024, "\n";
134         }' | LC_COLLATE=POSIX sort >$tmp.xfs_db
135
136 echo ===xfs_db output >> $seq.full
137 cat $tmp.xfs_db >> $seq.full
138 [ ! -s $tmp.xfs_db ] && echo "warning: xfs_db output file is empty"
139
140 echo Comparing out of quota and xfs_db
141 diff $tmp.quota $tmp.xfs_db 
142 [ $? -eq 0 ] && echo OK.
143
144 export -n MOUNT_OPTIONS
145
146 # success, all done
147 status=0
148 exit