Skip to content

Commit fad6551

Browse files
Christoph Hellwigaxboe
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]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 7657618 commit fad6551

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

block/blk-settings.c

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

403+
/*
404+
* When discard is not supported, discard_granularity should be reported
405+
* as 0 to userspace.
406+
*/
407+
if (lim->max_discard_sectors)
408+
lim->discard_granularity =
409+
max(lim->discard_granularity, lim->physical_block_size);
410+
else
411+
lim->discard_granularity = 0;
412+
403413
if (!lim->max_discard_segments)
404414
lim->max_discard_segments = 1;
405415

406-
if (lim->discard_granularity < lim->physical_block_size)
407-
lim->discard_granularity = lim->physical_block_size;
408-
409416
/*
410417
* By default there is no limit on the segment boundary alignment,
411418
* but if there is one it can't be smaller than the page size as

0 commit comments

Comments
 (0)