linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: check if device supports trim
@ 2013-09-20 16:42 David Sterba
  2013-09-23 15:08 ` Eric Sandeen
  0 siblings, 1 reply; 4+ messages in thread
From: David Sterba @ 2013-09-20 16:42 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The message about trim was printed unconditionally, we should check if
trim is supported at all.

Signed-off-by: David Sterba <dsterba@suse.cz>
---
 utils.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/utils.c b/utils.c
index 5fa193b..6c74654 100644
--- a/utils.c
+++ b/utils.c
@@ -597,13 +597,16 @@ int btrfs_prepare_device(int fd, char *file, int zero_end, u64 *block_count_ret,
 	}
 
 	if (discard) {
-		fprintf(stderr, "Performing full device TRIM (%s) ...\n",
-				pretty_size(block_count));
 		/*
-		 * We intentionally ignore errors from the discard ioctl.  It is
-		 * not necessary for the mkfs functionality but just an optimization.
+		 * We intentionally ignore errors from the discard ioctl.  It
+		 * is not necessary for the mkfs functionality but just an
+		 * optimization.
 		 */
-		discard_blocks(fd, 0, block_count);
+		if (discard_blocks(fd, 0, 0) == 0) {
+			fprintf(stderr, "Performing full device TRIM (%s) ...\n",
+				pretty_size(block_count));
+			discard_blocks(fd, 0, block_count);
+		}
 	}
 
 	ret = zero_dev_start(fd);
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-23 15:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-20 16:42 [PATCH] btrfs-progs: check if device supports trim David Sterba
2013-09-23 15:08 ` Eric Sandeen
2013-09-23 15:44   ` David Sterba
2013-09-23 15:46     ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).