Skip to content

Commit

Permalink
sd: factor out a sd_discard_mode helper
Browse files Browse the repository at this point in the history
Split the logic to pick the right discard mode into a little helper
to prepare for further changes.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20240531074837.1648501-10-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Jun 14, 2024
1 parent d15b9bd commit f1e8185
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions drivers/scsi/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3201,6 +3201,25 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
return;
}

static unsigned int sd_discard_mode(struct scsi_disk *sdkp)
{
if (!sdkp->lbpvpd) {
/* LBP VPD page not provided */
if (sdkp->max_unmap_blocks)
return SD_LBP_UNMAP;
return SD_LBP_WS16;
}

/* LBP VPD page tells us what to use */
if (sdkp->lbpu && sdkp->max_unmap_blocks)
return SD_LBP_UNMAP;
if (sdkp->lbpws)
return SD_LBP_WS16;
if (sdkp->lbpws10)
return SD_LBP_WS10;
return SD_LBP_DISABLE;
}

/**
* sd_read_block_limits - Query disk device for preferred I/O sizes.
* @sdkp: disk to query
Expand Down Expand Up @@ -3239,23 +3258,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
sdkp->unmap_alignment =
get_unaligned_be32(&vpd->data[32]) & ~(1 << 31);

if (!sdkp->lbpvpd) { /* LBP VPD page not provided */

if (sdkp->max_unmap_blocks)
sd_config_discard(sdkp, SD_LBP_UNMAP);
else
sd_config_discard(sdkp, SD_LBP_WS16);

} else { /* LBP VPD page tells us what to use */
if (sdkp->lbpu && sdkp->max_unmap_blocks)
sd_config_discard(sdkp, SD_LBP_UNMAP);
else if (sdkp->lbpws)
sd_config_discard(sdkp, SD_LBP_WS16);
else if (sdkp->lbpws10)
sd_config_discard(sdkp, SD_LBP_WS10);
else
sd_config_discard(sdkp, SD_LBP_DISABLE);
}
sd_config_discard(sdkp, sd_discard_mode(sdkp));
}

out:
Expand Down

0 comments on commit f1e8185

Please sign in to comment.