diff options
author | Jan Kara <jack@suse.cz> | 2016-03-30 13:34:34 +0200 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2016-03-31 10:28:24 +0200 |
commit | ded2822490905c499375a4eef9432dba831950a8 (patch) | |
tree | ea656a91234688f575d011e984a992717666d90a | |
parent | 6206e37f8f478d0908bfb93045b5b303a09f8a9b (diff) | |
download | quota-tools-ded2822490905c499375a4eef9432dba831950a8.tar.gz |
quotaon: Add project quota support
Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | quotaon.8 | 10 | ||||
-rw-r--r-- | quotaon.c | 20 | ||||
-rw-r--r-- | quotaon_xfs.c | 52 |
3 files changed, 61 insertions, 21 deletions
@@ -14,7 +14,7 @@ quotaon, quotaoff \- turn filesystem quotas on and off .br .B quotaon [ -.B \-avugfp +.B \-avugPfp ] [ .B \-F .I format-name @@ -22,7 +22,7 @@ quotaon, quotaoff \- turn filesystem quotas on and off .LP .B quotaoff [ -.B \-vugp +.B \-vugPp ] [ .B \-x @@ -109,6 +109,9 @@ Manipulate user quotas. This is the default. .B -g, --group Manipulate group quotas. .TP +.B -P, --project +Manipulate project quotas. +.TP .B -p, --print-state Instead of turning quotas on just print state of quotas (ie. whether. quota is on or off) .TP @@ -148,6 +151,9 @@ Manipulate user quotas. This is the default. .B -g, --group Manipulate group quotas. .TP +.B -P, --project +Manipulate project quotas. +.TP .B -p, --print-state Instead of turning quotas off just print state of quotas (ie. whether. quota is on or off) .TP @@ -54,6 +54,7 @@ #define FL_ALL 8 #define FL_STAT 16 #define FL_OFF 32 +#define FL_PROJECT 64 static int flags, fmt = -1; char *progname; @@ -63,12 +64,13 @@ static char *xarg = NULL; static void usage(void) { - errstr(_("Usage:\n\t%s [-guvp] [-F quotaformat] [-x state] -a\n\ -\t%s [-guvp] [-F quotaformat] [-x state] filesys ...\n\n\ + errstr(_("Usage:\n\t%s [-guPvp] [-F quotaformat] [-x state] -a\n\ +\t%s [-guPvp] [-F quotaformat] [-x state] filesys ...\n\n\ -a, --all %s\n\ -f, --off turn quotas off\n\ -u, --user operate on user quotas\n\ -g, --group operate on group quotas\n\ +-P, --project operate on project quotas\n\ -p, --print-state print whether quotas are on or off\n\ -x, --xfs-command=cmd perform XFS quota command\n\ -F, --format=formatname operate on specific quota format\n\ @@ -90,6 +92,7 @@ static void parse_options(int argcnt, char **argstr) { "verbose", 0, NULL, 'v' }, { "user", 0, NULL, 'u' }, { "group", 0, NULL, 'g' }, + { "project", 0, NULL, 'P' }, { "print-state", 0, NULL, 'p' }, { "xfs-command", 1, NULL, 'x' }, { "format", 1, NULL, 'F' }, @@ -98,7 +101,7 @@ static void parse_options(int argcnt, char **argstr) { NULL, 0, NULL, 0 } }; - while ((c = getopt_long(argcnt, argstr, "afvugpx:VF:h", long_opts, NULL)) != -1) { + while ((c = getopt_long(argcnt, argstr, "afvugpPx:VF:h", long_opts, NULL)) != -1) { switch (c) { case 'a': flags |= FL_ALL; @@ -112,6 +115,9 @@ static void parse_options(int argcnt, char **argstr) case 'u': flags |= FL_USER; break; + case 'P': + flags |= FL_PROJECT; + break; case 'v': flags |= FL_VERBOSE; break; @@ -141,8 +147,8 @@ static void parse_options(int argcnt, char **argstr) fputs(_("Cannot turn on/off quotas via RPC.\n"), stderr); exit(1); } - if (!(flags & (FL_USER | FL_GROUP))) - flags |= FL_USER | FL_GROUP; + if (!(flags & (FL_USER | FL_GROUP | FL_PROJECT))) + flags |= FL_USER | FL_GROUP | FL_PROJECT; if (!(flags & FL_ALL)) { mntpoints = argstr + optind; mntcnt = argcnt - optind; @@ -380,12 +386,16 @@ int main(int argc, char **argv) errs += newstate(mnt, GRPQUOTA, xarg); if (flags & FL_USER) errs += newstate(mnt, USRQUOTA, xarg); + if (flags & FL_PROJECT) + errs += newstate(mnt, PRJQUOTA, xarg); } else { if (flags & FL_GROUP) errs += print_state(mnt, GRPQUOTA); if (flags & FL_USER) errs += print_state(mnt, USRQUOTA); + if (flags & FL_PROJECT) + errs += print_state(mnt, PRJQUOTA); } } end_mounts_scan(); diff --git a/quotaon_xfs.c b/quotaon_xfs.c index ed47221..d557a75 100644 --- a/quotaon_xfs.c +++ b/quotaon_xfs.c @@ -45,12 +45,18 @@ static int xfs_state_check(int qcmd, int type, int flags, const char *dev, int r if (info.qs_flags & XFS_QUOTA_UDQ_ENFD) state = ENFD; } - else { /* GRPQUOTA */ + else if (type == GRPQUOTA) { if (info.qs_flags & XFS_QUOTA_GDQ_ACCT) state = ACCT; if (info.qs_flags & XFS_QUOTA_GDQ_ENFD) state = ENFD; } + else if (type == PRJQUOTA) { + if (info.qs_flags & XFS_QUOTA_PDQ_ACCT) + state = ACCT; + if (info.qs_flags & XFS_QUOTA_PDQ_ENFD) + state = ENFD; + } switch (state) { case QOFF: @@ -83,7 +89,9 @@ static int xfs_state_check(int qcmd, int type, int flags, const char *dev, int r " (reboot to take effect)\n"), _(type2name(type))); return 1; } - if (xopts & XFS_QUOTA_UDQ_ENFD || xopts & XFS_QUOTA_GDQ_ENFD) { + if (xopts & XFS_QUOTA_UDQ_ENFD || + xopts & XFS_QUOTA_GDQ_ENFD || + xopts & XFS_QUOTA_PDQ_ENFD) { pinfo(_("Enabling %s quota enforcement on %s\n"), _(type2name(type)), dev); return 1; } @@ -91,7 +99,9 @@ static int xfs_state_check(int qcmd, int type, int flags, const char *dev, int r _(type2name(type)), dev); return -1; case Q_XFS_QUOTAOFF: - if (xopts & XFS_QUOTA_UDQ_ACCT || xopts & XFS_QUOTA_GDQ_ACCT) { + if (xopts & XFS_QUOTA_UDQ_ACCT || + xopts & XFS_QUOTA_GDQ_ACCT || + xopts & XFS_QUOTA_PDQ_ACCT) { pinfo(_("Disabling %s quota accounting on %s\n"), _(type2name(type)), dev); return 1; @@ -114,13 +124,17 @@ static int xfs_state_check(int qcmd, int type, int flags, const char *dev, int r _(type2name(type)), dev); return -1; case Q_XFS_QUOTAOFF: - if (xopts == XFS_QUOTA_UDQ_ACCT || xopts == XFS_QUOTA_GDQ_ACCT) { + if (xopts == XFS_QUOTA_UDQ_ACCT || + xopts == XFS_QUOTA_GDQ_ACCT || + xopts == XFS_QUOTA_PDQ_ACCT) { errstr(_("Cannot switch off %s quota " "accounting on %s when enforcement is on\n"), _(type2name(type)), dev); return -1; } - if (xopts & XFS_QUOTA_UDQ_ACCT || xopts & XFS_QUOTA_GDQ_ACCT) + if (xopts & XFS_QUOTA_UDQ_ACCT || + xopts & XFS_QUOTA_GDQ_ACCT || + xopts & XFS_QUOTA_PDQ_ACCT) acctstr = _("and accounting "); pinfo(_("Disabling %s quota enforcement %son %s\n"), _(type2name(type)), acctstr, dev); @@ -203,21 +217,31 @@ int xfs_newstate(struct mount_entry *mnt, int type, char *xarg, int flags) } #endif /* XFS_ROOTHACK */ - if (xarg == NULL) { /* only enfd on/off */ - xopts |= (type == USRQUOTA) ? XFS_QUOTA_UDQ_ENFD : - XFS_QUOTA_GDQ_ENFD; + if (xarg == NULL || strcmp(xarg, "enforce") == 0) { /* only enfd on/off */ + if (type == USRQUOTA) + xopts |= XFS_QUOTA_UDQ_ENFD; + else if (type == GRPQUOTA) + xopts |= XFS_QUOTA_GDQ_ENFD; + else if (type == PRJQUOTA) + xopts |= XFS_QUOTA_PDQ_ENFD; err = xfs_onoff(mnt->me_devname, type, flags, roothack, xopts); } else if (strcmp(xarg, "account") == 0) { - xopts |= (type == USRQUOTA) ? XFS_QUOTA_UDQ_ACCT : XFS_QUOTA_GDQ_ACCT; - err = xfs_onoff(mnt->me_devname, type, flags, roothack, xopts); - } - else if (strcmp(xarg, "enforce") == 0) { - xopts |= (type == USRQUOTA) ? XFS_QUOTA_UDQ_ENFD : XFS_QUOTA_GDQ_ENFD; + if (type == USRQUOTA) + xopts |= XFS_QUOTA_UDQ_ACCT; + else if (type == GRPQUOTA) + xopts |= XFS_QUOTA_GDQ_ACCT; + else if (type == PRJQUOTA) + xopts |= XFS_QUOTA_PDQ_ACCT; err = xfs_onoff(mnt->me_devname, type, flags, roothack, xopts); } else if (strcmp(xarg, "delete") == 0) { - xopts |= (type == USRQUOTA) ? XFS_USER_QUOTA : XFS_GROUP_QUOTA; + if (type == USRQUOTA) + xopts |= XFS_USER_QUOTA; + else if (type == GRPQUOTA) + xopts |= XFS_GROUP_QUOTA; + else if (type == PRJQUOTA) + xopts |= XFS_PROJ_QUOTA; err = xfs_delete(mnt->me_devname, type, flags, roothack, xopts); } else |