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