Blame SOURCES/xfsprogs-5.4.0-mkfs-tidy-up-discard-notifications.patch

212ea0
From 2383d7c5cf20efcff75cb29ca3e02cfbe1bf2209 Mon Sep 17 00:00:00 2001
212ea0
From: Eric Sandeen <sandeen@redhat.com>
212ea0
Date: Tue, 17 Dec 2019 16:52:39 -0500
212ea0
Subject: [PATCH] mkfs: tidy up discard notifications
212ea0
212ea0
Only notify user of discard operations if the first one succeeds,
212ea0
and be sure to print a trailing newline if we stop early.
212ea0
212ea0
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
212ea0
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
212ea0
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
212ea0
---
212ea0
 mkfs/xfs_mkfs.c | 16 ++++++++++------
212ea0
 1 file changed, 10 insertions(+), 6 deletions(-)
212ea0
212ea0
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
212ea0
index 4bfdebf6..606f79da 100644
212ea0
--- a/mkfs/xfs_mkfs.c
212ea0
+++ b/mkfs/xfs_mkfs.c
212ea0
@@ -1251,10 +1251,6 @@ discard_blocks(dev_t dev, uint64_t nsectors, int quiet)
212ea0
 	fd = libxfs_device_to_fd(dev);
212ea0
 	if (fd <= 0)
212ea0
 		return;
212ea0
-	if (!quiet) {
212ea0
-		printf("Discarding blocks...");
212ea0
-		fflush(stdout);
212ea0
-	}
212ea0
 
212ea0
 	/* The block discarding happens in smaller batches so it can be
212ea0
 	 * interrupted prematurely
212ea0
@@ -1267,12 +1263,20 @@ discard_blocks(dev_t dev, uint64_t nsectors, int quiet)
212ea0
 		 * not necessary for the mkfs functionality but just an
212ea0
 		 * optimization. However we should stop on error.
212ea0
 		 */
212ea0
-		if (platform_discard_blocks(fd, offset, tmp_step))
212ea0
+		if (platform_discard_blocks(fd, offset, tmp_step) == 0) {
212ea0
+			if (offset == 0 && !quiet) {
212ea0
+				printf("Discarding blocks...");
212ea0
+				fflush(stdout);
212ea0
+			}
212ea0
+		} else {
212ea0
+			if (offset > 0 && !quiet)
212ea0
+				printf("\n");
212ea0
 			return;
212ea0
+		}
212ea0
 
212ea0
 		offset += tmp_step;
212ea0
 	}
212ea0
-	if (!quiet)
212ea0
+	if (offset > 0 && !quiet)
212ea0
 		printf("Done.\n");
212ea0
 }
212ea0
 
212ea0
-- 
212ea0
2.17.0
212ea0