summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2016-03-30 13:59:40 +0200
committerJan Kara <jack@suse.cz>2016-03-31 10:28:50 +0200
commit83057d99412d0cc57c8d22042e1975e4da96a2fa (patch)
tree410b0cbf890c1087938d4f5f4ced901e1f8d1906
parent9e2f4616f30b55d442fdd7940824f265c172aac1 (diff)
downloadquota-tools-83057d99412d0cc57c8d22042e1975e4da96a2fa.tar.gz
quota: Add project quota support
Signed-off-by: Li Xi <lixi@ddn.com> Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--quota.122
-rw-r--r--quota.c29
2 files changed, 43 insertions, 8 deletions
diff --git a/quota.1 b/quota.1
index a034e9f..12dd94c 100644
--- a/quota.1
+++ b/quota.1
@@ -47,6 +47,20 @@ quota \- display disk usage and limits
.B -F
.I format-name
] [
+.B -qvswi
+] [
+.BR -l \ |
+[
+.BR -QAm
+]]
+.B -P
+.IR project ...
+.br
+.B quota
+[
+.B -F
+.I format-name
+] [
.B -qvswugQm
]
.B -f
@@ -88,6 +102,9 @@ argument(s) restricts the display to the specified group(s).
.B -u, --user
flag is equivalent to the default.
.TP
+.B -P, --project
+Print project quotas for the specified project.
+.TP
.B -v, --verbose
will display quotas on filesystems
where no storage is allocated.
@@ -164,8 +181,9 @@ Only the super-user may use the
.B \-u
flag and the optional
.B user
-argument to view the limits of other users.
-Non-super-users can use the the
+argument to view the limits of other users. Also viewing of project quota
+usage and limits is limited to super-user only.
+Non-super-users can use the
.B \-g
flag and optional
.B group
diff --git a/quota.c b/quota.c
index e195ead..c55e142 100644
--- a/quota.c
+++ b/quota.c
@@ -76,6 +76,7 @@
#define FL_NO_MIXED_PATHS 8192
#define FL_SHOW_MNTPOINT 16384
#define FL_SHOW_DEVICE 32768
+#define FL_PROJECT 65536
static int flags, fmt = -1;
char *progname;
@@ -83,13 +84,14 @@ char *progname;
static void usage(void)
{
errstr( "%s%s%s%s%s",
- _("Usage: quota [-guqvswim] [-l | [-Q | -A]] [-F quotaformat]\n"),
+ _("Usage: quota [-guPqvswim] [-l | [-Q | -A]] [-F quotaformat]\n"),
_("\tquota [-qvswim] [-l | [-Q | -A]] [-F quotaformat] -u username ...\n"),
_("\tquota [-qvswim] [-l | [-Q | -A]] [-F quotaformat] -g groupname ...\n"),
- _("\tquota [-qvswugQm] [-F quotaformat] -f filesystem ...\n"),
+ _("\tquota [-qvswugPQm] [-F quotaformat] -f filesystem ...\n"),
_("\n\
-u, --user display quota for user\n\
-g, --group display quota for group\n\
+-P, --project display quota for project\n\
-q, --quiet print more terse message\n\
-v, --verbose print more verbose message\n\
-s, --human-readable display numbers in human friendly units (MB, GB...)\n\
@@ -298,12 +300,13 @@ int main(int argc, char **argv)
{
int ngroups;
gid_t gidset[NGROUPS_MAX], *gidsetp;
- int i, ret;
+ int i, ret, type = 0;
struct option long_opts[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'V' },
{ "user", 0, NULL, 'u' },
{ "group", 0, NULL, 'g' },
+ { "project", 0, NULL, 'P' },
{ "quiet", 0, NULL, 'q' },
{ "verbose", 0, NULL, 'v' },
{ "human-readable", 0, NULL, 's' },
@@ -326,7 +329,7 @@ int main(int argc, char **argv)
progname = basename(argv[0]);
flags |= FL_SHOW_DEVICE;
- while ((ret = getopt_long(argc, argv, "hguqvsVliQF:wfApm", long_opts, NULL)) != -1) {
+ while ((ret = getopt_long(argc, argv, "hguqvsPVliQF:wfApm", long_opts, NULL)) != -1) {
switch (ret) {
case 'g':
flags |= FL_GROUP;
@@ -334,6 +337,9 @@ int main(int argc, char **argv)
case 'u':
flags |= FL_USER;
break;
+ case 'P':
+ flags |= FL_PROJECT;
+ break;
case 'q':
flags |= FL_QUIET;
break;
@@ -391,7 +397,7 @@ int main(int argc, char **argv)
argc -= optind;
argv += optind;
- if (!(flags & FL_USER) && !(flags & FL_GROUP))
+ if (!(flags & FL_USER) && !(flags & FL_GROUP) && !(flags & FL_PROJECT))
flags |= FL_USER;
if (flags & FL_FSLIST && flags & (FL_LOCALONLY | FL_NOAUTOFS))
errstr(_("Warning: Ignoring -%c when filesystem list specified.\n"), flags & FL_LOCALONLY ? 'l' : 'i');
@@ -419,10 +425,18 @@ int main(int argc, char **argv)
for (i = 0; i < ngroups; i++)
ret |= showquotas(GRPQUOTA, gidsetp[i], argc, argv);
}
+ if (flags & FL_PROJECT)
+ die(1, _("Project reports not supported without project name"));
exit(ret);
}
- if ((flags & FL_USER) && (flags & FL_GROUP))
+ if (flags & FL_USER)
+ type++;
+ if (flags & FL_GROUP)
+ type++;
+ if (flags & FL_PROJECT)
+ type++;
+ if (type > 1)
usage();
if (flags & FL_USER)
@@ -431,5 +445,8 @@ int main(int argc, char **argv)
else if (flags & FL_GROUP)
for (; argc > 0; argc--, argv++)
ret |= showquotas(GRPQUOTA, group2gid(*argv, !!(flags & FL_NUMNAMES), NULL), 0, NULL);
+ else if (flags & FL_PROJECT)
+ for (; argc > 0; argc--, argv++)
+ ret |= showquotas(PRJQUOTA, project2pid(*argv, !!(flags & FL_NUMNAMES), NULL), 0, NULL);
return ret;
}