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