Re: [PATCH 1/5] xfs_quota: separate quota info acquisition into get_quota()

Christoph Hellwig
2022-04-06T17:38:20Z

On Tue, Mar 29, 2022 at 12:24:59AM +0200, Andrey Albershteyn wrote:
> Both report_mount() and dump_file() have identical code to get quota
> information. This could be used for further separation of the
> functions.
>
> Signed-off-by: Andrey Albershteyn <aalbersh@redhat.com>
> ---
> quota/report.c | 49 +++++++++++++++++++++++--------------------------
> 1 file changed, 23 insertions(+), 26 deletions(-)
>
> diff --git a/quota/report.c b/quota/report.c
> index 2eb5b5a9..97a89a92 100644
> --- a/quota/report.c
> +++ b/quota/report.c
> @@ -59,16 +59,15 @@ report_help(void)
> "\n"));
> }
>
> -static int
> -dump_file(
> - FILE *fp,
> +static int
> +get_quota(
> + fs_disk_quota_t *d,
> uint id,
> uint *oid,
> uint type,
> char *dev,
> int flags)
> {
> - fs_disk_quota_t d;
> int cmd;
>
> if (flags & GETNEXTQUOTA_FLAG)
> @@ -77,7 +76,7 @@ dump_file(
> cmd = XFS_GETQUOTA;
>
> /* Fall back silently if XFS_GETNEXTQUOTA fails, warn on XFS_GETQUOTA */
> - if (xfsquotactl(cmd, dev, type, id, (void *)&d) < 0) {
> + if (xfsquotactl(cmd, dev, type, id, (void *)d) < 0) {
> if (errno != ENOENT && errno != ENOSYS && errno != ESRCH &&
> cmd == XFS_GETQUOTA)
> perror("XFS_GETQUOTA");
> @@ -85,12 +84,29 @@ dump_file(
> }
>
> if (oid) {
> - *oid = d.d_id;
> + *oid = d->d_id;
> /* Did kernelspace wrap? */
> if (*oid < id)
> return 0;
> }
>
> + return 1;
> +}
> +
> +static int
> +dump_file(
> + FILE *fp,
> + uint id,
> + uint *oid,
> + uint type,
> + char *dev,
> + int flags)
> +{
> + fs_disk_quota_t d;
> +
> + if (!get_quota(&d, id, oid, type, dev, flags))

Tab instead of a space after the if here.

Also if you touch this anyway it might be worth to replace
fs_disk_quota_t with struct fs_disk_quota.

> + if (!get_quota(&d, id, oid, type, mount->fs_name, flags))

Same here.

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>