RE: How to add/drop SCSI drives from within the driver?

From: Bagalkote, Sreenivas
Date: Wed Dec 08 2004 - 02:28:55 EST


Hello All,

Last week we proposed to add couple of IOCTLs to scan/remove the LDs.
It was suggested on the list that our application go sysfs route instead.
We are taking that route. (Matt Domsh, Christoph, JBG and Brian King -
thanks for your feedback! It is appreciated.)

Please review our updated proposal. Considering that our application can
add and remove drives on the fly:

Adding a drive:- For application to use sysfs to scan newly added drive,
it needs to know the HCTL (SCSI address - Host, Channel, Target & Lun)
of the drive. Driver is the only one that knows the mapping between a
drive and the corresponding HCTL.

Removing a drive:- There is no sane way for the application to map out
drives to /dev/sd<x>. If application has a way of knowing the HCTL of a
deleted drive, then using that HCTL, it can match the corresponding SCSI
device name (/dev/sd<x>) and use sysfs to remove that drive.

To this end, we are requesting to be allowed to add a small IOCTL to the
driver that returns the HCTL for an LD. Our strong case is really the
"Adding
a drive" case. Somebody may suggest that an application can blindly
scan all channels and all targets on a host when it adds one drive. That
would
_not_ be correct thing to do. Application should ideally scan only the
drives that
it has added.

I am attaching and inlining the patch that implements this logic.

Thank you,
Sreenivas
LSI Logic

diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_ioctl.h
new-rc2/drivers/scsi/megaraid/megaraid_ioctl.h
--- old-rc2/drivers/scsi/megaraid/megaraid_ioctl.h 2004-12-07
16:40:16.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_ioctl.h 2004-12-07
23:57:51.415674008 -0500
@@ -51,6 +51,7 @@
#define MEGAIOC_QNADAP 'm' /* Query # of adapters */
#define MEGAIOC_QDRVRVER 'e' /* Query driver version */
#define MEGAIOC_QADAPINFO 'g' /* Query adapter information */
+#define MEGAIOC_GET_SADDR 'a' /* Get SCSI address of an LD */

#define USCSICMD 0x80
#define UIOC_RD 0x00001
@@ -62,6 +63,7 @@
#define GET_ADAP_INFO 0x30000
#define GET_CAP 0x40000
#define GET_STATS 0x50000
+#define GET_LD_SADDR 0x60000
#define GET_IOCTL_VERSION 0x01

#define EXT_IOCTL_SIGN_SZ 16
@@ -217,6 +219,27 @@

} __attribute__ ((packed)) mcontroller_t;

+/**
+ * ld_device_address_t : SCSI device address for the logical drives
+ *
+ * @host_no : host# to which LD belogs; as understood by
mid-layer
+ * @channel : channel on which LD is exported
+ * @target : target on which the LD is exported
+ * @lun : lun on which the LD is exported
+ * @ld : the LD for which this information is sought
+ * @reserved : reserved fields; must be set to zero
+ *
+ * NOTE : Applications set the LD number and expect
the
+ * SCSI address to be returned in the first four
fields
+ */
+typedef struct {
+ uint32_t host_no;
+ uint32_t channel;
+ uint32_t scsi_id;
+ uint32_t lun;
+ uint32_t ld;
+ uint32_t reserved[3];
+} ld_device_address_t;

