btrfs-progs: fix discard support check
PATCH v2 1/1 btrfs-progs: fix discard support check
[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 the value based on atoi() to provide more robustness
- delete unnecessary '\n' in pr_verbose()
--- common/device-utils.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
common/device-utils.c +3 -2
@@ -64,8 +64,9 @@ 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 ) { -pr_verbose (3 ,"%s: discard_granularity %s\n" , device, buf); +/* string(buf) end with '\n\0' */ +if (atoi (buf) ==0 ) { +pr_verbose (3 ,"%s: discard_granularity %s" , device, buf);return 0 ; } }
Signature · 1 line
2.32.0
Quoted 12 lines · 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'.
Quoted 6 lines
[FIX]
- compare the value based onatoi()to provide more robustness
- delete unnecessary '\n' inpr_verbose()Fixes c50c448518bb ("btrfs-progs: do sysfs detection of device discard capability")Signed-off-by Wang Yugui <[email protected]>
Added to devel, thanks.