summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2013-09-20 18:42:07 +0200
committerChris Mason <chris.mason@fusionio.com>2013-10-16 08:23:11 -0400
commit25d82d222944a234a006d8828fa20329a370c807 (patch)
treed8f0541da7cd37e808f231f347bc90618c4818a8
parentb5efa4c3c9cd879e2f8079c56df8e38ae7024121 (diff)
btrfs-progs: check if device supports trim
The message about trim was printed unconditionally, we should check if trim is supported at all. Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
-rw-r--r--utils.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/utils.c b/utils.c
index 58d56f5d..c6022fc0 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);