xfstests: convert tests to use new results directory
[xfstests-dev.git] / tests / xfs / 262
1 #! /bin/bash
2 # FS QA Test No. 262
3 #
4 # This test checks the project quota values reported by the quota
5 # "df" and "report" subcommands to ensure they match what they
6 # should be.  There was a bug (fixed by xfsprogs commit 7cb2d41b)
7 # where the values reported were double what they should have been.
8 #
9 # SGI PV 1015651
10 #
11 #-----------------------------------------------------------------------
12 # Copyright (c) 2011 SGI.  All Rights Reserved.
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License as
16 # published by the Free Software Foundation.
17 #
18 # This program is distributed in the hope that it would be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 #
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write the Free Software Foundation,
25 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
26 #-----------------------------------------------------------------------
27 #
28
29 seq=$(basename $0)
30 seqres=$RESULT_DIR/$seq
31 seqres=$RESULT_DIR/$seq
32 seqres=$RESULT_DIR/$seq
33 echo "QA output created by ${seq}"
34
35 here=$(pwd)
36
37 cp /dev/null "${seq}.full"
38
39 tmp=/tmp/$$
40 my_projects=${tmp}.projects
41 my_projid=${tmp}.projid
42 proj_name=test_project
43 proj_num=1
44
45 qlimit_meg=500  # 500M limit imposed = 500 * 1024 * 1024 bytes
46
47 status=1        # failure is the default!
48 trap "_cleanup; exit \$status" 0 1 2 3 15
49
50 _cleanup()
51 {
52     cd /
53     rm -f ${tmp}.*
54 }
55
56 # get standard environment, filters and checks
57 . ./common.rc
58 . ./common.filter
59 . ./common.quota
60
61 echo "Silence is golden."
62
63 # real QA test starts here
64
65 proj_dir="${SCRATCH_MNT}/test"
66
67 # Modify as appropriate.
68 _supported_fs xfs
69 _supported_os Linux
70
71 _require_quota
72 _require_scratch
73
74
75 # Make sure the hard limits reported are what was set.
76 # It is entirely too clever...
77 # It exploits the fact that we've set the soft and hard limits to
78 # the same value, and as a result the value in the fourth field in
79 # both the "df" and the "report" output.  For "report", the line we're
80 # interested in contains our project name in the first field.  For "df"
81 # it contains our project directory in the last field.
82 _filter_quota_rpt() {
83         awk '
84         BEGIN {
85                 proj_name = "'${proj_name}'";
86                 proj_dir = "'${proj_dir}'";
87                 qlimit_meg = '${qlimit_meg}';
88                 qlimit = qlimit_meg * 1024 * 1024;
89         }
90         # This function parses the human-readable values produced
91         # by xfs_quota output
92         function byte_size(value,  result) {
93                 result = strtonum(value);
94                 unit = value;
95                 gsub("[0-9][0-9]*", "", unit);
96                 shift = index("KMGTPE", unit);
97                 while (shift--)
98                         result *= 1024;
99                 return result;
100         }
101         {
102                 if ($1 !~ proj_name && $nf !~ proj_dir)
103                         next;
104                 bsize = byte_size($4);
105                 if (bsize != qlimit)
106                         printf("hard limit %d bytes, expected %d\n",
107                                 bsize, qlimit);
108         }
109         '
110 }
111
112 _quota_cmd() {
113         xfs_quota -P "${my_projid}" -D "${my_projects}" -x \
114                 -c "$@" "${SCRATCH_MNT}"
115 }
116
117 # Set up--mount scratch and create the project directory
118
119 echo ${proj_name}:${proj_num} > "${my_projid}"
120 echo ${proj_num}:${proj_dir} > "${my_projects}"
121
122 _scratch_mkfs                                           >> "${seq}.full" 2>&1
123
124 export MOUNT_OPTIONS="-opquota"
125 _qmount
126 mkdir -p "${proj_dir}"
127
128 # Setup the project quota directory
129 _quota_cmd "project -s ${proj_name}"                    >> "${seq}.full" 2>&1
130
131 # Assign block quota limits
132 _quota_cmd "limit -p bhard=${qlimit_meg}m bsoft=${qlimit_meg}m ${proj_name}" \
133                                                         2>> "${seq}.full" 1>&2
134
135 # See what gets reported
136 _quota_cmd "report"             | _filter_quota_rpt     2>> "${seq}.full"
137 _quota_cmd "df"                 | _filter_quota_rpt     2>> "${seq}.full"
138
139 # This time using "human readable" output
140 _quota_cmd "report -h"          | _filter_quota_rpt     2>> "${seq}.full"
141 _quota_cmd "df -h"              | _filter_quota_rpt     2>> "${seq}.full"
142
143 # Clean up
144 rm -rf "${proj_dir}"
145 _scratch_unmount
146
147 status=0        # success, all done