diff options
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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); |