update 114 for new getparents interface and xfs_io parent command.
[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 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 #
13 # creator
14 owner=nathans@sgi.com
15
16 seq=`basename $0`
17 echo "QA output created by $seq"
18
19 here=`pwd`
20 tmp=/tmp/$$
21 status=1        # failure is the default!
22
23 # get standard environment, filters and checks
24 . ./common.rc
25 . ./common.filter
26 . ./common.quota
27
28 _cleanup()
29 {
30         cd /
31         umount $SCRATCH_MNT 2>/dev/null
32         rm -f $tmp.*
33 }
34 trap "_cleanup; exit \$status" 0 1 2 3 15
35
36 # real QA test starts here
37 _supported_fs xfs
38 _supported_os IRIX Linux
39
40 rm -f $seq.full
41
42 _require_scratch
43 _require_quota
44 _require_nobody
45
46 # setup a default run
47 if [ -z "$MOUNT_OPTIONS" ]; then
48         export MOUNT_OPTIONS="-o uquota"
49 fi
50
51 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
52 cat $tmp.mkfs >>$seq.full
53 chmod a+w $seq.full     # arbitrary users will write here
54
55 # keep the blocksize from mkfs ($dbsize)
56 . $tmp.mkfs
57
58 _qmount
59
60 # setup user/group to test
61 if src/feature -U $SCRATCH_DEV ; then
62         type=u; eval `_choose_uid`
63 elif src/feature -G $SCRATCH_DEV ; then
64         type=g; eval `_choose_gid`
65 else
66         _notrun "No quota support at mount time"
67 fi
68
69 # create 100 (fs-blocksize) blocks
70 _file_as_id $SCRATCH_MNT/foo $id $type $dbsize 220
71 sync
72
73 # Irix uses filesystem name and Linux uses device of filesystem
74 if [ $HOSTOS = "Linux" ]; then
75     QUOTA_FS=$SCRATCH_DEV
76 else
77     QUOTA_FS=$SCRATCH_MNT
78 fi
79
80 # set limit at 1001 (1k) blocks
81 bsoft=1001
82 bhard=1001
83 isoft=10
84 ihard=10
85 _setquota -$type $id $bsoft $bhard $isoft $ihard $QUOTA_FS
86
87 _filter_quota()
88 {
89     perl -ne '
90         if (m[^\s*'$QUOTA_FS'\s+(\d+)\s+(\d+)\s+(\d+)] ||
91                 ($next == 1 && m,^\s+(\d+)\s+(\d+)\s+(\d+),)) {
92                 print "used_blocks=", $1, "\n";
93                 print "soft_blocks=", $2, "\n";
94                 print "hard_blocks=", $3, "\n";
95                 $next = 0;
96         }
97         elsif (m[^\s*'$QUOTA_FS']) {            # devfs (long) names
98                 $next = 1;
99         }' | LC_COLLATE=POSIX sort
100 }
101
102 # cross check blks, softblks, hardblks <-> quota, xfs_db
103 _quota -$type $id | tee -a $seq.full | _filter_quota >$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 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