xfstests: randholes: rearrange fns and drop their declarations
[xfstests-dev.git] / 052
1 #! /bin/bash
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 gquota to test group quota,
7 # defaults to uquota 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
13 # modify it under the terms 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,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #
25 #-----------------------------------------------------------------------
26 #
27 # creator
28 owner=nathans@sgi.com
29
30 seq=`basename $0`
31 echo "QA output created by $seq"
32
33 here=`pwd`
34 tmp=/tmp/$$
35 status=1        # failure is the default!
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40 . ./common.quota
41
42 _cleanup()
43 {
44         cd /
45         umount $SCRATCH_MNT 2>/dev/null
46         rm -f $tmp.*
47 }
48 trap "_cleanup; exit \$status" 0 1 2 3 15
49
50 # real QA test starts here
51 _supported_fs xfs
52 _supported_os IRIX Linux
53
54 rm -f $seq.full
55
56 _require_scratch
57 _require_xfs_quota
58 _require_nobody
59
60 # setup a default run
61 _qmount_option uquota
62
63 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
64 cat $tmp.mkfs >>$seq.full
65 chmod a+w $seq.full     # arbitrary users will write here
66
67 # keep the blocksize from mkfs ($dbsize)
68 . $tmp.mkfs
69
70 _qmount
71
72 # setup user/group to test
73 if src/feature -U $SCRATCH_DEV ; then
74         type=u; eval `_choose_uid`
75 elif src/feature -G $SCRATCH_DEV ; then
76         type=g; eval `_choose_gid`
77 elif src/feature -P $SCRATCH_DEV ; then
78         type=p; eval `_choose_prid`
79 else
80         _notrun "No quota support at mount time"
81 fi
82
83 # create 100 (fs-blocksize) blocks
84 _file_as_id $SCRATCH_MNT/foo $id $type $dbsize 220
85 sync
86
87 # set limit at 1001 (1k) blocks
88 bsoft=1001
89 bhard=1001
90 isoft=10
91 ihard=10
92 xfs_quota -x \
93         -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
94         -c "limit -$type isoft=$isoft ihard=$ihard $id" \
95         $SCRATCH_DEV
96
97 # cross check blks, softblks, hardblks <-> quota, xfs_db
98 xfs_quota -c "quota -$type -birnN $id" $SCRATCH_DEV |
99                         tr -d '\n' | tr -s '[:space:]' | tee -a $seq.full |
100         perl -ne 'if (m[^\s*'$SCRATCH_DEV'\s+(\d+)\s+(\d+)\s+(\d+)]) {
101                 print "used_blocks=", $1, "\n";
102                 print "soft_blocks=", $2, "\n";
103                 print "hard_blocks=", $3, "\n";
104                 $next = 0;
105         }' | LC_COLLATE=POSIX sort >$tmp.quota
106
107 echo ===quota output >> $seq.full
108 cat $tmp.quota >> $seq.full
109 [ ! -s $tmp.quota ] && echo "warning: quota output file is empty"
110
111 umount $SCRATCH_MNT
112
113 # note - does (insitu) conversion from fs blocks to 1K blocks
114 xfs_db -rc "dquot -$type $id" -c p $SCRATCH_DEV | tee -a $seq.full | perl -ne '
115         if (/^diskdq.bcount = (\d+)$/) {
116                  print "used_blocks=", $1 * '$dbsize' / 1024, "\n";
117         }
118         elsif (/^diskdq.blk_hardlimit = (\d+)$/) {
119                  print "hard_blocks=", $1 * '$dbsize' / 1024, "\n";
120         }
121         elsif (/^diskdq.blk_softlimit = (\d+)$/) {
122                 print "soft_blocks=", $1 * '$dbsize' / 1024, "\n";
123         }' | LC_COLLATE=POSIX sort >$tmp.xfs_db
124
125 echo ===xfs_db output >> $seq.full
126 cat $tmp.xfs_db >> $seq.full
127 [ ! -s $tmp.xfs_db ] && echo "warning: xfs_db output file is empty"
128
129 echo Comparing out of xfs_quota and xfs_db
130 diff $tmp.quota $tmp.xfs_db
131 [ $? -eq 0 ] && echo OK.
132
133 # success, all done
134 status=0
135 exit