diff options
author | Christoph Hellwig <hch@lst.de> | 2025-07-31 08:22:28 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-08-15 12:14:05 +0200 |
commit | 0257dc08a404824dc24a748c226cd5773a468f7a (patch) | |
tree | 286dd322de4226693c9eb6340166f961c3786739 | |
parent | 3ff8fe9194a7f5f2691c3ff557eff9ad66c19465 (diff) |
block: ensure discard_granularity is zero when discard is not supported
[ Upstream commit fad6551fcf537375702b9af012508156a16a1ff7 ]
Documentation/ABI/stable/sysfs-block states:
What: /sys/block/<disk>/queue/discard_granularity
[...]
A discard_granularity of 0 means that the device does not support
discard functionality.
but this got broken when sorting out the block limits updates. Fix this
by setting the discard_granularity limit to zero when the combined
max_discard_sectors is zero.
Fixes: 3c407dc723bb ("block: default the discard granularity to sector size")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20250731152228.873923-1-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | block/blk-settings.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/block/blk-settings.c b/block/blk-settings.c index 7858c92b4483..22ce7fa4fe20 100644 --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -320,12 +320,19 @@ static int blk_validate_limits(struct queue_limits *lim) lim->max_discard_sectors = min(lim->max_hw_discard_sectors, lim->max_user_discard_sectors); + /* + * When discard is not supported, discard_granularity should be reported + * as 0 to userspace. + */ + if (lim->max_discard_sectors) + lim->discard_granularity = + max(lim->discard_granularity, lim->physical_block_size); + else + lim->discard_granularity = 0; + if (!lim->max_discard_segments) lim->max_discard_segments = 1; - if (lim->discard_granularity < lim->physical_block_size) - lim->discard_granularity = lim->physical_block_size; - /* * By default there is no limit on the segment boundary alignment, * but if there is one it can't be smaller than the page size as |