Skip to content

Commit c765f17

Browse files
Christoph Hellwigkawasaki
authored andcommitted
block: ensure discard_granularity is zero when discard is not supported
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: 3c407dc ("block: default the discard granularity to sector size") Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]>
1 parent de83e48 commit c765f17

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

block/blk-settings.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,12 +388,19 @@ int blk_validate_limits(struct queue_limits *lim)
388388
lim->max_discard_sectors =
389389
min(lim->max_hw_discard_sectors, lim->max_user_discard_sectors);
390390

391+
/*
392+
* When discard is not supported, discard_granularity should be reported
393+
* as 0 to userspace.
394+
*/
395+
if (lim->max_discard_sectors)
396+
lim->discard_granularity =
397+
max(lim->discard_granularity, lim->physical_block_size);
398+
else
399+
lim->discard_granularity = 0;
400+
391401
if (!lim->max_discard_segments)
392402
lim->max_discard_segments = 1;
393403

394-
if (lim->discard_granularity < lim->physical_block_size)
395-
lim->discard_granularity = lim->physical_block_size;
396-
397404
/*
398405
* By default there is no limit on the segment boundary alignment,
399406
* but if there is one it can't be smaller than the page size as

0 commit comments

Comments
 (0)