generic/405: test mkfs against thin provision device
[xfstests-dev.git] / tests / generic / 386
1 #! /bin/bash
2 # FS QA Test No. 386
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 echo "QA output created by $seq"
32
33 here=$(pwd)
34
35 rm -f $seqres.full
36
37 tmp=/tmp/$$
38 my_projects=$tmp.projects
39 my_projid=$tmp.projid
40 proj_name=test_project
41 proj_num=1
42
43 qlimit_meg=500  # 500M limit imposed = 500 * 1024 * 1024 bytes
44
45 status=1        # failure is the default!
46 trap "_cleanup; exit \$status" 0 1 2 3 15
47
48 _cleanup()
49 {
50     cd /
51     rm -f $tmp.*
52 }
53
54 # get standard environment, filters and checks
55 . ./common/rc
56 . ./common/filter
57 . ./common/quota
58
59 echo "Silence is golden."
60
61 # real QA test starts here
62
63 proj_dir="$SCRATCH_MNT/test"
64
65 # Modify as appropriate.
66 _supported_fs generic
67 _supported_os Linux
68
69 _require_quota
70 _require_xfs_quota_foreign
71 _require_scratch
72
73 # Make sure the hard limits reported are what was set.
74 # It is entirely too clever...
75 # It exploits the fact that we've set the soft and hard limits to
76 # the same value, and as a result the value in the fourth field in
77 # both the "df" and the "report" output.  For "report", the line we're
78 # interested in contains our project name in the first field.  For "df"
79 # it contains our project directory in the last field.
80 # But if the device name is too long, the "df" output is broke into two
81 # lines, the fourth field is not correct, so take $(nf-2) of "df"
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) {
103                         # this is the "report" output
104                         bsize = byte_size($4);
105                 } else if ($nf =~ proj_dir) {
106                         # this is the "df" output
107                         bsize = byte_size($(nf-2));
108                 } else {
109                         next;
110                 }
111                 if (bsize != qlimit)
112                         printf("hard limit %d bytes, expected %d\n",
113                                 bsize, qlimit);
114         }
115         '
116 }
117
118 _quota_cmd() {
119         $XFS_QUOTA_PROG -P "$my_projid" -D "$my_projects" -x \
120                 -c "$@" "$SCRATCH_MNT"
121 }
122
123 # Set up--mount scratch and create the project directory
124
125 echo $proj_name:$proj_num > "$my_projid"
126 echo $proj_num:$proj_dir > "$my_projects"
127
128 _scratch_mkfs                                   >> "$seqres.full" 2>&1
129 _scratch_enable_pquota
130
131 _qmount_option "prjquota"
132 _qmount
133 _require_prjquota $SCRATCH_DEV
134
135 mkdir -p "${proj_dir}"
136
137 # Setup the project quota directory
138 _quota_cmd "project -s ${proj_name}"                    >> "$seqres.full" 2>&1
139
140 # Assign block quota limits
141 _quota_cmd "limit -p bhard=${qlimit_meg}m bsoft=${qlimit_meg}m ${proj_name}" \
142                                                         2>> "$seqres.full" 1>&2
143
144 # See what gets reported
145 _quota_cmd "report"             | _filter_quota_rpt     2>> "$seqres.full"
146 _quota_cmd "df"                 | _filter_quota_rpt     2>> "$seqres.full"
147
148 # This time using "human readable" output
149 _quota_cmd "report -h"          | _filter_quota_rpt     2>> "$seqres.full"
150 _quota_cmd "df -h"              | _filter_quota_rpt     2>> "$seqres.full"
151
152 # Clean up
153 rm -rf "$proj_dir"
154 _scratch_unmount
155
156 status=0        # success, all done