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

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