Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Wang Yugui <wangyugui@e16-tech.com>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: fix discard support check
Date: Sat, 13 Nov 2021 15:04:48 +0800	[thread overview]
Message-ID: <20211113150444.C372.409509F4@e16-tech.com> (raw)
In-Reply-To: <19cde2a1-d17d-d8cf-2539-c1d79b32e376@gmx.com>

Hi,

> On 2021/11/13 11:14, Wang Yugui wrote:
> > [BUG]
> > mkfs.btrfs(v5.15) output a message even if the disk is a HDD without
> > TRIM/DISCARD support.
> >    Performing full device TRIM /dev/sdc2 (326.03GiB) ...
> >
> > [CAUSE]
> > mkfs.btrfs check TRIM/DISCARD support through the content of
> > queue/discard_granularity, but compare it against a wrong value.
> >
> > When hdd without TRIM/DISCARD support, the content of
> > queue/discard_granularity is '0' '\n' '\0', rather than '0' '\0'.
> 
> Can we get rid of such bad comparison and just go strtoll() and compare
> the value?

strtoll() or strcmp() is a good choice for refact.  but now just a
direct fix.

Best Regards
Wang Yugui (wangyugui@e16-tech.com)
2021/11/13


> 
> >
> > [FIX]
> > compare it against the right value.
> >
> > Fixes: c50c448518bb ("btrfs-progs: do sysfs detection of device discard capability")
> > Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>
> > ---
> >   common/device-utils.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/common/device-utils.c b/common/device-utils.c
> > index 74a25879..76d5c584 100644
> > --- a/common/device-utils.c
> > +++ b/common/device-utils.c
> > @@ -64,7 +64,7 @@ static int discard_supported(const char *device)
> >   		pr_verbose(3, "cannot read discard_granularity for %s\n", device);
> >   		return 0;
> >   	} else {
> > -		if (buf[0] == '0' && buf[1] == 0) {
> > +		if (buf[0] == '0' && buf[1] == '\n') {
> >   			pr_verbose(3, "%s: discard_granularity %s\n", device, buf);
> >   			return 0;
> >   		}
> >



  reply	other threads:[~2021-11-13  7:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-13  3:14 [PATCH] btrfs-progs: fix discard support check Wang Yugui
2021-11-13  4:45 ` Qu Wenruo
2021-11-13  7:04   ` Wang Yugui [this message]
2021-11-13  7:49     ` Nikolay Borisov

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=20211113150444.C372.409509F4@e16-tech.com \
    --to=wangyugui@e16-tech.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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