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

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