generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 386
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 SGI.  All Rights Reserved.
4 #
5 # FS QA Test No. 386
6 #
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.
11 #
12 # SGI PV 1015651
13 #
14 . ./common/preamble
15 _begin_fstest auto quick quota
16
17 my_projects=$tmp.projects
18 my_projid=$tmp.projid
19 proj_name=test_project
20 proj_num=1
21
22 qlimit_meg=500  # 500M limit imposed = 500 * 1024 * 1024 bytes
23
24 # Import common functions.
25 . ./common/filter
26 . ./common/quota
27
28 echo "Silence is golden."
29
30 # real QA test starts here
31
32 proj_dir="$SCRATCH_MNT/test"
33
34 # Modify as appropriate.
35 _supported_fs generic
36
37 _require_quota
38 _require_xfs_quota_foreign
39 _require_scratch
40
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"
50 _filter_quota_rpt() {
51         awk '
52         BEGIN {
53                 proj_name = "'${proj_name}'";
54                 proj_dir = "'${proj_dir}'";
55                 qlimit_meg = '${qlimit_meg}';
56                 qlimit = qlimit_meg * 1024 * 1024;
57         }
58         # This function parses the human-readable values produced
59         # by xfs_quota output
60         function byte_size(value,  result) {
61                 result = strtonum(value);
62                 unit = value;
63                 gsub("[0-9][0-9]*", "", unit);
64                 shift = index("KMGTPE", unit);
65                 while (shift--)
66                         result *= 1024;
67                 return result;
68         }
69         {
70                 if ($1 ~ proj_name) {
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));
76                 } else {
77                         next;
78                 }
79                 if (bsize != qlimit)
80                         printf("hard limit %d bytes, expected %d\n",
81                                 bsize, qlimit);
82         }
83         '
84 }
85
86 _quota_cmd() {
87         $XFS_QUOTA_PROG -P "$my_projid" -D "$my_projects" -x \
88                 -c "$@" "$SCRATCH_MNT"
89 }
90
91 # Set up--mount scratch and create the project directory
92
93 echo $proj_name:$proj_num > "$my_projid"
94 echo $proj_num:$proj_dir > "$my_projects"
95
96 _scratch_mkfs                                   >> "$seqres.full" 2>&1
97 _scratch_enable_pquota
98
99 _qmount_option "prjquota"
100 _qmount
101 _require_prjquota $SCRATCH_DEV
102
103 mkdir -p "${proj_dir}"
104
105 # Setup the project quota directory
106 _quota_cmd "project -s ${proj_name}"                    >> "$seqres.full" 2>&1
107
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
111
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"
115
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"
119
120 # Clean up
121 rm -rf "$proj_dir"
122 _scratch_unmount
123
124 status=0        # success, all done