[PATCH] sd: disable logical block provisioning if 'lbpme' is not set

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hannes Reinecke <hare@xxxxxxxx>

When evaluating the 'block limits' VPD page we need to check if
the 'lbpme' (logical block provisioning management enable) bit
is set in the READ CAPACITY (16) output.
If it isn't we can safely assume that we cannot use DISCARD on
this device.

[JD: forward-ported to kernel v4.20]

Signed-off-by: Hannes Reinecke <hare@xxxxxxxx>
Signed-off-by: Jean Delvare <jdelvare@xxxxxxxx>
---
Hannes, please double-check that my forward-port is correct.

 drivers/scsi/sd.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -411,6 +411,13 @@ provisioning_mode_store(struct device *d
 	if (mode < 0)
 		return -EINVAL;
 
+	/*
+	 * If logical block provisioning isn't enabled we can only
+	 * select 'disable' here.
+	 */
+	if (!sdkp->lbpme && mode != SD_LBP_DISABLE)
+		return -EINVAL;
+
 	sd_config_discard(sdkp, mode);
 
 	return count;
@@ -2942,8 +2949,10 @@ static void sd_read_block_limits(struct
 
 		sdkp->max_ws_blocks = (u32)get_unaligned_be64(&buffer[36]);
 
-		if (!sdkp->lbpme)
+		if (!sdkp->lbpme) {
+			sd_config_discard(sdkp, SD_LBP_DISABLE);
 			goto out;
+		}
 
 		lba_count = get_unaligned_be32(&buffer[20]);
 		desc_count = get_unaligned_be32(&buffer[24]);


-- 
Jean Delvare
SUSE L3 Support



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux