Blame SOURCES/xfsprogs-5.8.0-xfs_quota-command-error-message-improvement.patch

4bf432
From ca42fa70929e88781e7daeee4cf4588adb834661 Mon Sep 17 00:00:00 2001
4bf432
From: Bill O'Donnell <billodo@redhat.com>
4bf432
Date: Mon, 24 Aug 2020 13:23:23 -0400
4bf432
Subject: [PATCH] xfs_quota: command error message improvement
4bf432
4bf432
Make the error messages for rudimentary xfs_quota commands
4bf432
(off, enable, disable) more user friendly, instead of the
4bf432
terse sys error outputs.
4bf432
4bf432
Signed-off-by: Bill O'Donnell <billodo@redhat.com>
4bf432
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
4bf432
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
4bf432
---
4bf432
 quota/state.c | 32 ++++++++++++++++++++++++++------
4bf432
 1 file changed, 26 insertions(+), 6 deletions(-)
4bf432
4bf432
diff --git a/quota/state.c b/quota/state.c
4bf432
index 8f9718f1..7a595fc6 100644
4bf432
--- a/quota/state.c
4bf432
+++ b/quota/state.c
4bf432
@@ -306,8 +306,16 @@ enable_enforcement(
4bf432
 		return;
4bf432
 	}
4bf432
 	dir = mount->fs_name;
4bf432
-	if (xfsquotactl(XFS_QUOTAON, dir, type, 0, (void *)&qflags) < 0)
4bf432
-		perror("XFS_QUOTAON");
4bf432
+	if (xfsquotactl(XFS_QUOTAON, dir, type, 0, (void *)&qflags) < 0) {
4bf432
+		if (errno == EEXIST)
4bf432
+			fprintf(stderr,
4bf432
+				_("Quota enforcement already enabled.\n"));
4bf432
+		else if (errno == EINVAL || errno == ENOSYS)
4bf432
+			fprintf(stderr,
4bf432
+				_("Can't enable enforcement when quota off.\n"));
4bf432
+		else
4bf432
+			perror("XFS_QUOTAON");
4bf432
+	}
4bf432
 	else if (flags & VERBOSE_FLAG)
4bf432
 		state_quotafile_mount(stdout, type, mount, flags);
4bf432
 }
4bf432
@@ -328,8 +336,16 @@ disable_enforcement(
4bf432
 		return;
4bf432
 	}
4bf432
 	dir = mount->fs_name;
4bf432
-	if (xfsquotactl(XFS_QUOTAOFF, dir, type, 0, (void *)&qflags) < 0)
4bf432
-		perror("XFS_QUOTAOFF");
4bf432
+	if (xfsquotactl(XFS_QUOTAOFF, dir, type, 0, (void *)&qflags) < 0) {
4bf432
+		if (errno == EEXIST)
4bf432
+			fprintf(stderr,
4bf432
+				_("Quota enforcement already disabled.\n"));
4bf432
+		else if (errno == EINVAL || errno == ENOSYS)
4bf432
+			fprintf(stderr,
4bf432
+				_("Can't disable enforcement when quota off.\n"));
4bf432
+		else
4bf432
+			perror("XFS_QUOTAOFF");
4bf432
+	}
4bf432
 	else if (flags & VERBOSE_FLAG)
4bf432
 		state_quotafile_mount(stdout, type, mount, flags);
4bf432
 }
4bf432
@@ -350,8 +366,12 @@ quotaoff(
4bf432
 		return;
4bf432
 	}
4bf432
 	dir = mount->fs_name;
4bf432
-	if (xfsquotactl(XFS_QUOTAOFF, dir, type, 0, (void *)&qflags) < 0)
4bf432
-		perror("XFS_QUOTAOFF");
4bf432
+	if (xfsquotactl(XFS_QUOTAOFF, dir, type, 0, (void *)&qflags) < 0) {
4bf432
+		if (errno == EEXIST || errno == ENOSYS)
4bf432
+			fprintf(stderr, _("Quota already off.\n"));
4bf432
+		else
4bf432
+			perror("XFS_QUOTAOFF");
4bf432
+	}
4bf432
 	else if (flags & VERBOSE_FLAG)
4bf432
 		state_quotafile_mount(stdout, type, mount, flags);
4bf432
 }
4bf432
-- 
4bf432
2.31.1
4bf432