Skip to content

Commit f1e8185

Browse files
Christoph Hellwigaxboe
authored andcommitted
sd: factor out a sd_discard_mode helper
Split the logic to pick the right discard mode into a little helper to prepare for further changes. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Damien Le Moal <[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 d15b9bd commit f1e8185

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

drivers/scsi/sd.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3201,6 +3201,25 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
32013201
return;
32023202
}
32033203

3204+
static unsigned int sd_discard_mode(struct scsi_disk *sdkp)
3205+
{
3206+
if (!sdkp->lbpvpd) {
3207+
/* LBP VPD page not provided */
3208+
if (sdkp->max_unmap_blocks)
3209+
return SD_LBP_UNMAP;
3210+
return SD_LBP_WS16;
3211+
}
3212+
3213+
/* LBP VPD page tells us what to use */
3214+
if (sdkp->lbpu && sdkp->max_unmap_blocks)
3215+
return SD_LBP_UNMAP;
3216+
if (sdkp->lbpws)
3217+
return SD_LBP_WS16;
3218+
if (sdkp->lbpws10)
3219+
return SD_LBP_WS10;
3220+
return SD_LBP_DISABLE;
3221+
}
3222+
32043223
/**
32053224
* sd_read_block_limits - Query disk device for preferred I/O sizes.
32063225
* @sdkp: disk to query
@@ -3239,23 +3258,7 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
32393258
sdkp->unmap_alignment =
32403259
get_unaligned_be32(&vpd->data[32]) & ~(1 << 31);
32413260

3242-
if (!sdkp->lbpvpd) { /* LBP VPD page not provided */
3243-
3244-
if (sdkp->max_unmap_blocks)
3245-
sd_config_discard(sdkp, SD_LBP_UNMAP);
3246-
else
3247-
sd_config_discard(sdkp, SD_LBP_WS16);
3248-
3249-
} else { /* LBP VPD page tells us what to use */
3250-
if (sdkp->lbpu && sdkp->max_unmap_blocks)
3251-
sd_config_discard(sdkp, SD_LBP_UNMAP);
3252-
else if (sdkp->lbpws)
3253-
sd_config_discard(sdkp, SD_LBP_WS16);
3254-
else if (sdkp->lbpws10)
3255-
sd_config_discard(sdkp, SD_LBP_WS10);
3256-
else
3257-
sd_config_discard(sdkp, SD_LBP_DISABLE);
3258-
}
3261+
sd_config_discard(sdkp, sd_discard_mode(sdkp));
32593262
}
32603263

32613264
out:

0 commit comments

Comments
 (0)