diff mbox series

megaraid_sas: device scan on logical target with invalid LUN ID deletes that target from the OS

Message ID 20220324094711.48833-1-chandrakanth.patil@broadcom.com (mailing list archive)
State Changes Requested
Headers show
Series megaraid_sas: device scan on logical target with invalid LUN ID deletes that target from the OS | expand

Commit Message

Chandrakanth Patil March 24, 2022, 9:47 a.m. UTC
The megaraid_sas driver supports single LUN, that is LUN 0. And all other
LUNs are unsupported.
When a device scan on logical target with invalid lun is invoked through
sysfs that target itself is getting removed from the OS. So added a LUN
ID validation in the slave destroy to avoid the target deletion.

Signed-off-by: Chandrakanth patil <chandrakanth.patil@broadcom.com>
---
 drivers/scsi/megaraid/megaraid_sas.h      | 3 +++
 drivers/scsi/megaraid/megaraid_sas_base.c | 7 +++++++
 2 files changed, 10 insertions(+)

Comments

Christoph Hellwig March 24, 2022, 9:50 a.m. UTC | #1
On Thu, Mar 24, 2022 at 02:47:11AM -0700, Chandrakanth patil wrote:
> The megaraid_sas driver supports single LUN, that is LUN 0. And all other
> LUNs are unsupported.
> When a device scan on logical target with invalid lun is invoked through
> sysfs that target itself is getting removed from the OS. So added a LUN
> ID validation in the slave destroy to avoid the target deletion.

Please set the max_lun member ins the host template isntead of papering
over this in the driver.
Chandrakanth Patil March 30, 2022, 10:39 a.m. UTC | #2
Hi Christoph,

in shost, we set the max_lun to 8 during load and that is meant for
NON_RAID devices.
whereas RAID device supports only a single LUN so this patch takes care of that.

-ckp


On Thu, Mar 24, 2022 at 3:20 PM Christoph Hellwig <hch@infradead.org> wrote:
>
> On Thu, Mar 24, 2022 at 02:47:11AM -0700, Chandrakanth patil wrote:
> > The megaraid_sas driver supports single LUN, that is LUN 0. And all other
> > LUNs are unsupported.
> > When a device scan on logical target with invalid lun is invoked through
> > sysfs that target itself is getting removed from the OS. So added a LUN
> > ID validation in the slave destroy to avoid the target deletion.
>
> Please set the max_lun member ins the host template isntead of papering
> over this in the driver.
diff mbox series

Patch

diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 611871ef15b5..4919ea54b827 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -2560,6 +2560,9 @@  struct megasas_instance_template {
 #define MEGASAS_IS_LOGICAL(sdev)					\
 	((sdev->channel < MEGASAS_MAX_PD_CHANNELS) ? 0 : 1)
 
+#define MEGASAS_IS_LUN_VALID(sdev)					\
+	(((sdev)->lun == 0) ? 1 : 0)
+
 #define MEGASAS_DEV_INDEX(scp)						\
 	(((scp->device->channel % 2) * MEGASAS_MAX_DEV_PER_CHANNEL) +	\
 	scp->device->id)
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 8bf72dbc33b7..db6793608447 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -2126,6 +2126,9 @@  static int megasas_slave_alloc(struct scsi_device *sdev)
 			goto scan_target;
 		}
 		return -ENXIO;
+	} else if (!MEGASAS_IS_LUN_VALID(sdev)) {
+		sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
+		return -ENXIO;
 	}
 
 scan_target:
@@ -2156,6 +2159,10 @@  static void megasas_slave_destroy(struct scsi_device *sdev)
 	instance = megasas_lookup_instance(sdev->host->host_no);
 
 	if (MEGASAS_IS_LOGICAL(sdev)) {
+		if (!MEGASAS_IS_LUN_VALID(sdev)) {
+			sdev_printk(KERN_INFO, sdev, "%s: invalid LUN\n", __func__);
+			return;
+		}
 		ld_tgt_id = MEGASAS_TARGET_ID(sdev);
 		instance->ld_tgtid_status[ld_tgt_id] = LD_TARGET_ID_DELETED;
 		if (megasas_dbg_lvl & LD_PD_DEBUG)