Skip to contentSkip to conversation

xfs_quota: modify commands which can't handle multiple types

PATCH Superseded Zorro Lang 2 participants 2 messages Feb 12, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

PATCH 1/1 xfs_quota: modify commands which can't handle multiple types

Some xfs_quota commands can't deal with multiple types together. For example, if we run "limit -ug ...", one type will overwrite the other. I find below commands can't handle multiple types:

[quota, limit, timer, warn, dump, restore and quot]

(Although timer and warn command can't support -ugp types until now, it will in one day.)

For every single $command, I change their ${command}_f function, ${command}_help() function, ${command}_cmd structure and man page.

---
 man/man8/xfs_quota.8 | 96 +++++++++++++++++++++++++++++++++++++++++++++-------
 quota/edit.c         | 78 ++++++++++++++++++++++++++----------------
 quota/quot.c         | 21 +++++++-----
 quota/quota.c        | 21 +++++++-----
 quota/report.c       | 26 +++++++++-----
 5 files changed, 175 insertions(+), 67 deletions(-)
man/man8/xfs_quota.8 +83 -13
index 3bee145..4652dfe 100644
@@ -169,7 +169,11 @@ command.
 .HP
 .B quota
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ] [
 .B \-bir
 ] [
@@ -188,6 +192,12 @@ Show individual usage and limits, for a single user
 or numeric user
 .IR ID .
 The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't used together. The
 .B \-h
 option reports in a "human-readable" format similar to the
 .BR df (1)
@@ -398,7 +408,11 @@ option reports state on all filesystems and not just the current path.
 .B
 limit
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ]
 .BI bsoft= N
 |
@@ -426,11 +440,21 @@ that will be used, otherwise a specific
 .I name
 or numeric
 .IR id entifier
-must be specified.
+must be specified. The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't be used together for this command.
 .HP
 .B timer
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ] [
 .B \-bir
 ]
@@ -442,11 +466,21 @@ be modified. The current timeout setting can be displayed using the
 .B state
 command. The value argument is a number of seconds, but units of
 \&'minutes', 'hours', 'days', and 'weeks' are also understood
-(as are their abbreviations 'm', 'h', 'd', and 'w').
+(as are their abbreviations 'm', 'h', 'd', and 'w'). The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't be used together for this command.
 .HP
 .B warn
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ] [
 .B \-bir
 ]
@@ -466,7 +500,13 @@ that will be used, otherwise a specific
 .I name
 or numeric
 .IR id entifier
-must be specified.
+must be specified. The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't be used together for this command.
 .B NOTE: this feature is not currently implemented.
 .TP
 .BR enable " [ " \-gpu " ] [ " \-v " ]"
