]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_quota: separate get_dquot() and dump_file()
authorAndrey Albershteyn <aalbersh@redhat.com>
Mon, 12 Sep 2022 14:32:37 +0000 (16:32 +0200)
committerCarlos Maiolino <cem@kernel.org>
Mon, 19 Sep 2022 14:45:43 +0000 (16:45 +0200)
Separate quota info acquisition from outputting it to file. This
allows upper functions to filter obtained info (e.g. within specific
ID range).

Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
quota/report.c

index 6994cba6f46975a3333443457c8f59a9bb239410..d5c6f84f087a53732d599207943671ba0dd5ed7c 100644 (file)
@@ -96,39 +96,31 @@ get_dquot(
 static int
 dump_file(
        FILE            *fp,
-       uint            id,
-       uint            *oid,
-       uint            type,
-       char            *dev,
-       int             flags)
+       struct fs_disk_quota *d,
+       char            *dev)
 {
-       struct fs_disk_quota d;
-
-       if (!get_dquot(&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)
+       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)
                return 1;
        fprintf(fp, "fs = %s\n", dev);
        /* this branch is for backward compatibility reasons */
-       if (d.d_rtb_softlimit || d.d_rtb_hardlimit)
+       if (d->d_rtb_softlimit || d->d_rtb_hardlimit)
                fprintf(fp, "%-10d %7llu %7llu %7llu %7llu %7llu %7llu\n",
-                       d.d_id,
-                       (unsigned long long)d.d_blk_softlimit,
-                       (unsigned long long)d.d_blk_hardlimit,
-                       (unsigned long long)d.d_ino_softlimit,
-                       (unsigned long long)d.d_ino_hardlimit,
-                       (unsigned long long)d.d_rtb_softlimit,
-                       (unsigned long long)d.d_rtb_hardlimit);
+                       d->d_id,
+                       (unsigned long long)d->d_blk_softlimit,
+                       (unsigned long long)d->d_blk_hardlimit,
+                       (unsigned long long)d->d_ino_softlimit,
+                       (unsigned long long)d->d_ino_hardlimit,
+                       (unsigned long long)d->d_rtb_softlimit,
+                       (unsigned long long)d->d_rtb_hardlimit);
        else
                fprintf(fp, "%-10d %7llu %7llu %7llu %7llu\n",
-                       d.d_id,
-                       (unsigned long long)d.d_blk_softlimit,
-                       (unsigned long long)d.d_blk_hardlimit,
-                       (unsigned long long)d.d_ino_softlimit,
-                       (unsigned long long)d.d_ino_hardlimit);
+                       d->d_id,
+                       (unsigned long long)d->d_blk_softlimit,
+                       (unsigned long long)d->d_blk_hardlimit,
+                       (unsigned long long)d->d_ino_softlimit,
+                       (unsigned long long)d->d_ino_hardlimit);
 
        return 1;
 }
@@ -142,6 +134,7 @@ dump_limits_any_type(
        uint            upper)
 {
        fs_path_t       *mount;
+       struct fs_disk_quota d;
        uint            id = 0, oid;
 
        if ((mount = fs_table_lookup(dir, FS_MOUNT_POINT)) == NULL) {
@@ -153,46 +146,57 @@ dump_limits_any_type(
 
        /* Range was specified; query everything in it */
        if (upper) {
-               for (id = lower; id <= upper; id++)
-                       dump_file(fp, id, NULL, type, mount->fs_name, 0);
+               for (id = lower; id <= upper; id++) {
+                       get_dquot(&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, id, &oid, type, mount->fs_name, GETNEXTQUOTA_FLAG)) {
+       if (get_dquot(&d, id, &oid, type, mount->fs_name, GETNEXTQUOTA_FLAG)) {
+               dump_file(fp, &d, mount->fs_name);
                id = oid + 1;
-               while (dump_file(fp, id, &oid, type, mount->fs_name,
-                                GETNEXTQUOTA_FLAG))
+               while (get_dquot(&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, g->gr_gid, NULL, type,
-                                         mount->fs_name, 0);
+                       while ((g = getgrent()) != NULL) {
+                               get_dquot(&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, p->pr_prid, NULL, type,
-                                         mount->fs_name, 0);
+                       while ((p = getprent()) != NULL) {
+                               get_dquot(&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, u->pw_uid, NULL, type,
-                                         mount->fs_name, 0);
+                       while ((u = getpwent()) != NULL) {
+                               get_dquot(&d, u->pw_uid, NULL, type,
+                                               mount->fs_name, 0);
+                               dump_file(fp, &d, mount->fs_name);
+                       }
                        endpwent();
                        break;
                }