xfs: fix more xfs_db open-coding instances
[xfstests-dev.git] / tests / xfs / 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
28 seq=`basename $0`
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
31
32 here=`pwd`
33 tmp=/tmp/$$
34 status=1        # failure is the default!
35
36 # get standard environment, filters and checks
37 . ./common/rc
38 . ./common/filter
39 . ./common/quota
40
41 _cleanup()
42 {
43         cd /
44         _scratch_unmount 2>/dev/null
45         rm -f $tmp.*
46 }
47 trap "_cleanup; exit \$status" 0 1 2 3 15
48
49 # real QA test starts here
50 _supported_fs xfs
51 _supported_os IRIX Linux
52
53 rm -f $seqres.full
54
55 _require_scratch
56 _require_xfs_quota
57 _require_nobody
58
59 # setup a default run
60 _qmount_option uquota
61
62 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
63 cat $tmp.mkfs >>$seqres.full
64 chmod a+w $seqres.full     # arbitrary users will write here
65
66 # keep the blocksize from mkfs ($dbsize)
67 . $tmp.mkfs
68
69 _qmount
70
71 # setup user/group to test
72 if src/feature -U $SCRATCH_DEV ; then
73         type=u; eval `_choose_uid`
74 elif src/feature -G $SCRATCH_DEV ; then
75         type=g; eval `_choose_gid`
76 elif src/feature -P $SCRATCH_DEV ; then
77         type=p; eval `_choose_prid`
78 else
79         _notrun "No quota support at mount time"
80 fi
81
82 # create 100 (fs-blocksize) blocks
83 _file_as_id $SCRATCH_MNT/foo $id $type $dbsize 220
84 sync
85
86 # set limit at 1001 (1k) blocks
87 bsoft=1001
88 bhard=1001
89 isoft=10
90 ihard=10
91 xfs_quota -x \
92         -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
93         -c "limit -$type isoft=$isoft ihard=$ihard $id" \
94         $SCRATCH_DEV
95
96 # cross check blks, softblks, hardblks <-> quota, xfs_db
97 xfs_quota -c "quota -$type -birnN $id" $SCRATCH_DEV |
98                         tr -d '\n' | tr -s '[:space:]' | tee -a $seqres.full |
99         perl -ne 'if (m[^\s*'$SCRATCH_DEV'\s+(\d+)\s+(\d+)\s+(\d+)]) {
100                 print "used_blocks=", $1, "\n";
101                 print "soft_blocks=", $2, "\n";
102                 print "hard_blocks=", $3, "\n";
103                 $next = 0;
104         }' | LC_COLLATE=POSIX sort >$tmp.quota
105
106 echo ===quota output >> $seqres.full
107 cat $tmp.quota >> $seqres.full
108 [ ! -s $tmp.quota ] && echo "warning: quota output file is empty"
109
110 _scratch_unmount
111
112 # note - does (insitu) conversion from fs blocks to 1K blocks
113 _scratch_xfs_db -rc "dquot -$type $id" -c p  | tee -a $seqres.full | perl -ne '
114         if (/^diskdq.bcount = (\d+)$/) {
115                  print "used_blocks=", $1 * '$dbsize' / 1024, "\n";
116         }
117         elsif (/^diskdq.blk_hardlimit = (\d+)$/) {
118                  print "hard_blocks=", $1 * '$dbsize' / 1024, "\n";
119         }
120         elsif (/^diskdq.blk_softlimit = (\d+)$/) {
121                 print "soft_blocks=", $1 * '$dbsize' / 1024, "\n";
122         }' | LC_COLLATE=POSIX sort >$tmp.xfs_db
123
124 echo ===xfs_db output >> $seqres.full
125 cat $tmp.xfs_db >> $seqres.full
126 [ ! -s $tmp.xfs_db ] && echo "warning: xfs_db output file is empty"
127
128 echo Comparing out of xfs_quota and xfs_db
129 diff $tmp.quota $tmp.xfs_db
130 [ $? -eq 0 ] && echo OK.
131
132 # success, all done
133 status=0
134 exit