Linux Btrfs filesystem development
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: fix discard support check
@ 2021-11-13  3:14 Wang Yugui
  2021-11-13  4:45 ` Qu Wenruo
  0 siblings, 1 reply; 4+ messages in thread
From: Wang Yugui @ 2021-11-13  3:14 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Wang Yugui

[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'.

[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;
 		}
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-13  8:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2021-11-13  7:49     ` Nikolay Borisov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox