From e7fac8bb7cedcb600bea245fc45089c7ff1e9728 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 29 Apr 2025 17:56:54 +0200 Subject: [PATCH 3/3] file-posix: Fix crash on discard_granularity == 0 RH-Author: Stefan Hajnoczi RH-MergeRequest: 450: file-posix: probe discard alignment on Linux block devices RH-Jira: RHEL-87734 RH-Acked-by: Kevin Wolf RH-Acked-by: Eric Blake RH-Commit: [3/3] 89a47a6fceb2222593cff4d8c85376c210dc7cc2 Block devices that don't support discard have a discard_granularity of 0. Currently, this results in a division by zero when we try to make sure that it's a multiple of request_alignment. Only try to update bs->bl.pdiscard_alignment when we got a non-zero discard_granularity from sysfs. Fixes: f605796aae4 ('file-posix: probe discard alignment on Linux block devices') Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi Reviewed-by: Eric Blake Message-ID: <20250429155654.102735-1-kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi (cherry picked from commit 71a30d54e6ab1d5c102a8bee2c263414697402ea) Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/file-posix.c b/block/file-posix.c index 3d5b024459..0cb4e922c0 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1565,7 +1565,7 @@ static void raw_refresh_limits(BlockDriverState *bs, Error **errp) int ret; ret = hdev_get_pdiscard_alignment(&st, &dalign); - if (ret == 0) { + if (ret == 0 && dalign != 0) { uint32_t ralign = bs->bl.request_alignment; /* Probably never happens, but handle it just in case */ -- 2.48.1