2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 SGI. All Rights Reserved.
7 # This test checks the project quota values reported by the quota
8 # "df" and "report" subcommands to ensure they match what they
9 # should be. There was a bug (fixed by xfsprogs commit 7cb2d41b)
10 # where the values reported were double what they should have been.
15 _begin_fstest auto quick quota
17 my_projects=$tmp.projects
19 proj_name=test_project
22 qlimit_meg=500 # 500M limit imposed = 500 * 1024 * 1024 bytes
24 # Import common functions.
28 echo "Silence is golden."
30 # real QA test starts here
32 proj_dir="$SCRATCH_MNT/test"
34 # Modify as appropriate.
38 _require_xfs_quota_foreign
41 # Make sure the hard limits reported are what was set.
42 # It is entirely too clever...
43 # It exploits the fact that we've set the soft and hard limits to
44 # the same value, and as a result the value in the second field in
45 # both the "df" and the "report" output. For "report", the line we're
46 # interested in contains our project name in the first field. For "df"
47 # it contains our project directory in the last field.
48 # But if the device name is too long, the "df" output is broke into two
49 # lines, the second field is not correct, so take $(NF-4) of "df"
53 proj_name = "'${proj_name}'";
54 proj_dir = "'${proj_dir}'";
55 qlimit_meg = '${qlimit_meg}';
56 qlimit = qlimit_meg * 1024 * 1024;
58 # This function parses the human-readable values produced
60 function byte_size(value, result) {
61 result = strtonum(value);
63 gsub("[0-9][0-9]*", "", unit);
64 shift = index("KMGTPE", unit);
71 # this is the "report" output
72 bsize = byte_size($4);
73 } else if ($NF ~ proj_dir) {
74 # this is the "df" output
75 bsize = byte_size($(NF-4));
80 printf("hard limit %d bytes, expected %d\n",
87 $XFS_QUOTA_PROG -P "$my_projid" -D "$my_projects" -x \
88 -c "$@" "$SCRATCH_MNT"
91 # Set up--mount scratch and create the project directory
93 echo $proj_name:$proj_num > "$my_projid"
94 echo $proj_num:$proj_dir > "$my_projects"
96 _scratch_mkfs >> "$seqres.full" 2>&1
97 _scratch_enable_pquota
99 _qmount_option "prjquota"
101 _require_prjquota $SCRATCH_DEV
103 mkdir -p "${proj_dir}"
105 # Setup the project quota directory
106 _quota_cmd "project -s ${proj_name}" >> "$seqres.full" 2>&1
108 # Assign block quota limits
109 _quota_cmd "limit -p bhard=${qlimit_meg}m bsoft=${qlimit_meg}m ${proj_name}" \
110 2>> "$seqres.full" 1>&2
112 # See what gets reported
113 _quota_cmd "report" | _filter_quota_rpt 2>> "$seqres.full"
114 _quota_cmd "df" | _filter_quota_rpt 2>> "$seqres.full"
116 # This time using "human readable" output
117 _quota_cmd "report -h" | _filter_quota_rpt 2>> "$seqres.full"
118 _quota_cmd "df -h" | _filter_quota_rpt 2>> "$seqres.full"
124 status=0 # success, all done