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