[PATCH 3/3] xfs_quota: use Q_XGETQUOTA2 for repquota
Eric Sandeen
sandeen at sandeen.net
Fri Jan 8 12:57:55 CST 2016
Rather than a loop over getpwnam() etc, use the Q_XGETQUOTA2
command to iterate through all active quotas.
If Q_XGETQUOTA2 fails, go back to the old way.
Signed-off-by: Eric Sandeen <sandeen at redhat.com>
---
quota/quota.h | 1 +
quota/report.c | 41 +++++++++++++++++++++++++++++++++++++----
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/quota/quota.h b/quota/quota.h
index 8b80029..dec8330 100644
--- a/quota/quota.h
+++ b/quota/quota.h
@@ -74,6 +74,7 @@ enum {
DEFAULTS_FLAG = 0x0100, /* use value as a default */
ABSOLUTE_FLAG = 0x0200, /* absolute time, not related to now */
NO_LOOKUP_FLAG = 0x0400, /* skip name lookups, just report ID */
+ GETQUOTA2_FLAG = 0x0800, /* use getquota2 quotactl */
};
/*
diff --git a/quota/report.c b/quota/report.c
index 746b04a..093155b 100644
--- a/quota/report.c
+++ b/quota/report.c
@@ -302,8 +302,14 @@ report_mount(
char c[8], h[8], s[8];
uint qflags;
int count;
+ int cmd;
- if (xfsquotactl(XFS_GETQUOTA, dev, type, id, (void *)&d) < 0) {
+ if (flags & GETQUOTA2_FLAG)
+ cmd = XFS_GETQUOTA2;
+ else
+ cmd = XFS_GETQUOTA;
+
+ if (xfsquotactl(cmd, dev, type, id, (void *)&d) < 0) {
if (errno != ENOENT && errno != ENOSYS && errno != ESRCH)
perror("XFS_GETQUOTA");
return 0;
@@ -425,7 +431,7 @@ report_user_mount(
uint flags)
{
struct passwd *u;
- uint id;
+ uint id = 0, oid;
if (upper) { /* identifier range specified */
for (id = lower; id <= upper; id++) {
@@ -433,6 +439,15 @@ report_user_mount(
form, XFS_USER_QUOTA, mount, flags))
flags |= NO_HEADER_FLAG;
}
+ } else if (report_mount(fp, id, NULL, &oid, form,
+ XFS_USER_QUOTA, mount, flags|GETQUOTA2_FLAG)) {
+ id = oid + 1;
+ flags |= GETQUOTA2_FLAG;
+ flags |= NO_HEADER_FLAG;
+ while (report_mount(fp, id, NULL, &oid, form, XFS_USER_QUOTA,
+ mount, flags)) {
+ id = oid + 1;
+ }
} else {
setpwent();
while ((u = getpwent()) != NULL) {
@@ -457,7 +472,7 @@ report_group_mount(
uint flags)
{
struct group *g;
- uint id;
+ uint id = 0, oid;
if (upper) { /* identifier range specified */
for (id = lower; id <= upper; id++) {
@@ -465,6 +480,15 @@ report_group_mount(
form, XFS_GROUP_QUOTA, mount, flags))
flags |= NO_HEADER_FLAG;
}
+ } else if (report_mount(fp, id, NULL, &oid, form,
+ XFS_GROUP_QUOTA, mount, flags|GETQUOTA2_FLAG)) {
+ id = oid + 1;
+ flags |= GETQUOTA2_FLAG;
+ flags |= NO_HEADER_FLAG;
+ while (report_mount(fp, id, NULL, &oid, form, XFS_GROUP_QUOTA,
+ mount, flags)) {
+ id = oid + 1;
+ }
} else {
setgrent();
while ((g = getgrent()) != NULL) {
@@ -488,7 +512,7 @@ report_project_mount(
uint flags)
{
fs_project_t *p;
- uint id;
+ uint id = 0, oid;
if (upper) { /* identifier range specified */
for (id = lower; id <= upper; id++) {
@@ -496,6 +520,15 @@ report_project_mount(
form, XFS_PROJ_QUOTA, mount, flags))
flags |= NO_HEADER_FLAG;
}
+ } else if (report_mount(fp, id, NULL, &oid, form,
+ XFS_PROJ_QUOTA, mount, flags|GETQUOTA2_FLAG)) {
+ id = oid + 1;
+ flags |= GETQUOTA2_FLAG;
+ flags |= NO_HEADER_FLAG;
+ while (report_mount(fp, id, NULL, &oid, form, XFS_PROJ_QUOTA,
+ mount, flags)) {
+ id = oid + 1;
+ }
} else {
setprent();
while ((p = getprent()) != NULL) {
--
1.7.1
More information about the xfs
mailing list