/**
* mm_dmapool_t : Represents one dma pool with just one buffer
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mbox.c
new-rc2/drivers/scsi/megaraid/megaraid_mbox.c
--- old-rc2/drivers/scsi/megaraid/megaraid_mbox.c 2004-12-07
16:40:16.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mbox.c 2004-12-08
01:29:39.420330024 -0500
@@ -10,7 +10,7 @@
* 2 of the License, or (at your option) any later version.
*
* FILE : megaraid_mbox.c
- * Version : v2.20.4.1 (Nov 04 2004)
+ * Version : v2.20.4.1+ TEST VERSION
*
* Authors:
* Atul Mukker <Atul.Mukker@xxxxxxxx>
@@ -3642,6 +3642,7 @@
megaraid_mbox_mm_handler(unsigned long drvr_data, uioc_t *kioc, uint32_t
action)
{
adapter_t *adapter;
+ ld_device_address_t* lda;

if (action != IOCTL_ISSUE) {
con_log(CL_ANN, (KERN_WARNING
@@ -3670,6 +3671,30 @@

return kioc->status;

+ case GET_LD_SADDR:
+
+ lda = (ld_device_address_t*)(unsigned long)kioc->buf_vaddr;
+
+ if ((lda->ld < 0) || (lda->ld > MAX_LOGICAL_DRIVES_40LD)) {
+ lda->host_no = 0xffffffff;
+ lda->channel = 0xffffffff;
+ lda->scsi_id = 0xffffffff;
+ lda->lun = 0xffffffff;
+ kioc->status = -ENODEV;
+ kioc->done(kioc);
+ return kioc->status;
+ }
+
+ lda->host_no = adapter->host->host_no;
+ lda->channel = adapter->max_channel;
+ lda->scsi_id = (lda->ld < adapter->init_id) ?
+ lda->ld : lda->ld + 1;
+ lda->lun = 0;
+ kioc->status = 0;
+ kioc->done(kioc);
+
+ return kioc->status;
+
case MBOX_CMD:

return megaraid_mbox_mm_command(adapter, kioc);
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mbox.h
new-rc2/drivers/scsi/megaraid/megaraid_mbox.h
--- old-rc2/drivers/scsi/megaraid/megaraid_mbox.h 2004-12-07
16:40:16.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mbox.h 2004-12-07
23:53:35.047647872 -0500
@@ -21,8 +21,8 @@
#include "megaraid_ioctl.h"


-#define MEGARAID_VERSION "2.20.4.1"
-#define MEGARAID_EXT_VERSION "(Release Date: Thu Nov 4 17:44:59 EST
2004)"
+#define MEGARAID_VERSION "2.20.4.1+ TEST VERSION"
+#define MEGARAID_EXT_VERSION "(Release Date: TEST VERSION)"


/*
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mm.c
new-rc2/drivers/scsi/megaraid/megaraid_mm.c
--- old-rc2/drivers/scsi/megaraid/megaraid_mm.c 2004-12-07
16:40:16.015101592 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mm.c 2004-12-08
01:27:35.171218760 -0500
@@ -10,7 +10,7 @@
* 2 of the License, or (at your option) any later version.
*
* FILE : megaraid_mm.c
- * Version : v2.20.2.2 (Nov 04 2004)
+ * Version : v2.20.2.2+ TEST VERSION
*
* Common management module
*/
@@ -373,6 +373,20 @@
if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
return (-ENOMEM);
}
+ else if (subopcode == MEGAIOC_GET_SADDR) {
+
+ kioc->opcode = GET_LD_SADDR;
+ kioc->data_dir = UIOC_RD;
+ kioc->xferlen = sizeof(ld_device_address_t);
+
+ if (mraid_mm_attach_buf(adp, kioc, kioc->xferlen))
+ return (-ENOMEM);
+
+ if (copy_from_user(kioc->buf_vaddr, mimd.data,
+ kioc->xferlen )) {
+ return (-EFAULT);
+ }
+ }
else {
con_log(CL_ANN, (KERN_WARNING
"megaraid cmm: Invalid subop\n"));
@@ -809,6 +823,15 @@

return 0;

+ case MEGAIOC_GET_SADDR:
+
+ if (copy_to_user(kmimd.data, kioc->buf_vaddr,
+ sizeof(ld_device_address_t))) {
+ return (-EFAULT);
+ }
+
+ return kioc->status;
+
default:
return (-EINVAL);
}
diff -Naur old-rc2/drivers/scsi/megaraid/megaraid_mm.h
new-rc2/drivers/scsi/megaraid/megaraid_mm.h
--- old-rc2/drivers/scsi/megaraid/megaraid_mm.h 2004-12-07
16:40:15.000000000 -0500
+++ new-rc2/drivers/scsi/megaraid/megaraid_mm.h 2004-12-07
23:52:50.975347880 -0500
@@ -29,9 +29,9 @@
#include "megaraid_ioctl.h"


-#define LSI_COMMON_MOD_VERSION "2.20.2.2"
+#define LSI_COMMON_MOD_VERSION "2.20.2.2+ TEST VERSION"
#define LSI_COMMON_MOD_EXT_VERSION \
- "(Release Date: Thu Nov 4 17:46:29 EST 2004)"
+ "(Release Date: TEST VERSION)"


#define LSI_DBGLVL dbglevel



>-----Original Message-----
>From: Matt Domsch [mailto:Matt_Domsch@xxxxxxxx]
>Sent: Friday, December 03, 2004 12:11 PM
>To: Bagalkote, Sreenivas
>Cc: 'brking@xxxxxxxxxx'; 'James Bottomley';
>'linux-kernel@xxxxxxxxxxxxxxx'; 'linux-scsi@xxxxxxxxxxxxxxx';
>'bunk@xxxxxxxxx'; 'Andrew Morton'; Ju, Seokmann; Doelfel,
>Hardy; Mukker, Atul
>Subject: Re: How to add/drop SCSI drives from within the driver?
>
>On Fri, Dec 03, 2004 at 10:29:29AM -0500, Bagalkote, Sreenivas wrote:
>> I agree. The sysfs method would have been the most logical
>way of doing it.
>> But then application becomes sysfs dependent. We really
>cannot do that.
>
>Why? With my efibootmgr (a userspace app like your
>megalib/megamgr/megamon), it looks for the existance of
>/sys/whatever/, and then operates with that if it is present.
>Else it looks for the existance of /proc/whatever (in your case
>/proc/scsi/scsi) and does likewise. No driver ioctl needed.
>
>> Given that we have to do it from within the driver, is whatever I am
>> doing right?
>
>Doing it within the driver means you've got to release a new
>driver for each affected OS, to avoid having to update the
>userspace app on each OS. I claim it's much easier to update
>a userspace lib/app than it is to update a driver on each
>installed system.
>
>Thanks,
>Matt
>
>--
>Matt Domsch
>Sr. Software Engineer, Lead Engineer
>Dell Linux Solutions linux.dell.com & www.dell.com/linux Linux
>on Dell mailing lists @ http://lists.us.dell.com
>

Attachment: megaraid_hctl.patch
Description: Binary data