public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Roman Mamedov <rm@romanrm.net>
To: Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: mkfs: use device_discard_blocks() to replace prepare_discard_device()
Date: Thu, 8 Jan 2026 09:51:20 +0500	[thread overview]
Message-ID: <20260108095120.0d85f706@nvm> (raw)
In-Reply-To: <284c38aeccd4abefa2349d2bab1cefb09e89b5bd.1767847334.git.wqu@suse.com>

On Thu,  8 Jan 2026 15:12:17 +1030
Qu Wenruo <wqu@suse.com> wrote:

> -static void prepare_discard_device(const char *filename, int fd, u64 byte_count, unsigned opflags)
> -{
> -	u64 cur = 0;
> -
> -	while (cur < byte_count) {
> -		/* 1G granularity */
> -		u64 chunk_size = (cur == 0) ? SZ_1M : min_t(u64, byte_count - cur, SZ_1G);
> -		int ret;
> -
> -		ret = discard_range(fd, cur, chunk_size);
> -		if (ret)
> -			return;
> -		/*
> -		 * The first range discarded successfully, meaning the device supports
> -		 * discard.
> -		 */
> -		if (opflags & PREP_DEVICE_VERBOSE && cur == 0)
> -			printf("Performing full device TRIM %s (%s) ...\n",
> -			       filename, pretty_size(byte_count));
> -		cur += chunk_size;
> -	}
> -}
> -
>  /*
>   * Write zeros to the given range [start, start + len)
>   */
> @@ -293,8 +270,16 @@ int btrfs_prepare_device(int fd, const char *file, u64 *byte_count_ret,
>  		goto err;
>  	}
>  
> -	if (!(opflags & PREP_DEVICE_ZONED) && (opflags & PREP_DEVICE_DISCARD))
> -		prepare_discard_device(file, fd, byte_count, opflags);
> +	if (!(opflags & PREP_DEVICE_ZONED) && (opflags & PREP_DEVICE_DISCARD)) {
> +		ret = device_discard_blocks(fd, 0, byte_count);
> +		if (ret < 0) {
> +			errno = -ret;
> +			warning("failed to discard device '%s': %m", file);
> +		} else {
> +			printf("Performing full device TRIM %s (%s) ...\n",
> +			       file, pretty_size(byte_count));
> +		}
> +	}
>  
>  	ret = btrfs_wipe_existing_sb(fd, zinfo);
>  	if (ret < 0) {

Before: the message is printed after the first successful discard of a 1G
range, so with any real-world device at the very beginning of operation.

After: the message is printed only after the full device is discarded???
And it still implies the operation has just begun and is in progress.

It could take a significant time and it was good to print it in the beginning
to let the user know what is going on.

Or I am missing something here?

-- 
With respect,
Roman

  reply	other threads:[~2026-01-08  4:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08  4:42 [PATCH] btrfs-progs: mkfs: use device_discard_blocks() to replace prepare_discard_device() Qu Wenruo
2026-01-08  4:51 ` Roman Mamedov [this message]
2026-01-08  4:54   ` Qu Wenruo
2026-01-08  5:10     ` Qu Wenruo
2026-01-08  5:38       ` Roman Mamedov

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=20260108095120.0d85f706@nvm \
    --to=rm@romanrm.net \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox