The commit 7985090aa0201(sd: Disable discard_zeroes_data for UNMAP) introduces regresion for QEMU SCSI. QEMU SCSI device claims to support UNMAP, WRITE SAME and WRITE SAME 16 in LBP VPD page, but only provides "Maximum unmap LBA count" in block limits VPD page, and "Maximum write same length" isn't set. The default max_discard_sectors(SD_MAX_WS16_BLOCKS) can't work at all since it is much bigger than the actual Maximum unmap LBA count. This patch trys to fix the regression by setting 'max_ws_blocks' as 'max_unmap_blocks' when block limits VPD page doesn't provide "Maximum write same length" under the situation. This approach is reasonable because device server supports the use of the WRITE SAME or WRITE SAME 10 command to unmap LBAs when LBPWS or LBPWS10 is set in LBP VPD page. Cc: Martin K. Petersen <martin.petersen@xxxxxxxxxx> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxx> Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxxxxx> --- drivers/scsi/sd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index fedab3c..2a69fee 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -2624,6 +2624,14 @@ static void sd_read_block_limits(struct scsi_disk *sdkp) } else { /* LBP VPD page tells us what to use */ + /* + * Borrow max_unmap_blocks if max_ws_blocks isn't + * provided from block limits VPD page + */ + if ((sdkp->lbpws10 || sdkp->lbpws) && + !sdkp->max_ws_blocks) + sdkp->max_ws_blocks = sdkp->max_unmap_blocks; + if (sdkp->lbpws) sd_config_discard(sdkp, SD_LBP_WS16); else if (sdkp->lbpws10) -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html