diff mbox series

[3/3] xfsprogs: xfs_quota state command should report ugp grace times

Message ID 20200715201253.171356-4-billodo@redhat.com (mailing list archive)
State Superseded
Headers show
Series xfsprogs: xfs_quota error message and state reporting improvement | expand

Commit Message

Bill O'Donnell July 15, 2020, 8:12 p.m. UTC
Since grace periods are now supported for three quota types (ugp),
modify xfs_quota state command to report times for all three.
Add a helper function for stat reporting.

Signed-off-by: Bill O'Donnell <billodo@redhat.com>
---
 quota/state.c | 108 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 80 insertions(+), 28 deletions(-)

Comments

Eric Sandeen July 15, 2020, 8:33 p.m. UTC | #1
On 7/15/20 1:12 PM, Bill O'Donnell wrote:
> Since grace periods are now supported for three quota types (ugp),
> modify xfs_quota state command to report times for all three.
> Add a helper function for stat reporting.
> 
> Signed-off-by: Bill O'Donnell <billodo@redhat.com>

...

> +	if (type & XFS_GROUP_QUOTA) {
> +		if (xfsquotactl(XFS_GETQSTATV, dev, XFS_GROUP_QUOTA,
> +				0, (void *)&sv) < 0) {
> +			if (xfsquotactl(XFS_GETQSTAT, dev, XFS_GROUP_QUOTA,
> +					0, (void *)&s) < 0) {
> +				if (flags & VERBOSE_FLAG)
> +					fprintf(fp,
> +						_("%s quota are not enabled on %s\n"),
> +						type_to_string(XFS_GROUP_QUOTA),
> +						dev);
> +				return;
> +			}
> +			state_stat_to_statv(&s, &sv);
> +		}

At first glance, can't all of the above be moved into the helper as well?

Maybe something like this (needs fixing up for sure)

static void
state_quotafile_stat(
	FILE			*fp,
	uint			type,
	struct fs_path		*mount,
	struct fs_quota_statv	*sv)
{
	bool 			accounting, enforcing;
	struct fs_qfilestat	*qsv;

	switch(type) {
	case XFS_USER_QUOTA:
		qsv = &sv->qs_uquota;
		accounting = sv->qs_flags & XFS_QUOTA_UDQ_ACCT;
		enforcing = sv->qs_flags & XFS_QUOTA_UDQ_ENFD;		
		break;
	case XFS_GROUP_QUOTA:
		...
		break;
...
	default:
		/* defensive check goes here */
	}

	if (xfsquotactl(XFS_GETQSTATV, dev, type, 0, (void *)&sv) < 0) {
		if (xfsquotactl(XFS_GETQSTAT, dev, type, 0, (void *)&s) < 0) {
			if (flags & VERBOSE_FLAG)
				fprintf(fp,
					_("%s quota are not enabled on %s\n"),
					type_to_string(type), dev);
			return;
		}
		state_stat_to_statv(&s, &sv)
	}	

	state_qfilestat(fp, mount, type, qsv, accounting, enforcing);

	state_timelimit(fp, XFS_BLOCK_QUOTA, sv->qs_btimelimit);
	state_warnlimit(fp, XFS_BLOCK_QUOTA, sv->qs_bwarnlimit);

	state_timelimit(fp, XFS_INODE_QUOTA, sv->qs_itimelimit);
	state_warnlimit(fp, XFS_INODE_QUOTA, sv->qs_iwarnlimit);

	state_timelimit(fp, XFS_RTBLOCK_QUOTA, sv->qs_rtbtimelimit);
}


Thanks,
-Eric
Bill O'Donnell July 15, 2020, 8:44 p.m. UTC | #2
On Wed, Jul 15, 2020 at 01:33:29PM -0700, Eric Sandeen wrote:
> On 7/15/20 1:12 PM, Bill O'Donnell wrote:
> > Since grace periods are now supported for three quota types (ugp),
> > modify xfs_quota state command to report times for all three.
> > Add a helper function for stat reporting.
> > 
> > Signed-off-by: Bill O'Donnell <billodo@redhat.com>
> 
> ...
> 
> > +	if (type & XFS_GROUP_QUOTA) {
> > +		if (xfsquotactl(XFS_GETQSTATV, dev, XFS_GROUP_QUOTA,
> > +				0, (void *)&sv) < 0) {
> > +			if (xfsquotactl(XFS_GETQSTAT, dev, XFS_GROUP_QUOTA,
> > +					0, (void *)&s) < 0) {
> > +				if (flags & VERBOSE_FLAG)
> > +					fprintf(fp,
> > +						_("%s quota are not enabled on %s\n"),
> > +						type_to_string(XFS_GROUP_QUOTA),
> > +						dev);
> > +				return;
> > +			}
> > +			state_stat_to_statv(&s, &sv);
> > +		}
> 
> At first glance, can't all of the above be moved into the helper as well?
> 
> Maybe something like this (needs fixing up for sure)

Yeah, I should further reduce the redundancy.
Thanks-
Bill


> 
> static void
> state_quotafile_stat(
> 	FILE			*fp,
> 	uint			type,
> 	struct fs_path		*mount,
> 	struct fs_quota_statv	*sv)
> {
> 	bool 			accounting, enforcing;
> 	struct fs_qfilestat	*qsv;
> 
> 	switch(type) {
> 	case XFS_USER_QUOTA:
> 		qsv = &sv->qs_uquota;
> 		accounting = sv->qs_flags & XFS_QUOTA_UDQ_ACCT;
> 		enforcing = sv->qs_flags & XFS_QUOTA_UDQ_ENFD;		
> 		break;
> 	case XFS_GROUP_QUOTA:
> 		...
> 		break;
> ...
> 	default:
> 		/* defensive check goes here */
> 	}
> 
> 	if (xfsquotactl(XFS_GETQSTATV, dev, type, 0, (void *)&sv) < 0) {
> 		if (xfsquotactl(XFS_GETQSTAT, dev, type, 0, (void *)&s) < 0) {
> 			if (flags & VERBOSE_FLAG)
> 				fprintf(fp,
> 					_("%s quota are not enabled on %s\n"),
> 					type_to_string(type), dev);
> 			return;
> 		}
> 		state_stat_to_statv(&s, &sv)
> 	}	
> 
> 	state_qfilestat(fp, mount, type, qsv, accounting, enforcing);
> 
> 	state_timelimit(fp, XFS_BLOCK_QUOTA, sv->qs_btimelimit);
> 	state_warnlimit(fp, XFS_BLOCK_QUOTA, sv->qs_bwarnlimit);
> 
> 	state_timelimit(fp, XFS_INODE_QUOTA, sv->qs_itimelimit);
> 	state_warnlimit(fp, XFS_INODE_QUOTA, sv->qs_iwarnlimit);
> 
> 	state_timelimit(fp, XFS_RTBLOCK_QUOTA, sv->qs_rtbtimelimit);
> }
> 
> 
> Thanks,
> -Eric
>
diff mbox series

Patch

diff --git a/quota/state.c b/quota/state.c
index 1627181d..5aadcca2 100644
--- a/quota/state.c
+++ b/quota/state.c
@@ -190,6 +190,39 @@  state_stat_to_statv(
 	}
 }
 
+static void
+state_quotafile_stat(
+	FILE			*fp,
+	uint			type,
+	struct fs_path		*mount,
+	struct fs_quota_statv	*sv)
+{
+	switch(type) {
+	case XFS_USER_QUOTA:
+		state_qfilestat(fp, mount, XFS_USER_QUOTA, &sv->qs_uquota,
+				sv->qs_flags & XFS_QUOTA_UDQ_ACCT,
+				sv->qs_flags & XFS_QUOTA_UDQ_ENFD);
+		break;
+	case XFS_GROUP_QUOTA:
+		state_qfilestat(fp, mount, XFS_GROUP_QUOTA, &sv->qs_gquota,
+				sv->qs_flags & XFS_QUOTA_GDQ_ACCT,
+				sv->qs_flags & XFS_QUOTA_GDQ_ENFD);
+		break;
+	case XFS_PROJ_QUOTA:
+		state_qfilestat(fp, mount, XFS_PROJ_QUOTA, &sv->qs_pquota,
+				sv->qs_flags & XFS_QUOTA_PDQ_ACCT,
+				sv->qs_flags & XFS_QUOTA_PDQ_ENFD);
+		break;
+	}
+	state_timelimit(fp, XFS_BLOCK_QUOTA, sv->qs_btimelimit);
+	state_warnlimit(fp, XFS_BLOCK_QUOTA, sv->qs_bwarnlimit);
+
+	state_timelimit(fp, XFS_INODE_QUOTA, sv->qs_itimelimit);
+	state_warnlimit(fp, XFS_INODE_QUOTA, sv->qs_iwarnlimit);
+
+	state_timelimit(fp, XFS_RTBLOCK_QUOTA, sv->qs_rtbtimelimit);
+}
+
 static void
 state_quotafile_mount(
 	FILE			*fp,
@@ -203,37 +236,56 @@  state_quotafile_mount(
 
 	sv.qs_version = FS_QSTATV_VERSION1;
 
-	if (xfsquotactl(XFS_GETQSTATV, dev, type, 0, (void *)&sv) < 0) {
-		if (xfsquotactl(XFS_GETQSTAT, dev, type, 0, (void *)&s) < 0) {
-			if (flags & VERBOSE_FLAG)
-				fprintf(fp,
-					_("%s quota are not enabled on %s\n"),
-					type_to_string(type), dev);
-			return;
+	if (type & XFS_USER_QUOTA) {
+		if (xfsquotactl(XFS_GETQSTATV, dev, XFS_USER_QUOTA,
+				0, (void *)&sv) < 0) {
+			if (xfsquotactl(XFS_GETQSTAT, dev, XFS_USER_QUOTA,
+					0, (void *)&s) < 0) {
+				if (flags & VERBOSE_FLAG)
+					fprintf(fp,
+						_("%s quota are not enabled on %s\n"),
+						type_to_string(XFS_USER_QUOTA),
+						dev);
+				return;
+			}
+			state_stat_to_statv(&s, &sv);
 		}
-		state_stat_to_statv(&s, &sv);
+		state_quotafile_stat(fp, XFS_USER_QUOTA, mount, &sv);
 	}
 
-	if (type & XFS_USER_QUOTA)
-		state_qfilestat(fp, mount, XFS_USER_QUOTA, &sv.qs_uquota,
-				sv.qs_flags & XFS_QUOTA_UDQ_ACCT,
-				sv.qs_flags & XFS_QUOTA_UDQ_ENFD);
-	if (type & XFS_GROUP_QUOTA)
-		state_qfilestat(fp, mount, XFS_GROUP_QUOTA, &sv.qs_gquota,
-				sv.qs_flags & XFS_QUOTA_GDQ_ACCT,
-				sv.qs_flags & XFS_QUOTA_GDQ_ENFD);
-	if (type & XFS_PROJ_QUOTA)
-		state_qfilestat(fp, mount, XFS_PROJ_QUOTA, &sv.qs_pquota,
-				sv.qs_flags & XFS_QUOTA_PDQ_ACCT,
-				sv.qs_flags & XFS_QUOTA_PDQ_ENFD);
-
-	state_timelimit(fp, XFS_BLOCK_QUOTA, sv.qs_btimelimit);
-	state_warnlimit(fp, XFS_BLOCK_QUOTA, sv.qs_bwarnlimit);
-
-	state_timelimit(fp, XFS_INODE_QUOTA, sv.qs_itimelimit);
-	state_warnlimit(fp, XFS_INODE_QUOTA, sv.qs_iwarnlimit);
-
-	state_timelimit(fp, XFS_RTBLOCK_QUOTA, sv.qs_rtbtimelimit);
+	if (type & XFS_GROUP_QUOTA) {
+		if (xfsquotactl(XFS_GETQSTATV, dev, XFS_GROUP_QUOTA,
+				0, (void *)&sv) < 0) {
+			if (xfsquotactl(XFS_GETQSTAT, dev, XFS_GROUP_QUOTA,
+					0, (void *)&s) < 0) {
+				if (flags & VERBOSE_FLAG)
+					fprintf(fp,
+						_("%s quota are not enabled on %s\n"),
+						type_to_string(XFS_GROUP_QUOTA),
+						dev);
+				return;
+			}
+			state_stat_to_statv(&s, &sv);
+		}
+		state_quotafile_stat(fp, XFS_GROUP_QUOTA, mount, &sv);
+	}
+
+	if (type & XFS_PROJ_QUOTA) {
+		if (xfsquotactl(XFS_GETQSTATV, dev, XFS_PROJ_QUOTA,
+				0, (void *)&sv) < 0) {
+			if (xfsquotactl(XFS_GETQSTAT, dev, XFS_PROJ_QUOTA,
+					0, (void *)&s) < 0) {
+				if (flags & VERBOSE_FLAG)
+					fprintf(fp,
+						_("%s quota are not enabled on %s\n"),
+						type_to_string(XFS_PROJ_QUOTA),
+						dev);
+				return;
+			}
+			state_stat_to_statv(&s, &sv);
+		}
+		state_quotafile_stat(fp, XFS_PROJ_QUOTA, mount, &sv);
+	}
 }
 
 static void