[PATCH 3/5] xfs_quota: split get_quota() and report_mount()/dump_file()

Andrey Albershteyn
2022-03-28T22:27:09Z

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
---
quota/report.c | 134 ++++++++++++++++++++++++++++---------------------
1 file changed, 78 insertions(+), 56 deletions(-)

diff --git a/quota/report.c b/quota/report.c
index 0462ce97..14b7f458 100644
--- a/quota/report.c
+++ b/quota/report.c
@@ -97,15 +97,8 @@ static int
dump_file(
FILE *fp,
fs_disk_quota_t *d,
- uint id,
- uint *oid,
- uint type,
- char *dev,
- int flags)
+ char *dev)
{
- if (!get_quota(d, id, oid, type, dev, flags))
- return 0;
-
if (!d->d_blk_softlimit && !d->d_blk_hardlimit &&
!d->d_ino_softlimit && !d->d_ino_hardlimit &&
!d->d_rtb_softlimit && !d->d_rtb_hardlimit)
@@ -153,46 +146,54 @@ dump_limits_any_type(

/* Range was specified; query everything in it */
if (upper) {
- for (id = lower; id <= upper; id++)
- dump_file(fp, &d, id, NULL, type, mount->fs_name, 0);
+ for (id = lower; id <= upper; id++) {
+ get_quota(&d, id, &oid, type, mount->fs_name, 0);
+ dump_file(fp, &d, mount->fs_name);
+ }
return;
}

/* Use GETNEXTQUOTA if it's available */
- if (dump_file(fp, &d, id, &oid, type, mount->fs_name, GETNEXTQUOTA_FLAG)) {
+ if (get_quota(&d, id, &oid, type, mount->fs_name, GETNEXTQUOTA_FLAG)) {
+ dump_file(fp, &d, mount->fs_name);
id = oid + 1;
- while (dump_file(fp, &d, id, &oid, type, mount->fs_name,
- GETNEXTQUOTA_FLAG))
+ while (get_quota(&d, id, &oid, type, mount->fs_name,
+ GETNEXTQUOTA_FLAG)) {
+ dump_file(fp, &d, mount->fs_name);
id = oid + 1;
+ }
return;
- }
+ }

/* Otherwise fall back to iterating over each uid/gid/prjid */
switch (type) {
case XFS_GROUP_QUOTA: {
struct group *g;
setgrent();
- while ((g = getgrent()) != NULL)
- dump_file(fp, &d, g->gr_gid, NULL, type,
- mount->fs_name, 0);
+ while ((g = getgrent()) != NULL) {
+ get_quota(&d, g->gr_gid, NULL, type, mount->fs_name, 0);
+ dump_file(fp, &d, mount->fs_name);
+ }
endgrent();
break;
}
case XFS_PROJ_QUOTA: {
struct fs_project *p;
setprent();
- while ((p = getprent()) != NULL)
- dump_file(fp, &d, p->pr_prid, NULL, type,
- mount->fs_name, 0);
+ while ((p = getprent()) != NULL) {
+ get_quota(&d, p->pr_prid, NULL, type, mount->fs_name, 0);
+ dump_file(fp, &d, mount->fs_name);
+ }
endprent();
break;
}
case XFS_USER_QUOTA: {
struct passwd *u;
setpwent();
- while ((u = getpwent()) != NULL)
- dump_file(fp, &d, u->pw_uid, NULL, type,
- mount->fs_name, 0);
+ while ((u = getpwent()) != NULL) {
+ get_quota(&d, u->pw_uid, NULL, type, mount->fs_name, 0);
+ dump_file(fp, &d, mount->fs_name);
+ }
endpwent();
break;
}
@@ -336,9 +337,7 @@ static int
report_mount(
FILE *fp,
fs_disk_quota_t *d,
- uint32_t id,
char *name,
- uint32_t *oid,
uint form,
uint type,
fs_path_t *mount,
@@ -349,9 +348,6 @@ report_mount(
uint qflags;
int count;

- if (!get_quota(d, id, oid, type, mount->fs_name, flags))
- return 0;
-
if (flags & TERSE_FLAG) {
count = 0;
if ((form & XFS_BLOCK_QUOTA) && d->d_bcount)
@@ -477,26 +473,35 @@ report_user_mount(

if (upper) { /* identifier range specified */
for (id = lower; id <= upper; id++) {
- if (report_mount(fp, &d, id, NULL, NULL,
- form, XFS_USER_QUOTA, mount, flags))
+ if (get_quota(&d, id, NULL, XFS_USER_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, NULL, form, XFS_USER_QUOTA, mount,
+ flags);
flags |= NO_HEADER_FLAG;
+ }
}
- } else if (report_mount(fp, &d, id, NULL, &oid, form,
- XFS_USER_QUOTA, mount,
+ } else if (get_quota(&d, id, &oid, XFS_USER_QUOTA, mount->fs_name,
flags|GETNEXTQUOTA_FLAG)) {
+ report_mount(fp, &d, NULL, form, XFS_USER_QUOTA, mount,
+ flags|GETNEXTQUOTA_FLAG);
id = oid + 1;
flags |= GETNEXTQUOTA_FLAG;
flags |= NO_HEADER_FLAG;
- while (report_mount(fp, &d, id, NULL, &oid, form, XFS_USER_QUOTA,
- mount, flags)) {
+ while (get_quota(&d, id, &oid, XFS_USER_QUOTA, mount->fs_name,
+ flags)) {
+ report_mount(fp, &d, NULL, form, XFS_USER_QUOTA,
+ mount, flags);
id = oid + 1;
}
} else {
setpwent();
while ((u = getpwent()) != NULL) {
- if (report_mount(fp, &d, u->pw_uid, u->pw_name, NULL,
- form, XFS_USER_QUOTA, mount, flags))
+ if (get_quota(&d, u->pw_uid, NULL, XFS_USER_QUOTA, mount->fs_name,
+ flags)) {
+ report_mount(fp, &d, u->pw_name, form, XFS_USER_QUOTA, mount,
+ flags);
flags |= NO_HEADER_FLAG;
+ }
}
endpwent();
}
@@ -520,26 +525,34 @@ report_group_mount(

if (upper) { /* identifier range specified */
for (id = lower; id <= upper; id++) {
- if (report_mount(fp, &d, id, NULL, NULL,
- form, XFS_GROUP_QUOTA, mount, flags))
+ if (get_quota(&d, id, NULL, XFS_GROUP_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, NULL, form, XFS_GROUP_QUOTA, mount, flags);
flags |= NO_HEADER_FLAG;
+ }
}
- } else if (report_mount(fp, &d, id, NULL, &oid, form,
- XFS_GROUP_QUOTA, mount,
- flags|GETNEXTQUOTA_FLAG)) {
+ } else if (get_quota(&d, id, &oid, XFS_GROUP_QUOTA,
+ mount->fs_name, flags|GETNEXTQUOTA_FLAG)) {
+ report_mount(fp, &d, NULL, form, XFS_GROUP_QUOTA, mount,
+ flags|GETNEXTQUOTA_FLAG);
id = oid + 1;
flags |= GETNEXTQUOTA_FLAG;
flags |= NO_HEADER_FLAG;
- while (report_mount(fp, &d, id, NULL, &oid, form, XFS_GROUP_QUOTA,
- mount, flags)) {
+ while (get_quota(&d, id, &oid, XFS_GROUP_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, NULL, form, XFS_GROUP_QUOTA, mount,
+ flags);
id = oid + 1;
}
} else {
setgrent();
while ((g = getgrent()) != NULL) {
- if (report_mount(fp, &d, g->gr_gid, g->gr_name, NULL,
- form, XFS_GROUP_QUOTA, mount, flags))
+ if (get_quota(&d, g->gr_gid, NULL, XFS_GROUP_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, g->gr_name, form,
+ XFS_GROUP_QUOTA, mount, flags);
flags |= NO_HEADER_FLAG;
+ }
}
}
if (flags & NO_HEADER_FLAG)
@@ -562,18 +575,22 @@ report_project_mount(

if (upper) { /* identifier range specified */
for (id = lower; id <= upper; id++) {
- if (report_mount(fp, &d, id, NULL, NULL,
- form, XFS_PROJ_QUOTA, mount, flags))
+ if (get_quota(&d, id, NULL, XFS_PROJ_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, NULL, form, XFS_PROJ_QUOTA, mount, flags);
flags |= NO_HEADER_FLAG;
+ }
}
- } else if (report_mount(fp, &d, id, NULL, &oid, form,
- XFS_PROJ_QUOTA, mount,
- flags|GETNEXTQUOTA_FLAG)) {
+ } else if (get_quota(&d, id, &oid, XFS_PROJ_QUOTA,
+ mount->fs_name, flags|GETNEXTQUOTA_FLAG)) {
+ report_mount(fp, &d, NULL, form, XFS_PROJ_QUOTA, mount,
+ flags|GETNEXTQUOTA_FLAG);
id = oid + 1;
flags |= GETNEXTQUOTA_FLAG;
flags |= NO_HEADER_FLAG;
- while (report_mount(fp, &d, id, NULL, &oid, form, XFS_PROJ_QUOTA,
- mount, flags)) {
+ while (get_quota(&d, id, &oid, XFS_PROJ_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, NULL, form, XFS_PROJ_QUOTA, mount, flags);
id = oid + 1;
}
} else {
@@ -582,16 +599,21 @@ report_project_mount(
* Print default project quota, even if projid 0
* isn't defined
*/
- if (report_mount(fp, &d, 0, NULL, NULL,
- form, XFS_PROJ_QUOTA, mount, flags))
+ if (get_quota(&d, 0, NULL, XFS_PROJ_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, NULL, form, XFS_PROJ_QUOTA, mount, flags);
flags |= NO_HEADER_FLAG;
+ }
}

setprent();
while ((p = getprent()) != NULL) {
- if (report_mount(fp, &d, p->pr_prid, p->pr_name, NULL,
- form, XFS_PROJ_QUOTA, mount, flags))
+ if (get_quota(&d, p->pr_prid, NULL, XFS_PROJ_QUOTA,
+ mount->fs_name, flags)) {
+ report_mount(fp, &d, p->pr_name, form, XFS_PROJ_QUOTA, mount,
+ flags);
flags |= NO_HEADER_FLAG;
+ }
}
endprent();
}
--
2.27.0