]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: tidy up discard notifications
authorEric Sandeen <sandeen@redhat.com>
Tue, 17 Dec 2019 21:52:39 +0000 (16:52 -0500)
committerEric Sandeen <sandeen@redhat.com>
Tue, 17 Dec 2019 21:52:39 +0000 (16:52 -0500)
Only notify user of discard operations if the first one succeeds,
and be sure to print a trailing newline if we stop early.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
mkfs/xfs_mkfs.c

index 4bfdebf6f396202a388f8a96d2598a866aedeadd..606f79dafc233730a5ca283374f5af3c5b965c03 100644 (file)
@@ -1251,10 +1251,6 @@ discard_blocks(dev_t dev, uint64_t nsectors, int quiet)
        fd = libxfs_device_to_fd(dev);
        if (fd <= 0)
                return;
-       if (!quiet) {
-               printf("Discarding blocks...");
-               fflush(stdout);
-       }
 
        /* The block discarding happens in smaller batches so it can be
         * interrupted prematurely
@@ -1267,12 +1263,20 @@ discard_blocks(dev_t dev, uint64_t nsectors, int quiet)
                 * not necessary for the mkfs functionality but just an
                 * optimization. However we should stop on error.
                 */
-               if (platform_discard_blocks(fd, offset, tmp_step))
+               if (platform_discard_blocks(fd, offset, tmp_step) == 0) {
+                       if (offset == 0 && !quiet) {
+                               printf("Discarding blocks...");
+                               fflush(stdout);
+                       }
+               } else {
+                       if (offset > 0 && !quiet)
+                               printf("\n");
                        return;
+               }
 
                offset += tmp_step;
        }
-       if (!quiet)
+       if (offset > 0 && !quiet)
                printf("Done.\n");
 }