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 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
23 my_projects=$tmp.projects
25 proj_name=test_project
28 qlimit_meg=500 # 500M limit imposed = 500 * 1024 * 1024 bytes
30 status=1 # failure is the default!
31 trap "_cleanup; exit \$status" 0 1 2 3 15
39 # get standard environment, filters and checks
44 echo "Silence is golden."
46 # real QA test starts here
48 proj_dir="$SCRATCH_MNT/test"
50 # Modify as appropriate.
55 _require_xfs_quota_foreign
58 # Make sure the hard limits reported are what was set.
59 # It is entirely too clever...
60 # It exploits the fact that we've set the soft and hard limits to
61 # the same value, and as a result the value in the fourth field in
62 # both the "df" and the "report" output. For "report", the line we're
63 # interested in contains our project name in the first field. For "df"
64 # it contains our project directory in the last field.
65 # But if the device name is too long, the "df" output is broke into two
66 # lines, the fourth field is not correct, so take $(NF-2) of "df"
70 proj_name = "'${proj_name}'";
71 proj_dir = "'${proj_dir}'";
72 qlimit_meg = '${qlimit_meg}';
73 qlimit = qlimit_meg * 1024 * 1024;
75 # This function parses the human-readable values produced
77 function byte_size(value, result) {
78 result = strtonum(value);
80 gsub("[0-9][0-9]*", "", unit);
81 shift = index("KMGTPE", unit);
88 # this is the "report" output
89 bsize = byte_size($4);
90 } else if ($NF ~ proj_dir) {
91 # this is the "df" output
92 bsize = byte_size($(NF-2));
97 printf("hard limit %d bytes, expected %d\n",
104 $XFS_QUOTA_PROG -P "$my_projid" -D "$my_projects" -x \
105 -c "$@" "$SCRATCH_MNT"
108 # Set up--mount scratch and create the project directory
110 echo $proj_name:$proj_num > "$my_projid"
111 echo $proj_num:$proj_dir > "$my_projects"
113 _scratch_mkfs >> "$seqres.full" 2>&1
114 _scratch_enable_pquota
116 _qmount_option "prjquota"
118 _require_prjquota $SCRATCH_DEV
120 mkdir -p "${proj_dir}"
122 # Setup the project quota directory
123 _quota_cmd "project -s ${proj_name}" >> "$seqres.full" 2>&1
125 # Assign block quota limits
126 _quota_cmd "limit -p bhard=${qlimit_meg}m bsoft=${qlimit_meg}m ${proj_name}" \
127 2>> "$seqres.full" 1>&2
129 # See what gets reported
130 _quota_cmd "report" | _filter_quota_rpt 2>> "$seqres.full"
131 _quota_cmd "df" | _filter_quota_rpt 2>> "$seqres.full"
133 # This time using "human readable" output
134 _quota_cmd "report -h" | _filter_quota_rpt 2>> "$seqres.full"
135 _quota_cmd "df -h" | _filter_quota_rpt 2>> "$seqres.full"
141 status=0 # success, all done