All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@redhat.com>
To: David Sterba <dsterba@suse.cz>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: check if device supports trim
Date: Mon, 23 Sep 2013 10:08:08 -0500	[thread overview]
Message-ID: <52405958.4050209@redhat.com> (raw)
In-Reply-To: <1379695327-30046-1-git-send-email-dsterba@suse.cz>

On 9/20/13 11:42 AM, David Sterba wrote:
> The message about trim was printed unconditionally, we should check if
> trim is supported at all.

Good idea, but I wonder if there's any risk that discard(0,0) will ever
be optimized away on the kernel side & pass unconditionally?

I was thinking we could get this from blkid, but maybe not.

In the meantime it does do the right thing, so:

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> 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);
> 


  reply	other threads:[~2013-09-23 15:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20 16:42 [PATCH] btrfs-progs: check if device supports trim David Sterba
2013-09-23 15:08 ` Eric Sandeen [this message]
2013-09-23 15:44   ` David Sterba
2013-09-23 15:46     ` Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52405958.4050209@redhat.com \
    --to=sandeen@redhat.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.