fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 052
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 052
6 #
7 # Ensure that quota(1) displays blocksizes matching ondisk dquots.
8 #
9 # MOUNT_OPTIONS can be set to gquota to test group quota,
10 # defaults to uquota if MOUNT_OPTIONS is not set.
11 #
12 . ./common/preamble
13 _begin_fstest quota db auto quick
14
15 # Import common functions.
16 . ./common/filter
17 . ./common/quota
18
19 # Override the default cleanup function.
20 _cleanup()
21 {
22         cd /
23         _scratch_unmount 2>/dev/null
24         rm -f $tmp.*
25 }
26
27 # real QA test starts here
28 _supported_fs xfs
29
30 _require_scratch
31 _require_xfs_quota
32 _require_nobody
33
34 # setup a default run
35 _qmount_option uquota
36
37 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs
38 cat $tmp.mkfs >>$seqres.full
39 chmod a+w $seqres.full     # arbitrary users will write here
40
41 # keep the blocksize from mkfs ($dbsize)
42 . $tmp.mkfs
43
44 _qmount
45
46 # setup user/group to test
47 if $here/src/feature -U $SCRATCH_DEV ; then
48         type=u; eval `_choose_uid`
49 elif $here/src/feature -G $SCRATCH_DEV ; then
50         type=g; eval `_choose_gid`
51 elif $here/src/feature -P $SCRATCH_DEV ; then
52         type=p; eval `_choose_prid`
53 else
54         _notrun "No quota support at mount time"
55 fi
56
57 # create 100 (fs-blocksize) blocks
58 _file_as_id $SCRATCH_MNT/foo $id $type $dbsize 220
59 sync
60
61 # set limit at 1001 (1k) blocks
62 bsoft=1001
63 bhard=1001
64 isoft=10
65 ihard=10
66 xfs_quota -x \
67         -c "limit -$type bsoft=${bsoft}k bhard=${bhard}k $id" \
68         -c "limit -$type isoft=$isoft ihard=$ihard $id" \
69         $SCRATCH_DEV
70
71 # cross check blks, softblks, hardblks <-> quota, xfs_db
72 xfs_quota -c "quota -$type -birnN $id" $SCRATCH_DEV |
73                         tr -d '\n' | tr -s '[:space:]' | tee -a $seqres.full |
74         perl -ne 'if (m[^\s*'$SCRATCH_DEV'\s+(\d+)\s+(\d+)\s+(\d+)]) {
75                 print "used_blocks=", $1, "\n";
76                 print "soft_blocks=", $2, "\n";
77                 print "hard_blocks=", $3, "\n";
78                 $next = 0;
79         }' | LC_COLLATE=POSIX sort >$tmp.quota
80
81 echo ===quota output >> $seqres.full
82 cat $tmp.quota >> $seqres.full
83 [ ! -s $tmp.quota ] && echo "warning: quota output file is empty"
84
85 _scratch_unmount
86
87 # note - does (insitu) conversion from fs blocks to 1K blocks
88 _scratch_xfs_db -rc "dquot -$type $id" -c p  | tee -a $seqres.full | perl -ne '
89         if (/^diskdq.bcount = (\d+)$/) {
90                  print "used_blocks=", $1 * '$dbsize' / 1024, "\n";
91         }
92         elsif (/^diskdq.blk_hardlimit = (\d+)$/) {
93                  print "hard_blocks=", $1 * '$dbsize' / 1024, "\n";
94         }
95         elsif (/^diskdq.blk_softlimit = (\d+)$/) {
96                 print "soft_blocks=", $1 * '$dbsize' / 1024, "\n";
97         }' | LC_COLLATE=POSIX sort >$tmp.xfs_db
98
99 echo ===xfs_db output >> $seqres.full
100 cat $tmp.xfs_db >> $seqres.full
101 [ ! -s $tmp.xfs_db ] && echo "warning: xfs_db output file is empty"
102
103 echo Comparing out of xfs_quota and xfs_db
104 diff $tmp.quota $tmp.xfs_db
105 [ $? -eq 0 ] && echo OK.
106
107 # success, all done
108 status=0
109 exit