Skip to content

Commit d3205ab

Browse files
keithbuschChristoph Hellwig
authored andcommitted
nvme: fix discard support without oncs
The device can report discard support without setting the ONCS DSM bit. When not set, the driver clears max_discard_size expecting it to be set later. We don't know the size until we have the namespace format, though, so setting it is deferred until configuring one, but the driver was abandoning the discard settings due to that initial clearing. Move the max_discard_size calculation above the check for a '0' discard size. Fixes: 1a86924 ("nvme: fix interpretation of DMRSL") Reported-by: Laurence Oberman <[email protected]> Signed-off-by: Keith Busch <[email protected]> Reviewed-by: Niklas Cassel <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Tested-by: Laurence Oberman <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 38a8c4d commit d3205ab

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/nvme/host/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,9 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
16741674
struct request_queue *queue = disk->queue;
16751675
u32 size = queue_logical_block_size(queue);
16761676

1677+
if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX))
1678+
ctrl->max_discard_sectors = nvme_lba_to_sect(ns, ctrl->dmrsl);
1679+
16771680
if (ctrl->max_discard_sectors == 0) {
16781681
blk_queue_max_discard_sectors(queue, 0);
16791682
return;
@@ -1688,9 +1691,6 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns)
16881691
if (queue->limits.max_discard_sectors)
16891692
return;
16901693

1691-
if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns, UINT_MAX))
1692-
ctrl->max_discard_sectors = nvme_lba_to_sect(ns, ctrl->dmrsl);
1693-
16941694
blk_queue_max_discard_sectors(queue, ctrl->max_discard_sectors);
16951695
blk_queue_max_discard_segments(queue, ctrl->max_discard_segments);
16961696

0 commit comments

Comments
 (0)