@@ -497,7 +537,11 @@ report an error.
 .B
 dump
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ] [
 .B \-f
 .I file
@@ -506,11 +550,21 @@ dump
 Dump out quota limit information for backup utilities, either to
 standard output (default) or to a
 .IR file .
-This is only the limits, not the usage information, of course.
+This is only the limits, not the usage information, of course. The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't be used together for this command.
 .HP
 .B restore
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ] [
 .B \-f
 .I file
@@ -520,12 +574,22 @@ Restore quota limits from a backup
 .IR file .
 The file must be in the format produced by the
 .B dump
-command.
+command. The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't be used together for this command.
 .HP
 .B
 quot
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ] [
 .B \-bir
 ] [
@@ -551,7 +615,13 @@ option displays verbose information. The
 .B \-f
 option send the output to
 .I file
-instead of stdout.
+instead of stdout. The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't be used together for this command.
 .HP
 .B project
 [
quota/edit.c +49 -29

188 lines not on this page · raw message

quota/quot.c +13 -8
index 9116e48..5588a25 100644
@@ -62,9 +62,9 @@ quot_help(void)
 "       total of all files greater than 500 kilobytes.\n"
 " -v -- display three columns containing the number of kilobytes not\n"
 "       accessed in the last 30, 60, and 90 days.\n"
-" -g -- display group summary\n"
-" -p -- display project summary\n"
-" -u -- display user summary\n"
+" -g -- display group summary, can't coexist with -p, -u\n"
+" -p -- display project summary, can't coexist with -g, -u\n"
+" -u -- display user summary, can't coexist with -g, -p\n"
 " -b -- display number of blocks used\n"
 " -i -- display number of inodes used\n"
 " -r -- display number of realtime blocks used\n"
@@ -361,13 +361,13 @@ quot_f(
 			form |= XFS_RTBLOCK_QUOTA;
 			break;
 		case 'g':
-			type = XFS_GROUP_QUOTA;
+			type |= XFS_GROUP_QUOTA;
 			break;
 		case 'p':
-			type = XFS_PROJ_QUOTA;
+			type |= XFS_PROJ_QUOTA;
 			break;
 		case 'u':
-			type = XFS_USER_QUOTA;
+			type |= XFS_USER_QUOTA;
 			break;
 		case 'a':
 			flags |= ALL_MOUNTS_FLAG;
@@ -389,8 +389,13 @@ quot_f(
 	if (!form)
 		form = XFS_BLOCK_QUOTA;
 
-	if (!type)
+	if (!type) {
 		type = XFS_USER_QUOTA;
+	} else if (type != XFS_GROUP_QUOTA
+	           && type != XFS_PROJ_QUOTA
+	           && type != XFS_USER_QUOTA) {
+		return command_usage(&quot_cmd);
+	}
 
 	if ((fp = fopen_write_secure(fname)) == NULL)
 		return 0;
@@ -416,7 +421,7 @@ quot_init(void)
 	quot_cmd.cfunc = quot_f;
 	quot_cmd.argmin = 0;
 	quot_cmd.argmax = -1;
-	quot_cmd.args = _("[-bir] [-gpu] [-acv] [-f file]");
+	quot_cmd.args = _("[-bir] [-g|-p|-u] [-acv] [-f file]");
 	quot_cmd.oneline = _("summarize filesystem ownership");
 	quot_cmd.help = quot_help;
 
quota/quota.c +13 -8
index f6b24c3..9ba0bc9 100644
@@ -32,9 +32,9 @@ quota_help(void)
 "\n"
 " display usage and quota information\n"
 "\n"
-" -g -- display group quota information\n"
-" -p -- display project quota information\n"
-" -u -- display user quota information\n"
+" -g -- display group quota information, can't coexist with -p, -u\n"
+" -p -- display project quota information, can't coexist with -g, -u\n"
+" -u -- display user quota information, can't coexist with -g, -p\n"
 " -b -- display number of blocks used\n"
 " -i -- display number of inodes used\n"
 " -r -- display number of realtime blocks used\n"
@@ -409,13 +409,13 @@ quota_f(
 			form |= XFS_RTBLOCK_QUOTA;
 			break;
 		case 'g':
-			type = XFS_GROUP_QUOTA;
+			type |= XFS_GROUP_QUOTA;
 			break;
 		case 'p':
-			type = XFS_PROJ_QUOTA;
+			type |= XFS_PROJ_QUOTA;
 			break;
 		case 'u':
-			type = XFS_USER_QUOTA;
+			type |= XFS_USER_QUOTA;
 			break;
 		case 'h':
 			flags |= HUMAN_FLAG;
@@ -437,8 +437,13 @@ quota_f(
 	if (!form)
 		form = XFS_BLOCK_QUOTA;
 
-	if (!type)
+	if (!type) {
 		type = XFS_USER_QUOTA;
+	} else if (type != XFS_GROUP_QUOTA
+	           && type != XFS_PROJ_QUOTA
+	           && type != XFS_USER_QUOTA) {
+		return command_usage(&quota_cmd);
+	}
 
 	if ((fp = fopen_write_secure(fname)) == NULL)
 		return 0;
@@ -461,7 +466,7 @@ quota_init(void)
 	quota_cmd.cfunc = quota_f;
 	quota_cmd.argmin = 0;
 	quota_cmd.argmax = -1;
-	quota_cmd.args = _("[-bir] [-gpu] [-hnNv] [-f file] [id|name]...");
+	quota_cmd.args = _("[-bir] [-g|-p|-u] [-hnNv] [-f file] [id|name]...");
 	quota_cmd.oneline = _("show usage and limits");
 	quota_cmd.help = quota_help;
 
quota/report.c +17 -9
index 8653134..2e7ec15 100644
@@ -30,14 +30,14 @@ static cmdinfo_t report_cmd;
 static void
 dump_help(void)
 {
-	dump_cmd.args = _("[-gpu] [-f file]");
+	dump_cmd.args = _("[-g|-p|-u] [-f file]");
 	dump_cmd.oneline = _("dump quota information for backup utilities");
 	printf(_(
 "\n"
 " create a backup file which contains quota limits information\n"
-" -g -- dump out group quota limits\n"
-" -p -- dump out project quota limits\n"
-" -u -- dump out user quota limits (default)\n"
+" -g -- dump out group quota limits, can't coexist with -p, -u\n"
+" -p -- dump out project quota limits, can't coexist with -g, -u\n"
+" -u -- dump out user quota limits (default), cant coexist with -g, -p\n"
 " -f -- write the dump out to the specified file\n"
 "\n"));
 }
@@ -199,7 +199,7 @@ dump_f(
 	FILE		*fp;
 	char		*fname = NULL;
 	uint		lower = 0, upper = 0;
-	int		c, type = XFS_USER_QUOTA;
+	int		c, type = 0;
 
 	while ((c = getopt(argc, argv, "f:gpuL:U:")) != EOF) {
 		switch(c) {
@@ -207,13 +207,13 @@ dump_f(
 			fname = optarg;
 			break;
 		case 'g':
-			type = XFS_GROUP_QUOTA;
+			type |= XFS_GROUP_QUOTA;
 			break;
 		case 'p':
-			type = XFS_PROJ_QUOTA;
+			type |= XFS_PROJ_QUOTA;
 			break;
 		case 'u':
-			type = XFS_USER_QUOTA;
+			type |= XFS_USER_QUOTA;
 			break;
 		case 'L':
 			lower = (uint)atoi(optarg);
@@ -229,6 +229,14 @@ dump_f(
 	if (argc != optind)
 		return command_usage(&dump_cmd);
 
+	if (!type) {
+		type = XFS_USER_QUOTA;
+	} else if (type != XFS_GROUP_QUOTA
+	           && type != XFS_PROJ_QUOTA
+	           && type != XFS_USER_QUOTA) {
+		return command_usage(&dump_cmd);
+	}
+
 	if ((fp = fopen_write_secure(fname)) == NULL)
 		return 0;
 
@@ -725,7 +733,7 @@ report_init(void)
 	dump_cmd.cfunc = dump_f;
 	dump_cmd.argmin = 0;
 	dump_cmd.argmax = -1;
-	dump_cmd.args = _("[-gpu] [-f file]");
+	dump_cmd.args = _("[-g|-p|-u] [-f file]");
 	dump_cmd.oneline = _("dump quota information for backup utilities");
 	dump_cmd.help = dump_help;
 
Signature · 6 lines
1.9.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw

Hi Zorro -

Quoted 28 lines · Zorro Lang

Some xfs_quota commands can't deal with multiple types together. For example, if we run "limit -ug ...", one type will overwrite the other. I find below commands can't handle multiple types:

[quota, limit, timer, warn, dump, restore and quot]

(Although timer and warn command can't support -ugp types until now, it will in one day.)

For every single $command, I change their ${command}_f function, ${command}_help() function, ${command}_cmd structure and man page.

---
 man/man8/xfs_quota.8 | 96 +++++++++++++++++++++++++++++++++++++++++++++-------
 quota/edit.c         | 78 ++++++++++++++++++++++++++----------------
 quota/quot.c         | 21 +++++++-----
 quota/quota.c        | 21 +++++++-----
 quota/report.c       | 26 +++++++++-----
 5 files changed, 175 insertions(+), 67 deletions(-)
man/man8/xfs_quota.8 +0 -0
index 3bee145..4652dfe 100644
@@ -169,7 +169,11 @@ command.
 .HP
 .B quota

man/man8/xfs_quota.8 command. · line 179

Quoted 10 lines
man/man8/xfs_quota.8 +5 -1
 [
-.B \-gpu
+.B \-g
+|
+.B \-p
+|
+.B \-u
 ] [
 .B \-bir
 ] [

I had mentioned on IRC that this might be more compact:

.BR \-g | \-u | \-p

but actually yours may look better, with spaces.

So that looks good.

... snip ...

man/man8/xfs_quota.8 be modified. The current timeout setting can be displayed using the · line 475

Quoted 12 lines
man/man8/xfs_quota.8 +7 -1
@@ -442,11 +466,21 @@ be modified. The current timeout setting can be displayed using the
 .B state
 command. The value argument is a number of seconds, but units of
 \&'minutes', 'hours', 'days', and 'weeks' are also understood
-(as are their abbreviations 'm', 'h', 'd', and 'w').
+(as are their abbreviations 'm', 'h', 'd', and 'w'). The
+.B \-u
+,
+.B \-g
+and
+.B \-p
+types can't be used together for this command.

If you present it as [-u|-g|-p] or "-u|-g|-p" I don't think you need to re-state that they are exclusive.

(this is true for every command you've modified)

It's a standard that everyone should be aware of:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html

...

Quoted 7 lines
quota/edit.c +0 -0
index 6146f7e..9dab4c3 100644
@@ -43,9 +43,9 @@ limit_help(void)
 " block limits that are currently being used for the specified user, group,\n"
 " or project.  The filesystem identified by the current path is modified.\n"

quota/edit.c limit_help(void) · line 51

Quoted 10 lines
quota/edit.c +3 -3
 " -d -- set the default values, used the first time a file is created\n"
-" -g -- modify group quota limits\n"
-" -p -- modify project quota limits\n"
-" -u -- modify user quota limits\n"
+" -g -- modify group quota limits, can't coexist with -p, -u\n"
+" -p -- modify project quota limits, can't coexist with -g, -u\n"
+" -u -- modify user quota limits, can't coexist with -g, -p\n"
 " The block limit values can be specified with a units suffix - accepted\n"
 " units are: k (kilobytes), m (megabytes), g (gigabytes), and t (terabytes).\n"
 " The user/group/project can be specified either by name or by number.\n"

Again, I think that if the help output specifies it as:

limit [-g|-p|-u] bsoft|bhard|isoft|ihard|rtbsoft|rtbhard=N -d|id|name -- modify quota limits

then you don't need to add "can't coexist ..." to later lines.

(this is also true for every command you've modified)

...

Quoted 19 lines
quota/edit.c +3 -3
@@ -282,13 +282,13 @@ limit_f(
 			flags |= DEFAULTS_FLAG;
 			break;
 		case 'g':
-			type = XFS_GROUP_QUOTA;
+			type |= XFS_GROUP_QUOTA;
 			break;
 		case 'p':
-			type = XFS_PROJ_QUOTA;
+			type |= XFS_PROJ_QUOTA;
 			break;
 		case 'u':
-			type = XFS_USER_QUOTA;
+			type |= XFS_USER_QUOTA;
 			break;
 		default:
 			return command_usage(&limit_cmd);
@@ -343,8 +343,13 @@ limit_f(
 

quota/edit.c limit_f( · line 352

Quoted 10 lines
quota/edit.c +6 -1
 	name = (flags & DEFAULTS_FLAG) ? "0" : argv[optind++];
 
-	if (!type)
+	if (!type) {
 		type = XFS_USER_QUOTA;
+	} else if (type != XFS_GROUP_QUOTA
+	           && type != XFS_PROJ_QUOTA
+	           && type != XFS_USER_QUOTA) {
+		return command_usage(&limit_cmd);
+	}

Nitpick, this would be a little cleaner as:

quota/edit.c limit_f( · line 352

Quoted 8 lines
quota/edit.c +6 -1
-	if (!type)
+	if (!type) {
 		type = XFS_USER_QUOTA;
+	} else if (type != XFS_GROUP_QUOTA &&
+	           type != XFS_PROJ_QUOTA &&
+	           type != XFS_USER_QUOTA) {
+		return command_usage(&limit_cmd);
+	}

... we often put the && or the || at the end like this. It just makes things line up nicely.

...

quota/edit.c edit_init(void) · line 709

Quoted 6 lines
quota/edit.c +1 -1
@@ -686,7 +706,7 @@ edit_init(void)
 	limit_cmd.argmin = 2;
 	limit_cmd.argmax = -1;
 	limit_cmd.args = \
-	_("[-gpu] bsoft|bhard|isoft|ihard|rtbsoft|rtbhard=N -d|id|name");
+	_("[-g|-p|-u] bsoft|bhard|isoft|ihard|rtbsoft|rtbhard=N -d|id|name");

yes, [-g|-p|-u] looks good.

Quoted 34 lines
quota/edit.c +3 -3
 	limit_cmd.oneline = _("modify quota limits");
 	limit_cmd.help = limit_help;
 
@@ -694,14 +714,14 @@ edit_init(void)
 	restore_cmd.cfunc = restore_f;
 	restore_cmd.argmin = 0;
 	restore_cmd.argmax = -1;
-	restore_cmd.args = _("[-gpu] [-f file]");
+	restore_cmd.args = _("[-g|-p|-u] [-f file]");
 	restore_cmd.oneline = _("restore quota limits from a backup file");
 
 	timer_cmd.name = "timer";
 	timer_cmd.cfunc = timer_f;
 	timer_cmd.argmin = 2;
 	timer_cmd.argmax = -1;
-	timer_cmd.args = _("[-bir] [-gpu] value");
+	timer_cmd.args = _("[-bir] [-g|-p|-u] value");
 	timer_cmd.oneline = _("set quota enforcement timeouts");
 	timer_cmd.help = timer_help;
 
@@ -709,7 +729,7 @@ edit_init(void)
 	warn_cmd.cfunc = warn_f;
 	warn_cmd.argmin = 2;
 	warn_cmd.argmax = -1;
-	warn_cmd.args = _("[-bir] [-gpu] value -d|id|name");
+	warn_cmd.args = _("[-bir] [-g|-p|-u] value -d|id|name");
 	warn_cmd.oneline = _("get/set enforcement warning counter");
 	warn_cmd.help = warn_help;
 
quota/quot.c +0 -0
index 9116e48..5588a25 100644

quota/quot.c quot_help(void) · line 67

Quoted 9 lines
quota/quot.c +3 -3
@@ -62,9 +62,9 @@ quot_help(void)
 "       total of all files greater than 500 kilobytes.\n"
 " -v -- display three columns containing the number of kilobytes not\n"
 "       accessed in the last 30, 60, and 90 days.\n"
-" -g -- display group summary\n"
-" -p -- display project summary\n"
-" -u -- display user summary\n"
+" -g -- display group summary, can't coexist with -p, -u\n"
+" -p -- display project summary, can't coexist with -g, -u\n"
+" -u -- display user summary, can't coexist with -g, -p\n"

again no need to re-state if you change the synopsis to make it clear; but please do change quot_cmd.args to show that they are exclusive:

- quot_cmd.args = _("[-bir] [-gpu] [-acv] [-f file]");
+ quot_cmd.args = _("[-bir] [-g|-p|-u] [-acv] [-f file]");

I think every command you changed might need to have the args fixed up like this, and then you do not have change the longer *_help text.

Thanks,
-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs