scsi_dh update
Subsystems (2)
cover scsi_dh update
Hi James, Hannes,
These are the same set of patches that Hannes sent early this morning with the prelog below.
I just ported it to compile clean on top of 2.6.26-git6.
Made 3 additional changes:
1. Added a break under MODE_SELECT option in function get_req() (in 3/8)
2. Added the ifndef portion for scsi_dh_attach() and scsi_dh_detach (in 6/8)
3. Moved the definition of SCSI_DH_DEV_UNSUPP from 6/8 to 3/8.
regards,
chandra
------ Here is the 0/8 from Hannes's original patchset. -----------
Hi James,
this is the (hopefully final) update to my scsi_dh patchset. Features are:
- Move device-table matching into the device_handler infrastructure, so that individual drivers don't have to implement it themselves
- Adds a 'dh_state' sysfs attribute for manually attaching device handler to new or unknown disks; this allows to override the internal device tables
- Update the dm-multipath code to attach the device handler specified in the multipath configuration
- Add a cache to speed up lookup of several identical devices
- Update existing EMC, RDAC, and hp_sw device handler to use the new infrastructure
- Add new SPC-3 ALUA device handler
The NetApp device handler has been left out for now as it's still under development.
Please apply.
Cheers,
Hannes
--------------------------------------------------------------------
PATCH 1/8 scsi_dh: Implement common device table handling
Instead of having each and every driver implement its own device table scanning code we should rather implement a common routine and scan the device tables there.
This allows us also to implement a general notifier chain callback for all device handler instead for one per handler.
--- drivers/scsi/device_handler/scsi_dh.c | 202 ++++++++++++++++++++++----- drivers/scsi/device_handler/scsi_dh_emc.c | 92 +++++------- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 85 +++++------- drivers/scsi/device_handler/scsi_dh_rdac.c | 106 ++++++--------- include/scsi/scsi_device.h | 9 +- 5 files changed, 292 insertions(+), 202 deletions(-)
drivers/scsi/device_handler/scsi_dh.c +170 -32
@@ -33,7 +33,7 @@ static struct scsi_device_handler *get_dspin_lock (&list_lock);list_for_each_entry (tmp, &scsi_dh_list, list) { -if (!strcmp (tmp->name, name)) { +if (!strncmp (tmp->name, name,strlen (tmp->name))) { found = tmp;break ; }
@@ -42,51 +42,173 @@ static struct scsi_device_handler *get_dreturn found; } -static int scsi_dh_notifier_add (struct device *dev,void *data) +static int device_handler_match (struct scsi_device_handler *tmp, +struct scsi_device *sdev) { -struct scsi_device_handler *scsi_dh = data; +int i; + +for (i =0 ; tmp->devlist[i].vendor; i++) { +if (!strncmp (sdev->vendor, tmp->devlist[i].vendor, +strlen (tmp->devlist[i].vendor)) && + !strncmp (sdev->model, tmp->devlist[i].model, +strlen (tmp->devlist[i].model))) { +return 1 ; + } + } - scsi_dh->nb.notifier_call (&scsi_dh->nb,BUS_NOTIFY_ADD_DEVICE , dev);return 0 ; }/* -* scsi_register_device_handler - register a device handler personality -* module. -* @scsi_dh - device handler to be registered. +* scsi_dh_handler_attach - Attach a device handler to a device +* @sdev - SCSI device the device handler should attach to +* @scsi_dh - The device handler to attach +*/ +static int scsi_dh_handler_attach (struct scsi_device *sdev, +struct scsi_device_handler *scsi_dh) +{ +int err =0 ; + +if (sdev->scsi_dh_data) { +if (sdev->scsi_dh_data->scsi_dh != scsi_dh) + err = -EBUSY ; + }else if (scsi_dh->attach) + err = scsi_dh->attach (sdev); + +return err; +} + +/* +* scsi_dh_handler_detach - Detach a device handler from a device +* @sdev - SCSI device the device handler should be detached from +* @scsi_dh - Device handler to be detached * -* Returns 0 on success, -EBUSY if handler already registered. +* Detach from a device handler. If a device handler is specified, +* only detach if the currently attached handler is equal to it. */ -int scsi_register_device_handler (struct scsi_device_handler *scsi_dh) +static void scsi_dh_handler_detach (struct scsi_device *sdev, +struct scsi_device_handler *scsi_dh) { -int ret = -EBUSY ; -struct scsi_device_handler *tmp; +if (!sdev->scsi_dh_data) +return ; - tmp =get_device_handler (scsi_dh->name); -if (tmp) - goto done; +if (scsi_dh && scsi_dh != sdev->scsi_dh_data->scsi_dh) +return ; - ret =bus_register_notifier (&scsi_bus_type, &scsi_dh->nb); +if (!scsi_dh) + scsi_dh = sdev->scsi_dh_data->scsi_dh; + +if (scsi_dh && scsi_dh->detach) + scsi_dh->detach (sdev); +} + +/* +* scsi_dh_notifier - notifier chain callback +*/ +static int scsi_dh_notifier (struct notifier_block *nb, +unsigned long action,void *data) +{ +struct device *dev = data; +struct scsi_device *sdev; +int err =0 ; +struct scsi_device_handler *tmp, *devinfo =NULL ; + +if (!scsi_is_sdev_device (dev)) +return 0 ; + + sdev =to_scsi_device (dev); -bus_for_each_dev (&scsi_bus_type,NULL , scsi_dh, scsi_dh_notifier_add);spin_lock (&list_lock); -list_add (&scsi_dh->list, &scsi_dh_list); +list_for_each_entry (tmp, &scsi_dh_list, list) { +if (device_handler_match (tmp, sdev)) { + devinfo = tmp; +break ; + } + }spin_unlock (&list_lock); -done: -return ret; +if (!devinfo) + goto out; + +if (action ==BUS_NOTIFY_ADD_DEVICE ) { + err =scsi_dh_handler_attach (sdev, devinfo); + }else if (action ==BUS_NOTIFY_DEL_DEVICE ) { +scsi_dh_handler_detach (sdev,NULL ); + } +out: +return err; } -EXPORT_SYMBOL_GPL (scsi_register_device_handler); +/* +* scsi_dh_notifier_add - Callback for scsi_register_device_handler +*/ +static int scsi_dh_notifier_add (struct device *dev,void *data) +{ +struct scsi_device_handler *scsi_dh = data; +struct scsi_device *sdev; + +if (!scsi_is_sdev_device (dev)) +return 0 ; + +if (!get_device (dev)) +return 0 ; + + sdev =to_scsi_device (dev); + +if (device_handler_match (scsi_dh, sdev)) +scsi_dh_handler_attach (sdev, scsi_dh); + +put_device (dev); + +return 0 ; +} + +/* +* scsi_dh_notifier_remove - Callback for scsi_unregister_device_handler +*/ static int scsi_dh_notifier_remove (struct device *dev,void *data) {struct scsi_device_handler *scsi_dh = data; +struct scsi_device *sdev; + +if (!scsi_is_sdev_device (dev)) +return 0 ; + +if (!get_device (dev)) +return 0 ; + + sdev =to_scsi_device (dev); + +scsi_dh_handler_detach (sdev, scsi_dh); + +put_device (dev); - scsi_dh->nb.notifier_call (&scsi_dh->nb,BUS_NOTIFY_DEL_DEVICE , dev);return 0 ; }/* +* scsi_register_device_handler - register a device handler personality +* module. +* @scsi_dh - device handler to be registered. +* +* Returns 0 on success, -EBUSY if handler already registered. +*/ +int scsi_register_device_handler (struct scsi_device_handler *scsi_dh) +{ +if (get_device_handler (scsi_dh->name)) +return -EBUSY ; + +spin_lock (&list_lock); +list_add (&scsi_dh->list, &scsi_dh_list); +spin_unlock (&list_lock); +bus_for_each_dev (&scsi_bus_type,NULL , scsi_dh, scsi_dh_notifier_add); +printk (KERN_INFO "%s: device handler registered\n" , scsi_dh->name); + +return SCSI_DH_OK ; +} +EXPORT_SYMBOL_GPL (scsi_register_device_handler); + +/* * scsi_unregister_device_handler - register a device handler personality * module. * @scsi_dh - device handler to be unregistered.
@@ -95,23 +217,18 @@ static int scsi_dh_notifier_remove(struc*/ int scsi_unregister_device_handler (struct scsi_device_handler *scsi_dh) { -int ret = -ENODEV ; -struct scsi_device_handler *tmp; - - tmp =get_device_handler (scsi_dh->name); -if (!tmp) - goto done; - - ret =bus_unregister_notifier (&scsi_bus_type, &scsi_dh->nb); +if (!get_device_handler (scsi_dh->name)) +return -ENODEV ;bus_for_each_dev (&scsi_bus_type,NULL , scsi_dh, - scsi_dh_notifier_remove); + scsi_dh_notifier_remove); +spin_lock (&list_lock);list_del (&scsi_dh->list);spin_unlock (&list_lock); +printk (KERN_INFO "%s: device handler unregistered\n" , scsi_dh->name); -done: -return ret; +return SCSI_DH_OK ; }EXPORT_SYMBOL_GPL (scsi_unregister_device_handler);
@@ -157,6 +274,27 @@ int scsi_dh_handler_exist(const char *na }EXPORT_SYMBOL_GPL (scsi_dh_handler_exist); +static struct notifier_block scsi_dh_nb = { + .notifier_call = scsi_dh_notifier +}; + +static int __init scsi_dh_init (void ) +{ +int r; + + r =bus_register_notifier (&scsi_bus_type, &scsi_dh_nb); + +return r; +} + +static void __exit scsi_dh_exit(void) +{ +bus_unregister_notifier (&scsi_bus_type, &scsi_dh_nb); +} + +module_init (scsi_dh_init); +module_exit (scsi_dh_exit); +MODULE_DESCRIPTION ("SCSI device handler" );MODULE_AUTHOR ("Chandra Seetharaman <[email protected]>" );MODULE_LICENSE ("GPL" );
drivers/scsi/device_handler/scsi_dh_emc.c +44 -67
150 lines not on this page · raw message
drivers/scsi/device_handler/scsi_dh_hp_sw.c +34 -56
119 lines not on this page · raw message
drivers/scsi/device_handler/scsi_dh_rdac.c +43 -66
142 lines not on this page · raw message
include/scsi/scsi_device.h +8 -1
@@ -167,15 +167,22 @@ struct scsi_device {unsigned long sdev_data[0 ]; } __attribute__((aligned(sizeof(unsigned long)))); +struct scsi_dh_devlist { +char *vendor; +char *model; +}; +struct scsi_device_handler {/* Used by the infrastructure */ struct list_head list;/* list of scsi_device_handlers */ -struct notifier_block nb;/* Filled by the hardware handler */ struct module *module;const char *name; +const struct scsi_dh_devlist *devlist;int (*check_sense)(struct scsi_device *,struct scsi_sense_hdr *); +int (*attach)(struct scsi_device *); +void (*detach)(struct scsi_device *);int (*activate)(struct scsi_device *);int (*prep_fn)(struct scsi_device *,struct request *); };
PATCH 2/8 scsi_dh: Add 'dh_state' sysfs attribute
In reply to Chandra SeetharamanImplement a 'dh_state' sdev attribute for dynamic device handler manipulation. A read on the attribute will return the name of the currently attached device handler or 'detached' if no handler is attached.
The attribute allows the following strings to be written:
- The name of the device handler to be attached if the state is 'detached'.
- 'activate' to trigger path activation if a device handler is attached.
- 'detach' to detach the currently attached device handler.
--- drivers/scsi/device_handler/scsi_dh.c | 103 ++++++++++++++++++++++++++++++++- 1 files changed, 102 insertions(+), 1 deletions(-)
drivers/scsi/device_handler/scsi_dh.c +102 -1
@@ -84,7 +84,7 @@ static int scsi_dh_handler_attach(struct* @scsi_dh - Device handler to be detached * * Detach from a device handler. If a device handler is specified, -* only detach if the currently attached handler is equal to it. +* only detach if the currently attached handler matches @scsi_dh. */ static void scsi_dh_handler_detach (struct scsi_device *sdev,struct scsi_device_handler *scsi_dh)
@@ -103,6 +103,98 @@ static void scsi_dh_handler_detach(struc }/* +* Functions for sysfs attribute 'dh_state' +*/ +static ssize_t +store_dh_state (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct scsi_device *sdev =to_scsi_device (dev); +struct scsi_device_handler *scsi_dh; +int err = -EINVAL ; + +if (!sdev->scsi_dh_data) { +/* +* Attach to a device handler +*/ +if (!(scsi_dh =get_device_handler (buf))) +return err; + err =scsi_dh_handler_attach (sdev, scsi_dh); + }else { + scsi_dh = sdev->scsi_dh_data->scsi_dh; +if (!strncmp (buf,"detach" ,6 )) { +/* +* Detach from a device handler +*/ +scsi_dh_handler_detach (sdev, scsi_dh); + err =0 ; + }else if (!strncmp (buf,"activate" ,8 )) { +/* +* Activate a device handler +*/ +if (scsi_dh->activate) + err = scsi_dh->activate (sdev); +else + err =0 ; + } + } + +return err<0 ?err:count; +} + +static ssize_t +show_dh_state (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct scsi_device *sdev =to_scsi_device (dev); + +if (!sdev->scsi_dh_data) +return snprintf (buf,20 ,"detached\n" ); + +return snprintf (buf,20 ,"%s\n" , sdev->scsi_dh_data->scsi_dh->name); +} + +static struct device_attribute scsi_dh_state_attr = +__ATTR (dh_state,S_IRUGO |S_IWUSR , show_dh_state, + store_dh_state); + +/* +* scsi_dh_sysfs_attr_add - Callback for scsi_init_dh +*/ +static int scsi_dh_sysfs_attr_add (struct device *dev,void *data) +{ +struct scsi_device *sdev; +int err; + +if (!scsi_is_sdev_device (dev)) +return 0 ; + + sdev =to_scsi_device (dev); + + err =device_create_file (&sdev->sdev_gendev, + &scsi_dh_state_attr); + +return 0 ; +} + +/* +* scsi_dh_sysfs_attr_remove - Callback for scsi_exit_dh +*/ +static int scsi_dh_sysfs_attr_remove (struct device *dev,void *data) +{ +struct scsi_device *sdev; + +if (!scsi_is_sdev_device (dev)) +return 0 ; + + sdev =to_scsi_device (dev); + +device_remove_file (&sdev->sdev_gendev, + &scsi_dh_state_attr); + +return 0 ; +} + +/* * scsi_dh_notifier - notifier chain callback */ static int scsi_dh_notifier(struct notifier_block *nb,
@@ -132,7 +224,10 @@ static int scsi_dh_notifier(struct notifif (action ==BUS_NOTIFY_ADD_DEVICE ) { err =scsi_dh_handler_attach (sdev, devinfo); +if (!err) + err =device_create_file (dev, &scsi_dh_state_attr); }else if (action ==BUS_NOTIFY_DEL_DEVICE ) { +device_remove_file (dev, &scsi_dh_state_attr);scsi_dh_handler_detach (sdev,NULL ); } out:
@@ -284,11 +379,17 @@ static int __init scsi_dh_init(void) r =bus_register_notifier (&scsi_bus_type, &scsi_dh_nb); +if (!r) +bus_for_each_dev (&scsi_bus_type,NULL ,NULL , + scsi_dh_sysfs_attr_add); +return r; } static void __exit scsi_dh_exit(void) { +bus_for_each_dev (&scsi_bus_type,NULL ,NULL , + scsi_dh_sysfs_attr_remove);bus_unregister_notifier (&scsi_bus_type, &scsi_dh_nb); }
PATCH 3/8 scsi_dh: Update EMC handler
In reply to Chandra SeetharamanThis patch converts the EMC device handler to use a proper state machine. We now also parse the extended INQUIRY information to determine if long trespass commands are supported. And we're now using the long trespass command correctly. And finally there's now an check at init time to refuse to attach to devices not supporting EMC-specific VPD pages.
--- drivers/scsi/device_handler/scsi_dh_emc.c | 546 ++++++++++++++++++++--------- 1 files changed, 371 insertions(+), 175 deletions(-)
drivers/scsi/device_handler/scsi_dh_emc.c +372 -175
@@ -25,28 +25,31 @@#include <scsi/scsi_dh.h> #include <scsi/scsi_device.h> -#define CLARIION_NAME "emc_clariion" +#define CLARIION_NAME "emc"#define CLARIION_TRESPASS_PAGE 0x22 -#define CLARIION_BUFFER_SIZE 0x80 +#define CLARIION_BUFFER_SIZE 0xFC#define CLARIION_TIMEOUT (60 * HZ)#define CLARIION_RETRIES 3#define CLARIION_UNBOUND_LU -1 +#define CLARIION_SP_A 0 +#define CLARIION_SP_B 1 -static unsigned char long_trespass[] = { -0 ,0 ,0 ,0 , -CLARIION_TRESPASS_PAGE ,/* Page code */ -0x09 ,/* Page length - 2 */ -0x81 ,/* Trespass code + Honor reservation bit */ -0xff ,0xff ,/* Trespass target */ -0 ,0 ,0 ,0 ,0 ,0 /* Reserved bytes / unknown */ -}; +/* Flags */ +#define CLARIION_SHORT_TRESPASS 1 +#define CLARIION_HONOR_RESERVATIONS 2 + +/* LUN states */ +#define CLARIION_LUN_UNINITIALIZED -1 +#define CLARIION_LUN_UNBOUND 0 +#define CLARIION_LUN_BOUND 1 +#define CLARIION_LUN_OWNED 2 -static unsigned char long_trespass_hr[] = { -0 ,0 ,0 ,0 , +static unsigned char long_trespass[] = { +0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,CLARIION_TRESPASS_PAGE ,/* Page code */ 0x09 ,/* Page length - 2 */ -0x01 ,/* Trespass code + Honor reservation bit */ +0x01 ,/* Trespass code */ 0xff ,0xff ,/* Trespass target */ 0 ,0 ,0 ,0 ,0 ,0 /* Reserved bytes / unknown */ };
@@ -55,39 +58,56 @@ static unsigned char short_trespass[] =0 ,0 ,0 ,0 ,CLARIION_TRESPASS_PAGE ,/* Page code */ 0x02 ,/* Page length - 2 */ -0x81 ,/* Trespass code + Honor reservation bit */ +0x01 ,/* Trespass code */ 0xff, /* Trespass target */ }; -static unsigned char short_trespass_hr[] = { -0 ,0 ,0 ,0 , -CLARIION_TRESPASS_PAGE ,/* Page code */ -0x02 ,/* Page length - 2 */ -0x01 ,/* Trespass code + Honor reservation bit */ -0xff ,/* Trespass target */ +static const char * lun_state[] = +{ +"not bound" , +"bound" , +"owned" , };struct clariion_dh_data {/* +* Flags: +* CLARIION_SHORT_TRESPASS * Use short trespass command (FC-series) or the long version * (default for AX/CX CLARiiON arrays). -*/ -unsigned short_trespass; -/* +* +* CLARIION_HONOR_RESERVATIONS * Whether or not (default) to honor SCSI reservations when * initiating a switch-over. */ -unsigned hr; -/* I/O buffer for both MODE_SELECT and INQUIRY commands. */ +unsigned flags; +/* +* I/O buffer for both MODE_SELECT and INQUIRY commands. +*/ char buffer[CLARIION_BUFFER_SIZE ];/* * SCSI sense buffer for commands -- assumes serial issuance * and completion sequence of all commands for same multipath. */ unsigned char sense[SCSI_SENSE_BUFFERSIZE ]; -/* which SP (A=0,B=1,UNBOUND=-1) is dflt SP for path's mapped dev */ +unsigned int senselen; +/* +* LUN state +*/ +int lun_state; +/* +* SP Port number +*/ +int port; +/* +* which SP (A=0,B=1,UNBOUND=-1) is the default SP for this +* path's mapped LUN +*/ int default_sp; -/* which SP (A=0,B=1,UNBOUND=-1) is active for path's mapped dev */ +/* +* which SP (A=0,B=1,UNBOUND=-1) is the active SP for this +* path's mapped LUN +*/ int current_sp; };
@@ -102,19 +122,16 @@ static inline struct clariion_dh_data/* * Parse MODE_SELECT cmd reply. */ -static int trespass_endio (struct scsi_device *sdev,int result) +static int trespass_endio (struct scsi_device *sdev,char *sense) { -int err =SCSI_DH_OK ; +int err =SCSI_DH_IO ;struct scsi_sense_hdr sshdr; -struct clariion_dh_data *csdev =get_clariion_data (sdev); -char *sense = csdev->sense; -if (status_byte (result) ==CHECK_CONDITION && -scsi_normalize_sense (sense,SCSI_SENSE_BUFFERSIZE , &sshdr)) { -sdev_printk (KERN_ERR , sdev,"Found valid sense data 0x%2x, " +if (!scsi_normalize_sense (sense,SCSI_SENSE_BUFFERSIZE , &sshdr)) { +sdev_printk (KERN_ERR , sdev,"%s: Found valid sense data 0x%2x, " "0x%2x, 0x%2x while sending CLARiiON trespass " -"command.\n" , sshdr.sense_key, sshdr.asc, - sshdr.ascq); +"command.\n" ,CLARIION_NAME , sshdr.sense_key, + sshdr.asc, sshdr.ascq);if ((sshdr.sense_key ==0x05 ) && (sshdr.asc ==0x04 ) && (sshdr.ascq ==0x00 )) {
@@ -122,9 +139,9 @@ static int trespass_endio(struct scsi_de* Array based copy in progress -- do not send * mode_select or copy will be aborted mid-stream. */ -sdev_printk (KERN_INFO , sdev,"Array Based Copy in " +sdev_printk (KERN_INFO , sdev,"%s: Array Based Copy in " "progress while sending CLARiiON trespass " -"command.\n" ); +"command.\n" ,CLARIION_NAME ); err =SCSI_DH_DEV_TEMP_BUSY ; }else if ((sshdr.sense_key ==0x02 ) && (sshdr.asc ==0x04 ) && (sshdr.ascq ==0x03 )) {
@@ -132,109 +149,113 @@ static int trespass_endio(struct scsi_de* LUN Not Ready - Manual Intervention Required * indicates in-progress ucode upgrade (NDU). */ -sdev_printk (KERN_INFO , sdev,"Detected in-progress " +sdev_printk (KERN_INFO , sdev,"%s: Detected in-progress " "ucode upgrade NDU operation while sending " -"CLARiiON trespass command.\n" ); +"CLARiiON trespass command.\n" ,CLARIION_NAME ); err =SCSI_DH_DEV_TEMP_BUSY ; }else err =SCSI_DH_DEV_FAILED ; - }else if (result) { -sdev_printk (KERN_ERR , sdev,"Error 0x%x while sending " -"CLARiiON trespass command.\n" , result); - err =SCSI_DH_IO ; + }else { +sdev_printk (KERN_INFO , sdev, +"%s: failed to send MODE SELECT, no sense available\n" , +CLARIION_NAME ); } -return err; } -static int parse_sp_info_reply (struct scsi_device *sdev,int result, -int *default_sp,int *current_sp,int *new_current_sp) +static int parse_sp_info_reply (struct scsi_device *sdev, +struct clariion_dh_data *csdev) {int err =SCSI_DH_OK ; -struct clariion_dh_data *csdev =get_clariion_data (sdev); - -if (result ==0 ) { -/* check for in-progress ucode upgrade (NDU) */ -if (csdev->buffer[48 ] !=0 ) { -sdev_printk (KERN_NOTICE , sdev,"Detected in-progress " -"ucode upgrade NDU operation while finding " -"current active SP." ); - err =SCSI_DH_DEV_TEMP_BUSY ; - }else { - *default_sp = csdev->buffer[5 ]; - -if (csdev->buffer[4 ] ==2 ) -/* SP for path is current */ - *current_sp = csdev->buffer[8 ]; -else { -if (csdev->buffer[4 ] ==1 ) -/* SP for this path is NOT current */ -if (csdev->buffer[8 ] ==0 ) - *current_sp =1 ; -else - *current_sp =0 ; -else -/* unbound LU or LUNZ */ - *current_sp =CLARIION_UNBOUND_LU ; - } - *new_current_sp = csdev->buffer[8 ]; - } - }else { -struct scsi_sense_hdr sshdr; - err =SCSI_DH_IO ; - -if (scsi_normalize_sense (csdev->sense,SCSI_SENSE_BUFFERSIZE , - &sshdr)) -sdev_printk (KERN_ERR , sdev,"Found valid sense data " -"0x%2x, 0x%2x, 0x%2x while finding current " -"active SP." , sshdr.sense_key, sshdr.asc, - sshdr.ascq); -else -sdev_printk (KERN_ERR , sdev,"Error 0x%x finding " -"current active SP." , result); +/* check for in-progress ucode upgrade (NDU) */ +if (csdev->buffer[48 ] !=0 ) { +sdev_printk (KERN_NOTICE , sdev,"%s: Detected in-progress " +"ucode upgrade NDU operation while finding " +"current active SP." ,CLARIION_NAME ); + err =SCSI_DH_DEV_TEMP_BUSY ; + goto out; + } +if (csdev->buffer[4 ] <0 || csdev->buffer[4 ] >2 ) { +/* Invalid buffer format */ +sdev_printk (KERN_NOTICE , sdev, +"%s: invalid VPD page 0xC0 format\n" , +CLARIION_NAME ); + err =SCSI_DH_NOSYS ; + goto out; + } +switch (csdev->buffer[28 ] &0x0f ) { +case 6 : +sdev_printk (KERN_NOTICE , sdev, +"%s: ALUA failover mode detected\n" , +CLARIION_NAME ); +break ; +case 4 : +/* Linux failover */ +break ; +default : +sdev_printk (KERN_WARNING , sdev, +"%s: Invalid failover mode %d\n" , +CLARIION_NAME , csdev->buffer[28 ] &0x0f ); + err =SCSI_DH_NOSYS ; + goto out; } + csdev->default_sp = csdev->buffer[5 ]; + csdev->lun_state = csdev->buffer[4 ]; + csdev->current_sp = csdev->buffer[8 ]; + csdev->port = csdev->buffer[7 ]; + +out:return err; } -static int sp_info_endio (struct scsi_device *sdev,int result, -int mode_select_sent,int *done) +#define emc_default_str "FC (Legacy)" + +static char *parse_sp_model (struct scsi_device *sdev,unsigned char *buffer) { -struct clariion_dh_data *csdev =get_clariion_data (sdev); -int err_flags, default_sp, current_sp, new_current_sp; +unsigned char len = buffer[4 ] +5 ; +char *sp_model =NULL ; +unsigned char sp_len, serial_len; + +if (len <160 ) { +sdev_printk (KERN_WARNING , sdev, +"%s: Invalid information section length %d\n" , +CLARIION_NAME , len); +/* Check for old FC arrays */ +if (!strncmp (buffer +8 ,"DGC" ,3 )) { +/* Old FC array, not supporting extended information */ + sp_model = emc_default_str; + } + goto out; + } - err_flags =parse_sp_info_reply (sdev, result, &default_sp, - ¤t_sp, &new_current_sp); +/* +* Parse extended information for SP model number +*/ + serial_len = buffer[160 ]; +if (serial_len ==0 || serial_len +161 > len) { +sdev_printk (KERN_WARNING , sdev, +"%s: Invalid array serial number length %d\n" , +CLARIION_NAME , serial_len); + goto out; + } + sp_len = buffer[99 ]; +if (sp_len ==0 || serial_len + sp_len +161 > len) { +sdev_printk (KERN_WARNING , sdev, +"%s: Invalid model number length %d\n" , +CLARIION_NAME , sp_len); + goto out; + } + sp_model = &buffer[serial_len +161 ]; +/* Strip whitespace at the end */ +while (sp_len >1 && sp_model[sp_len -1 ] ==' ' ) + sp_len--; -if (err_flags !=SCSI_DH_OK ) - goto done; + sp_model[sp_len] ='\0' ; -if (mode_select_sent) { - csdev->default_sp = default_sp; - csdev->current_sp = current_sp; - }else { -/* -* Issue the actual module_selec request IFF either -* (1) we do not know the identity of the current SP OR -* (2) what we think we know is actually correct. -*/ -if ((current_sp !=CLARIION_UNBOUND_LU ) && - (new_current_sp != current_sp)) { - - csdev->default_sp = default_sp; - csdev->current_sp = current_sp; - -sdev_printk (KERN_INFO , sdev,"Ignoring path group " -"switch-over command for CLARiiON SP%s since " -" mapped device is already initialized." , - current_sp ?"B" :"A" ); -if (done) - *done =1 ;/* as good as doing it */ - } - } -done: -return err_flags; +out: +return sp_model; }/*
@@ -244,48 +265,37 @@ done:* Uses data and sense buffers in hardware handler context structure and * assumes serial servicing of commands, both issuance and completion. */ -static struct request *get_req (struct scsi_device *sdev,int cmd) +static struct request *get_req (struct scsi_device *sdev,int cmd, +unsigned char *buffer) { -struct clariion_dh_data *csdev =get_clariion_data (sdev);struct request *rq; -unsigned char *page22;int len =0 ; rq =blk_get_request (sdev->request_queue, - (cmd ==MODE_SELECT ) ?WRITE :READ ,GFP_ATOMIC ); + (cmd ==MODE_SELECT ) ?WRITE :READ ,GFP_NOIO );if (!rq) {sdev_printk (KERN_INFO , sdev,"get_req: blk_get_request failed" );return NULL ; } -memset (&rq->cmd,0 ,BLK_MAX_CDB ); +memset (rq->cmd,0 ,BLK_MAX_CDB ); + rq->cmd_len =COMMAND_SIZE (cmd); rq->cmd[0 ] = cmd; - rq->cmd_len =COMMAND_SIZE (rq->cmd[0 ]);switch (cmd) {case MODE_SELECT : -if (csdev->short_trespass) { - page22 = csdev->hr ? short_trespass_hr : short_trespass; - len =sizeof (short_trespass); - }else { - page22 = csdev->hr ? long_trespass_hr : long_trespass; - len =sizeof (long_trespass); - } -/* -* Can't DMA from kernel BSS -- must copy selected trespass -* command mode page contents to context buffer which is -* allocated by kmalloc. -*/ -BUG_ON ((len >CLARIION_BUFFER_SIZE )); -memcpy (csdev->buffer, page22, len); + len =sizeof (short_trespass); + rq->cmd_flags |=REQ_RW ; + rq->cmd[1 ] =0x10 ; +break ; +case MODE_SELECT_10 : + len =sizeof (long_trespass); rq->cmd_flags |=REQ_RW ; rq->cmd[1 ] =0x10 ;break ;case INQUIRY : - rq->cmd[1 ] =0x1 ; - rq->cmd[2 ] =0xC0 ; len =CLARIION_BUFFER_SIZE ; -memset (csdev->buffer,0 ,CLARIION_BUFFER_SIZE ); +memset (buffer,0 , len);break ;default :BUG_ON (1 );
@@ -298,47 +308,94 @@ static struct request *get_req(struct sc rq->timeout =CLARIION_TIMEOUT ; rq->retries =CLARIION_RETRIES ; - rq->sense = csdev->sense; -memset (rq->sense,0 ,SCSI_SENSE_BUFFERSIZE ); - rq->sense_len =0 ; - -if (blk_rq_map_kern (sdev->request_queue, rq, csdev->buffer, - len,GFP_ATOMIC )) { -__blk_put_request (rq->q, rq); +if (blk_rq_map_kern (rq->q, rq, buffer, len,GFP_NOIO )) { +blk_put_request (rq);return NULL ; }return rq; } -static int send_cmd (struct scsi_device *sdev,int cmd) +static int send_inquiry_cmd (struct scsi_device *sdev,int page, +struct clariion_dh_data *csdev) { -struct request *rq =get_req (sdev, cmd); +struct request *rq =get_req (sdev,INQUIRY , csdev->buffer); +int err;if (!rq)return SCSI_DH_RES_TEMP_UNAVAIL ; -return blk_execute_rq (sdev->request_queue,NULL , rq,1 ); + rq->sense = csdev->sense; +memset (rq->sense,0 ,SCSI_SENSE_BUFFERSIZE ); + rq->sense_len = csdev->senselen =0 ; + + rq->cmd[0 ] =INQUIRY ; +if (page !=0 ) { + rq->cmd[1 ] =1 ; + rq->cmd[2 ] = page; + } + err =blk_execute_rq (sdev->request_queue,NULL , rq,1 ); +if (err == -EIO ) { +sdev_printk (KERN_INFO , sdev, +"%s: failed to send %s INQUIRY: %x\n" , +CLARIION_NAME , page?"EVPD" :"standard" , + rq->errors); + csdev->senselen = rq->sense_len; + err =SCSI_DH_IO ; + } + +blk_put_request (rq); + +return err; } -static int clariion_activate (struct scsi_device *sdev) +static int send_trespass_cmd (struct scsi_device *sdev, +struct clariion_dh_data *csdev) { -int result, done =0 ; +struct request *rq; +unsigned char *page22; +int err, len, cmd; - result =send_cmd (sdev,INQUIRY ); - result =sp_info_endio (sdev, result,0 , &done); -if (result || done) - goto done; +if (csdev->flags &CLARIION_SHORT_TRESPASS ) { + page22 = short_trespass; +if (!(csdev->flags &CLARIION_HONOR_RESERVATIONS )) +/* Set Honor Reservations bit */ + page22[6 ] |=0x80 ; + len =sizeof (short_trespass); + cmd =MODE_SELECT ; + }else { + page22 = long_trespass; +if (!(csdev->flags &CLARIION_HONOR_RESERVATIONS )) +/* Set Honor Reservations bit */ + page22[10 ] |=0x80 ; + len =sizeof (long_trespass); + cmd =MODE_SELECT_10 ; + } +BUG_ON ((len >CLARIION_BUFFER_SIZE )); +memcpy (csdev->buffer, page22, len); - result =send_cmd (sdev,MODE_SELECT ); - result =trespass_endio (sdev, result); -if (result) - goto done; + rq =get_req (sdev, cmd, csdev->buffer); +if (!rq) +return SCSI_DH_RES_TEMP_UNAVAIL ; - result =send_cmd (sdev,INQUIRY ); - result =sp_info_endio (sdev, result,1 ,NULL ); -done: -return result; + rq->sense = csdev->sense; +memset (rq->sense,0 ,SCSI_SENSE_BUFFERSIZE ); + rq->sense_len = csdev->senselen =0 ; + + err =blk_execute_rq (sdev->request_queue,NULL , rq,1 ); +if (err == -EIO ) { +if (rq->sense_len) { + err =trespass_endio (sdev, csdev->sense); + }else { +sdev_printk (KERN_INFO , sdev, +"%s: failed to send MODE SELECT: %x\n" , +CLARIION_NAME , rq->errors); + } + } + +blk_put_request (rq); + +return err; } static int clariion_check_sense(struct scsi_device *sdev,
@@ -386,13 +443,129 @@ static int clariion_check_sense(struct sbreak ; } -/* success just means we do not care what scsi-ml does */ -return SUCCESS ; +return SCSI_RETURN_NOT_HANDLED ; +} + +static int clariion_prep_fn (struct scsi_device *sdev,struct request *req) +{ +struct clariion_dh_data *h =get_clariion_data (sdev); +int ret =BLKPREP_OK ; + +if (h->lun_state !=CLARIION_LUN_OWNED ) { + ret =BLKPREP_KILL ; + req->cmd_flags |=REQ_QUIET ; + } +return ret; + +} + +static int clariion_std_inquiry (struct scsi_device *sdev, +struct clariion_dh_data *csdev) +{ +int err; +char *sp_model; + + err =send_inquiry_cmd (sdev,0 , csdev); +if (err !=SCSI_DH_OK && csdev->senselen) { +struct scsi_sense_hdr sshdr; + +if (scsi_normalize_sense (csdev->sense,SCSI_SENSE_BUFFERSIZE , + &sshdr)) { +sdev_printk (KERN_ERR , sdev,"%s: INQUIRY sense code " +"%02x/%02x/%02x\n" ,CLARIION_NAME , + sshdr.sense_key, sshdr.asc, sshdr.ascq); + } + err =SCSI_DH_IO ; + goto out; + } + + sp_model =parse_sp_model (sdev, csdev->buffer); +if (!sp_model) { + err =SCSI_DH_DEV_UNSUPP ; + goto out; + } + +/* +* FC Series arrays do not support long trespass +*/ +if (!strlen (sp_model) || !strncmp (sp_model,"FC" ,2 )) + csdev->flags |=CLARIION_SHORT_TRESPASS ; + +sdev_printk (KERN_INFO , sdev, +"%s: detected Clariion %s, flags %x\n" , +CLARIION_NAME , sp_model, csdev->flags); +out: +return err; +} + +static int clariion_send_inquiry (struct scsi_device *sdev, +struct clariion_dh_data *csdev) +{ +int err, retry =CLARIION_RETRIES ; + +retry: + err =send_inquiry_cmd (sdev,0xC0 , csdev); +if (err !=SCSI_DH_OK && csdev->senselen) { +struct scsi_sense_hdr sshdr; + + err =scsi_normalize_sense (csdev->sense,SCSI_SENSE_BUFFERSIZE , + &sshdr); +if (!err) +return SCSI_DH_IO ; + + err =clariion_check_sense (sdev, &sshdr); +if (retry >0 && err ==NEEDS_RETRY ) { + retry--; + goto retry; + } +sdev_printk (KERN_ERR , sdev,"%s: INQUIRY sense code " +"%02x/%02x/%02x\n" ,CLARIION_NAME , + sshdr.sense_key, sshdr.asc, sshdr.ascq); + err =SCSI_DH_IO ; + }else { + err =parse_sp_info_reply (sdev, csdev); + } +return err; +} + +static int clariion_activate (struct scsi_device *sdev) +{ +struct clariion_dh_data *csdev =get_clariion_data (sdev); +int result; + + result =clariion_send_inquiry (sdev, csdev); +if (result !=SCSI_DH_OK ) + goto done; + +if (csdev->lun_state ==CLARIION_LUN_OWNED ) + goto done; + + result =send_trespass_cmd (sdev, csdev); +if (result !=SCSI_DH_OK ) + goto done; +sdev_printk (KERN_INFO , sdev,"%s: %s trespass command sent\n" , +CLARIION_NAME , + csdev->flags&CLARIION_SHORT_TRESPASS ?"short" :"long" ); + +/* Update status */ + result =clariion_send_inquiry (sdev, csdev); +if (result !=SCSI_DH_OK ) + goto done; + +done: +sdev_printk (KERN_INFO , sdev, +"%s: at SP %c Port %d (%s, default SP %c)\n" , +CLARIION_NAME , csdev->current_sp +'A' , + csdev->port, lun_state[csdev->lun_state], + csdev->default_sp +'A' ); + +return result; }const struct scsi_dh_devlist clariion_dev_list[] = { {"DGC" ,"RAID" }, {"DGC" ,"DISK" }, + {"DGC" ,"VRAID" }, {NULL ,NULL }, };
@@ -407,6 +580,7 @@ static struct scsi_device_handler clarii .detach = clariion_bus_detach, .check_sense = clariion_check_sense, .activate = clariion_activate, + .prep_fn = clariion_prep_fn, };/*
@@ -417,28 +591,50 @@ static int clariion_bus_attach(struct scstruct scsi_dh_data *scsi_dh_data;struct clariion_dh_data *h;unsigned long flags; +int err; scsi_dh_data =kzalloc (sizeof (struct scsi_device_handler *) +sizeof (*h) ,GFP_KERNEL );if (!scsi_dh_data) { -sdev_printk (KERN_ERR , sdev,"Attach failed %s.\n" , +sdev_printk (KERN_ERR , sdev,"%s: Attach failed\n" ,CLARIION_NAME );return -ENOMEM ; } scsi_dh_data->scsi_dh = &clariion_dh; h = (struct clariion_dh_data *) scsi_dh_data->buf; + h->lun_state =CLARIION_LUN_UNINITIALIZED ; h->default_sp =CLARIION_UNBOUND_LU ; h->current_sp =CLARIION_UNBOUND_LU ; + err =clariion_std_inquiry (sdev, h); +if (err !=SCSI_DH_OK ) + goto failed; + + err =clariion_send_inquiry (sdev, h); +if (err !=SCSI_DH_OK ) + goto failed; + +if (!try_module_get (THIS_MODULE )) + goto failed; +spin_lock_irqsave (sdev->request_queue->queue_lock, flags); sdev->scsi_dh_data = scsi_dh_data;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); -sdev_printk (KERN_NOTICE , sdev,"Attached %s.\n" ,CLARIION_NAME ); -try_module_get (THIS_MODULE ); +sdev_printk (KERN_INFO , sdev, +"%s: connected to SP %c Port %d (%s, default SP %c)\n" , +CLARIION_NAME , h->current_sp +'A' , + h->port, lun_state[h->lun_state], + h->default_sp +'A' );return 0 ; + +failed: +kfree (scsi_dh_data); +sdev_printk (KERN_ERR , sdev,"%s: not attached\n" , +CLARIION_NAME ); +return -EINVAL ; }static void clariion_bus_detach (struct scsi_device *sdev)
@@ -451,7 +647,7 @@ static void clariion_bus_detach(struct s sdev->scsi_dh_data =NULL ;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); -sdev_printk (KERN_NOTICE , sdev,"Detached %s.\n" , +sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,CLARIION_NAME );kfree (scsi_dh_data);
@@ -464,7 +660,8 @@ static int __init clariion_init(void) r =scsi_register_device_handler (&clariion_dh);if (r !=0 ) -printk (KERN_ERR "Failed to register scsi device handler." ); +printk (KERN_ERR "%s: Failed to register scsi device handler." , +CLARIION_NAME );return r; }
include/scsi/scsi_dh.h +1 -0
@@ -32,6 +32,7 @@ enum {*/ SCSI_DH_DEV_FAILED ,/* generic device error */ SCSI_DH_DEV_TEMP_BUSY , +SCSI_DH_DEV_UNSUPP ,/* device handler not supported */ SCSI_DH_DEVICE_MAX, /* max device blkerr definition *//*
PATCH 4/8 scsi_dh: Update hp_sw hardware handler
In reply to Chandra SeetharamanThis patch updates the hp_sw device handler to properly check the return codes etc.
And adds the 'correct' machine definitions.
--- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 272 +++++++++++++++++++++++---- 1 files changed, 234 insertions(+), 38 deletions(-)
drivers/scsi/device_handler/scsi_dh_hp_sw.c +234 -38
@@ -4,6 +4,7 @@* * Copyright (C) 2006 Red Hat, Inc. All rights reserved. * Copyright (C) 2006 Mike Christie +* Copyright (C) 2008 Hannes Reinecke <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
@@ -25,13 +26,18 @@#include <scsi/scsi_eh.h> #include <scsi/scsi_dh.h> -#define HP_SW_NAME "hp_sw" +#define HP_SW_NAME "hp_sw" -#define HP_SW_TIMEOUT (60 * HZ) -#define HP_SW_RETRIES 3 +#define HP_SW_TIMEOUT (60 * HZ) +#define HP_SW_RETRIES 3 + +#define HP_SW_PATH_UNINITIALIZED -1 +#define HP_SW_PATH_ACTIVE 0 +#define HP_SW_PATH_PASSIVE 1struct hp_sw_dh_data {unsigned char sense[SCSI_SENSE_BUFFERSIZE ]; +int path_state;int retries; };
@@ -42,51 +48,161 @@ static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)return ((struct hp_sw_dh_data *) scsi_dh_data->buf); } -static int hp_sw_done (struct scsi_device *sdev) +/* +* tur_done - Handle TEST UNIT READY return status +* @sdev: sdev the command has been sent to +* @errors: blk error code +* +* Returns SCSI_DH_DEV_OFFLINED if the sdev is on the passive path +*/ +static int tur_done (struct scsi_device *sdev,unsigned char *sense) { -struct hp_sw_dh_data *h =get_hp_sw_data (sdev);struct scsi_sense_hdr sshdr; -int rc; - -sdev_printk (KERN_INFO , sdev,"hp_sw_done\n" ); +int ret; - rc =scsi_normalize_sense (h->sense,SCSI_SENSE_BUFFERSIZE , &sshdr); -if (!rc) + ret =scsi_normalize_sense (sense,SCSI_SENSE_BUFFERSIZE , &sshdr); +if (!ret) { +sdev_printk (KERN_WARNING , sdev, +"%s: sending tur failed, no sense available\n" , +HP_SW_NAME ); + ret =SCSI_DH_IO ; goto done; + }switch (sshdr.sense_key) { +case UNIT_ATTENTION : + ret =SCSI_DH_IMM_RETRY ; +break ;case NOT_READY : -if ((sshdr.asc ==0x04 ) && (sshdr.ascq ==3 )) { - rc =SCSI_DH_RETRY ; - h->retries++; +if ((sshdr.asc ==0x04 ) && (sshdr.ascq ==2 )) { +/* +* LUN not ready - Initialization command required +* +* This is the passive path +*/ + ret =SCSI_DH_DEV_OFFLINED ;break ; } -/* fall through */ +/* Fallthrough */ default : - h->retries++; - rc =SCSI_DH_IMM_RETRY ; +sdev_printk (KERN_WARNING , sdev, +"%s: sending tur failed, sense %x/%x/%x\n" , +HP_SW_NAME , sshdr.sense_key, sshdr.asc, + sshdr.ascq); +break ; } done: -if (rc ==SCSI_DH_OK || rc ==SCSI_DH_IO ) - h->retries =0 ; -else if (h->retries >HP_SW_RETRIES ) { - h->retries =0 ; +return ret; +} + +/* +* hp_sw_tur - Send TEST UNIT READY +* @sdev: sdev command should be sent to +* +* Use the TEST UNIT READY command to determine +* the path state. +*/ +static int hp_sw_tur (struct scsi_device *sdev,struct hp_sw_dh_data *h) +{ +struct request *req; +int ret; + + req =blk_get_request (sdev->request_queue,WRITE ,GFP_NOIO ); +if (!req) +return SCSI_DH_RES_TEMP_UNAVAIL ; + + req->cmd_type =REQ_TYPE_BLOCK_PC ; + req->cmd_flags |=REQ_FAILFAST ; + req->cmd_len =COMMAND_SIZE (TEST_UNIT_READY ); +memset (req->cmd,0 ,MAX_COMMAND_SIZE ); + req->cmd[0 ] =TEST_UNIT_READY ; + req->timeout =HP_SW_TIMEOUT ; + req->sense = h->sense; +memset (req->sense,0 ,SCSI_SENSE_BUFFERSIZE ); + req->sense_len =0 ; + +retry: + ret =blk_execute_rq (req->q,NULL , req,1 ); +if (ret == -EIO ) { +if (req->sense_len >0 ) { + ret =tur_done (sdev, h->sense); + }else { +sdev_printk (KERN_WARNING , sdev, +"%s: sending tur failed with %x\n" , +HP_SW_NAME , req->errors); + ret =SCSI_DH_IO ; + } + }else { + h->path_state =HP_SW_PATH_ACTIVE ; + ret =SCSI_DH_OK ; + } +if (ret ==SCSI_DH_IMM_RETRY ) + goto retry; +if (ret ==SCSI_DH_DEV_OFFLINED ) { + h->path_state =HP_SW_PATH_PASSIVE ; + ret =SCSI_DH_OK ; + } + +blk_put_request (req); + +return ret; +} + +/* +* start_done - Handle START STOP UNIT return status +* @sdev: sdev the command has been sent to +* @errors: blk error code +*/ +static int start_done (struct scsi_device *sdev,unsigned char *sense) +{ +struct scsi_sense_hdr sshdr; +int rc; + + rc =scsi_normalize_sense (sense,SCSI_SENSE_BUFFERSIZE , &sshdr); +if (!rc) { +sdev_printk (KERN_WARNING , sdev, +"%s: sending start_stop_unit failed, " +"no sense available\n" , +HP_SW_NAME ); +return SCSI_DH_IO ; + } +switch (sshdr.sense_key) { +case NOT_READY : +if ((sshdr.asc ==0x04 ) && (sshdr.ascq ==3 )) { +/* +* LUN not ready - manual intervention required +* +* Switch-over in progress, retry. +*/ + rc =SCSI_DH_RETRY ; +break ; + } +/* fall through */ +default : +sdev_printk (KERN_WARNING , sdev, +"%s: sending start_stop_unit failed, sense %x/%x/%x\n" , +HP_SW_NAME , sshdr.sense_key, sshdr.asc, + sshdr.ascq); rc =SCSI_DH_IO ; } +return rc; } -static int hp_sw_activate (struct scsi_device *sdev) +/* +* hp_sw_start_stop - Send START STOP UNIT command +* @sdev: sdev command should be sent to +* +* Sending START STOP UNIT activates the SP. +*/ +static int hp_sw_start_stop (struct scsi_device *sdev,struct hp_sw_dh_data *h) { -struct hp_sw_dh_data *h =get_hp_sw_data (sdev);struct request *req; -int ret =SCSI_DH_RES_TEMP_UNAVAIL ; +int ret, retry; - req =blk_get_request (sdev->request_queue,WRITE ,GFP_ATOMIC ); + req =blk_get_request (sdev->request_queue,WRITE ,GFP_NOIO );if (!req) - goto done; - -sdev_printk (KERN_INFO , sdev,"sending START_STOP." ); +return SCSI_DH_RES_TEMP_UNAVAIL ; req->cmd_type =REQ_TYPE_BLOCK_PC ; req->cmd_flags |=REQ_FAILFAST ;
@@ -98,19 +214,78 @@ static int hp_sw_activate(struct scsi_device *sdev) req->sense = h->sense;memset (req->sense,0 ,SCSI_SENSE_BUFFERSIZE ); req->sense_len =0 ; + retry = h->retries; +retry: ret =blk_execute_rq (req->q,NULL , req,1 ); -if (!ret)/* SUCCESS */ - ret =hp_sw_done (sdev); -else +if (ret == -EIO ) { +if (req->sense_len >0 ) { + ret =start_done (sdev, h->sense); + }else { +sdev_printk (KERN_WARNING , sdev, +"%s: sending start_stop_unit failed with %x\n" , +HP_SW_NAME , req->errors); + ret =SCSI_DH_IO ; + } + }else + ret =SCSI_DH_OK ; + +if (ret ==SCSI_DH_RETRY ) { +if (--retry) + goto retry; ret =SCSI_DH_IO ; -done: + } + +blk_put_request (req); + +return ret; +} + +static int hp_sw_prep_fn (struct scsi_device *sdev,struct request *req) +{ +struct hp_sw_dh_data *h =get_hp_sw_data (sdev); +int ret =BLKPREP_OK ; + +if (h->path_state !=HP_SW_PATH_ACTIVE ) { + ret =BLKPREP_KILL ; + req->cmd_flags |=REQ_QUIET ; + } +return ret; + +} + +/* +* hp_sw_activate - Activate a path +* @sdev: sdev on the path to be activated +* +* The HP Active/Passive firmware is pretty simple; +* the passive path reports NOT READY with sense codes +* 0x04/0x02; a START STOP UNIT command will then +* activate the passive path (and deactivate the +* previously active one). +*/ +static int hp_sw_activate (struct scsi_device *sdev) +{ +int ret =SCSI_DH_OK ; +struct hp_sw_dh_data *h =get_hp_sw_data (sdev); + + ret =hp_sw_tur (sdev, h); + +if (ret ==SCSI_DH_OK && h->path_state ==HP_SW_PATH_PASSIVE ) { + ret =hp_sw_start_stop (sdev, h); +if (ret ==SCSI_DH_OK ) +sdev_printk (KERN_INFO , sdev, +"%s: activated path\n" , +HP_SW_NAME ); + } +return ret; }const struct scsi_dh_devlist hp_sw_dh_data_list[] = { - {"COMPAQ" ,"MSA" }, - {"HP" ,"HSV" }, + {"COMPAQ" ,"MSA1000 VOLUME" }, + {"COMPAQ" ,"HSV110" }, + {"HP" ,"HSV100" }, {"DEC" ,"HSG80" }, {NULL ,NULL }, };
@@ -125,30 +300,51 @@ static struct scsi_device_handler hp_sw_dh = { .attach = hp_sw_bus_attach, .detach = hp_sw_bus_detach, .activate = hp_sw_activate, + .prep_fn = hp_sw_prep_fn, };static int hp_sw_bus_attach (struct scsi_device *sdev) {struct scsi_dh_data *scsi_dh_data; +struct hp_sw_dh_data *h;unsigned long flags; +int ret; scsi_dh_data =kzalloc (sizeof (struct scsi_device_handler *) +sizeof (struct hp_sw_dh_data ) ,GFP_KERNEL );if (!scsi_dh_data) { -sdev_printk (KERN_ERR , sdev,"Attach Failed %s.\n" , +sdev_printk (KERN_ERR , sdev,"%s: Attach Failed\n" ,HP_SW_NAME );return 0 ; } scsi_dh_data->scsi_dh = &hp_sw_dh; + h = (struct hp_sw_dh_data *) scsi_dh_data->buf; + h->path_state =HP_SW_PATH_UNINITIALIZED ; + h->retries =HP_SW_RETRIES ; + + ret =hp_sw_tur (sdev, h); +if (ret !=SCSI_DH_OK || h->path_state ==HP_SW_PATH_UNINITIALIZED ) + goto failed; + +if (!try_module_get (THIS_MODULE )) + goto failed; +spin_lock_irqsave (sdev->request_queue->queue_lock, flags); sdev->scsi_dh_data = scsi_dh_data;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); -try_module_get (THIS_MODULE ); -sdev_printk (KERN_NOTICE , sdev,"Attached %s.\n" ,HP_SW_NAME ); +sdev_printk (KERN_INFO , sdev,"%s: attached to %s path\n" , +HP_SW_NAME , h->path_state ==HP_SW_PATH_ACTIVE ? +"active" :"passive" );return 0 ; + +failed: +kfree (scsi_dh_data); +sdev_printk (KERN_ERR , sdev,"%s: not attached\n" , +HP_SW_NAME ); +return -EINVAL ; }static void hp_sw_bus_detach (struct scsi_device *sdev )
@@ -162,7 +358,7 @@ static void hp_sw_bus_detach( struct scsi_device *sdev )spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags);module_put (THIS_MODULE ); -sdev_printk (KERN_NOTICE , sdev,"Detached %s\n" ,HP_SW_NAME ); +sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,HP_SW_NAME );kfree (scsi_dh_data); }
@@ -180,6 +376,6 @@ static void __exit hp_sw_exit(void)module_init (hp_sw_init);module_exit (hp_sw_exit); -MODULE_DESCRIPTION ("HP MSA 1000" ); +MODULE_DESCRIPTION ("HP Active/Passive driver" );MODULE_AUTHOR ("Mike Christie <[email protected]" );MODULE_LICENSE ("GPL" );
Signature · 1 line
1.5.2.4
PATCH 5/8 scsi_dh: Update RDAC device handler
In reply to Chandra SeetharamanThis patch updates the RDAC device handler to
refuse to attach to devices not supporting the
RDAC vpd pages.
--- drivers/scsi/device_handler/scsi_dh_rdac.c | 163 ++++++++++++++++------------ 1 files changed, 94 insertions(+), 69 deletions(-)
drivers/scsi/device_handler/scsi_dh_rdac.c +94 -69
@@ -173,6 +173,11 @@ struct rdac_dh_data {#define RDAC_STATE_ACTIVE 0#define RDAC_STATE_PASSIVE 1unsigned char state; + +#define RDAC_LUN_UNOWNED 0 +#define RDAC_LUN_OWNED 1 +#define RDAC_LUN_AVT 2 +char lun_state;unsigned char sense[SCSI_SENSE_BUFFERSIZE ];union {struct c2_inquiry c2;
@@ -182,6 +187,13 @@ struct rdac_dh_data { } inq; }; +static const char *lun_state[] = +{ +"unowned" , +"owned" , +"owned (AVT mode)" , +}; +static LIST_HEAD (ctlr_list);static DEFINE_SPINLOCK (list_lock);
@@ -197,9 +209,8 @@ static struct request *get_rdac_req(stru {struct request *rq;struct request_queue *q = sdev->request_queue; -struct rdac_dh_data *h =get_rdac_data (sdev); - rq =blk_get_request (q, rw,GFP_KERNEL ); + rq =blk_get_request (q, rw,GFP_NOIO );if (!rq) { sdev_printk(KERN_INFO, sdev,
@@ -207,17 +218,14 @@ static struct request *get_rdac_req(strureturn NULL ; } -if (buflen &&blk_rq_map_kern (q, rq, buffer, buflen,GFP_KERNEL )) { +if (buflen &&blk_rq_map_kern (q, rq, buffer, buflen,GFP_NOIO )) {blk_put_request (rq);sdev_printk (KERN_INFO , sdev,"get_rdac_req: blk_rq_map_kern failed.\n" );return NULL ; } -memset (&rq->cmd,0 ,BLK_MAX_CDB ); - rq->sense = h->sense; -memset (rq->sense,0 ,SCSI_SENSE_BUFFERSIZE ); - rq->sense_len =0 ; +memset (rq->cmd,0 ,BLK_MAX_CDB ); rq->cmd_type =REQ_TYPE_BLOCK_PC ; rq->cmd_flags |=REQ_FAILFAST |REQ_NOMERGE ;
@@ -227,12 +235,12 @@ static struct request *get_rdac_req(strureturn rq; } -static struct request *rdac_failover_get (struct scsi_device *sdev) +static struct request *rdac_failover_get (struct scsi_device *sdev, +struct rdac_dh_data *h) {struct request *rq;struct rdac_mode_common *common;unsigned data_size; -struct rdac_dh_data *h =get_rdac_data (sdev);if (h->ctlr->use_ms10) {struct rdac_pg_expanded *rdac_pg;
@@ -277,6 +285,10 @@ static struct request *rdac_failover_get } rq->cmd_len =COMMAND_SIZE (rq->cmd[0 ]); + rq->sense = h->sense; +memset (rq->sense,0 ,SCSI_SENSE_BUFFERSIZE ); + rq->sense_len =0 ; +return rq; }
@@ -321,11 +333,10 @@ done: }static int submit_inquiry (struct scsi_device *sdev,int page_code, -unsigned int len) +unsigned int len,struct rdac_dh_data *h) {struct request *rq;struct request_queue *q = sdev->request_queue; -struct rdac_dh_data *h =get_rdac_data (sdev);int err =SCSI_DH_RES_TEMP_UNAVAIL ; rq =get_rdac_req (sdev, &h->inq, len,READ );
@@ -338,59 +349,68 @@ static int submit_inquiry(struct scsi_de rq->cmd[2 ] = page_code; rq->cmd[4 ] = len; rq->cmd_len =COMMAND_SIZE (INQUIRY ); + + rq->sense = h->sense; +memset (rq->sense,0 ,SCSI_SENSE_BUFFERSIZE ); + rq->sense_len =0 ; + err =blk_execute_rq (q,NULL , rq,1 );if (err == -EIO ) err =SCSI_DH_IO ; + +blk_put_request (rq); done:return err; } -static int get_lun (struct scsi_device *sdev) +static int get_lun (struct scsi_device *sdev,struct rdac_dh_data *h) {int err;struct c8_inquiry *inqp; -struct rdac_dh_data *h =get_rdac_data (sdev); - err =submit_inquiry (sdev,0xC8 ,sizeof (struct c8_inquiry )); + err =submit_inquiry (sdev,0xC8 ,sizeof (struct c8_inquiry ), h);if (err ==SCSI_DH_OK ) { inqp = &h->inq.c8; - h->lun = inqp->lun[7 ];/* currently it uses only one byte */ +if (inqp->page_code !=0xc8 ) +return SCSI_DH_NOSYS ; +if (inqp->page_id[0 ] !='e' || inqp->page_id[1 ] !='d' || + inqp->page_id[2 ] !='i' || inqp->page_id[3 ] !='d' ) +return SCSI_DH_NOSYS ; + h->lun =scsilun_to_int ((struct scsi_lun *)inqp->lun); }return err; } -#define RDAC_OWNED 0 -#define RDAC_UNOWNED 1 -#define RDAC_FAILED 2 -static int check_ownership (struct scsi_device *sdev) +static int check_ownership (struct scsi_device *sdev,struct rdac_dh_data *h) {int err;struct c9_inquiry *inqp; -struct rdac_dh_data *h =get_rdac_data (sdev); - err =submit_inquiry (sdev,0xC9 ,sizeof (struct c9_inquiry )); + err =submit_inquiry (sdev,0xC9 ,sizeof (struct c9_inquiry ), h);if (err ==SCSI_DH_OK ) { - err =RDAC_UNOWNED ; inqp = &h->inq.c9; -/* -* If in AVT mode or if the path already owns the LUN, -* return RDAC_OWNED; -*/ -if (((inqp->avte_cvp >>7 ) ==0x1 ) || - ((inqp->avte_cvp &0x1 ) !=0 )) - err =RDAC_OWNED ; - }else - err =RDAC_FAILED ; +if ((inqp->avte_cvp >>7 ) ==0x1 ) { +/* LUN in AVT mode */ +sdev_printk (KERN_NOTICE , sdev, +"%s: AVT mode detected\n" , +RDAC_NAME ); + h->lun_state =RDAC_LUN_AVT ; + }else if ((inqp->avte_cvp &0x1 ) !=0 ) { +/* LUN was owned by the controller */ + h->lun_state =RDAC_LUN_OWNED ; + } + } +return err; } -static int initialize_controller (struct scsi_device *sdev) +static int initialize_controller (struct scsi_device *sdev, +struct rdac_dh_data *h) {int err;struct c4_inquiry *inqp; -struct rdac_dh_data *h =get_rdac_data (sdev); - err =submit_inquiry (sdev,0xC4 ,sizeof (struct c4_inquiry )); + err =submit_inquiry (sdev,0xC4 ,sizeof (struct c4_inquiry ), h);if (err ==SCSI_DH_OK ) { inqp = &h->inq.c4; h->ctlr =get_controller (inqp->subsys_id, inqp->slot_id);
@@ -400,13 +420,12 @@ static int initialize_controller(structreturn err; } -static int set_mode_select (struct scsi_device *sdev) +static int set_mode_select (struct scsi_device *sdev,struct rdac_dh_data *h) {int err;struct c2_inquiry *inqp; -struct rdac_dh_data *h =get_rdac_data (sdev); - err =submit_inquiry (sdev,0xC2 ,sizeof (struct c2_inquiry )); + err =submit_inquiry (sdev,0xC2 ,sizeof (struct c2_inquiry ), h);if (err ==SCSI_DH_OK ) { inqp = &h->inq.c2;/*
@@ -421,13 +440,13 @@ static int set_mode_select(struct scsi_dreturn err; } -static int mode_select_handle_sense (struct scsi_device *sdev) +static int mode_select_handle_sense (struct scsi_device *sdev, +unsigned char *sensebuf) {struct scsi_sense_hdr sense_hdr; -struct rdac_dh_data *h =get_rdac_data (sdev);int sense, err =SCSI_DH_IO , ret; - ret =scsi_normalize_sense (h->sense,SCSI_SENSE_BUFFERSIZE , &sense_hdr); + ret =scsi_normalize_sense (sensebuf,SCSI_SENSE_BUFFERSIZE , &sense_hdr);if (!ret) goto done;
@@ -451,14 +470,13 @@ done:return err; } -static int send_mode_select (struct scsi_device *sdev) +static int send_mode_select (struct scsi_device *sdev,struct rdac_dh_data *h) {struct request *rq;struct request_queue *q = sdev->request_queue; -struct rdac_dh_data *h =get_rdac_data (sdev);int err =SCSI_DH_RES_TEMP_UNAVAIL ; - rq =rdac_failover_get (sdev); + rq =rdac_failover_get (sdev, h);if (!rq) goto done;
@@ -466,9 +484,11 @@ static int send_mode_select(struct scsi_ err =blk_execute_rq (q,NULL , rq,1 );if (err !=SCSI_DH_OK ) - err =mode_select_handle_sense (sdev); + err =mode_select_handle_sense (sdev, h->sense);if (err ==SCSI_DH_OK ) h->state =RDAC_STATE_ACTIVE ; + +blk_put_request (rq); done:return err; }
@@ -478,38 +498,23 @@ static int rdac_activate(struct scsi_devstruct rdac_dh_data *h =get_rdac_data (sdev);int err =SCSI_DH_OK ; -if (h->lun ==UNINITIALIZED_LUN ) { - err =get_lun (sdev); -if (err !=SCSI_DH_OK ) - goto done; - } - - err =check_ownership (sdev); -switch (err) { -case RDAC_UNOWNED : -break ; -case RDAC_OWNED : - err =SCSI_DH_OK ; - goto done; -case RDAC_FAILED : -default : - err =SCSI_DH_IO ; + err =check_ownership (sdev, h); +if (err !=SCSI_DH_OK ) goto done; - }if (!h->ctlr) { - err =initialize_controller (sdev); + err =initialize_controller (sdev, h);if (err !=SCSI_DH_OK ) goto done; }if (h->ctlr->use_ms10 ==-1 ) { - err =set_mode_select (sdev); + err =set_mode_select (sdev, h);if (err !=SCSI_DH_OK ) goto done; } - - err =send_mode_select (sdev); +if (h->lun_state ==RDAC_LUN_UNOWNED ) + err =send_mode_select (sdev, h); done:return err; }
@@ -606,11 +611,12 @@ static int rdac_bus_attach(struct scsi_dstruct scsi_dh_data *scsi_dh_data;struct rdac_dh_data *h;unsigned long flags; +int err; scsi_dh_data =kzalloc (sizeof (struct scsi_device_handler *) +sizeof (*h) ,GFP_KERNEL );if (!scsi_dh_data) { -sdev_printk (KERN_ERR , sdev,"Attach failed %s.\n" , +sdev_printk (KERN_ERR , sdev,"%s: Attach failed\n" ,RDAC_NAME );return 0 ; }
@@ -619,14 +625,33 @@ static int rdac_bus_attach(struct scsi_d h = (struct rdac_dh_data *) scsi_dh_data->buf; h->lun =UNINITIALIZED_LUN ; h->state =RDAC_STATE_ACTIVE ; + + err =get_lun (sdev, h); +if (err !=SCSI_DH_OK ) + goto failed; + + err =check_ownership (sdev, h); +if (err !=SCSI_DH_OK ) + goto failed; + +if (!try_module_get (THIS_MODULE )) + goto failed; +spin_lock_irqsave (sdev->request_queue->queue_lock, flags); sdev->scsi_dh_data = scsi_dh_data;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); -try_module_get (THIS_MODULE ); -sdev_printk (KERN_NOTICE , sdev,"Attached %s\n" ,RDAC_NAME ); +sdev_printk (KERN_NOTICE , sdev, +"%s: LUN %d (%s)\n" , +RDAC_NAME , h->lun, lun_state[(int )h->lun_state]);return 0 ; + +failed: +kfree (scsi_dh_data); +sdev_printk (KERN_ERR , sdev,"%s: not attached\n" , +RDAC_NAME ); +return -EINVAL ; }static void rdac_bus_detach (struct scsi_device *sdev )
@@ -645,7 +670,7 @@ static void rdac_bus_detach( struct scsikref_put (&h->ctlr->kref, release_controller);kfree (scsi_dh_data);module_put (THIS_MODULE ); -sdev_printk (KERN_NOTICE , sdev,"Detached %s\n" ,RDAC_NAME ); +sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,RDAC_NAME ); }
PATCH 6/8 scsi_dh: add generic SPC-3 alua handler
In reply to Chandra SeetharamanThis patch adds a generic SPC-3 ALUA handler.
--- drivers/scsi/device_handler/Kconfig | 8 + drivers/scsi/device_handler/Makefile | 1 + drivers/scsi/device_handler/scsi_dh_alua.c | 802 ++++++++++++++++++++++++++++ include/scsi/scsi.h | 3 + 5 files changed, 815 insertions(+), 0 deletions(-) create mode 100644 drivers/scsi/device_handler/scsi_dh_alua.c
drivers/scsi/device_handler/Kconfig +8 -0
@@ -30,3 +30,11 @@ config SCSI_DH_EMC depends on SCSI_DH help If you have a EMC CLARiiON select y. Otherwise, say N. + +config SCSI_DH_ALUA + tristate "SPC-3 ALUA Device Handler (EXPERIMENTAL)" + depends on SCSI_DH && EXPERIMENTAL + help + SCSI Device handler for generic SPC-3 Asymmetric Logical Unit + Access (ALUA). +
drivers/scsi/device_handler/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_SCSI_DH) += scsi_dh.o obj-$(CONFIG_SCSI_DH_RDAC) += scsi_dh_rdac.o obj-$(CONFIG_SCSI_DH_HP_SW) += scsi_dh_hp_sw.o obj-$(CONFIG_SCSI_DH_EMC) += scsi_dh_emc.o +obj-$(CONFIG_SCSI_DH_ALUA) += scsi_dh_alua.o
drivers/scsi/device_handler/scsi_dh_alua.c new file +802 -0
802 lines not on this page · raw message
include/scsi/scsi.h +3 -0
@@ -106,6 +106,7 @@#define VARIABLE_LENGTH_CMD 0x7f#define REPORT_LUNS 0xa0#define MAINTENANCE_IN 0xa3 +#define MAINTENANCE_OUT 0xa4#define MOVE_MEDIUM 0xa5#define EXCHANGE_MEDIUM 0xa6#define READ_12 0xa8
@@ -125,6 +126,8 @@#define SAI_READ_CAPACITY_16 0x10/* values for maintenance in */ #define MI_REPORT_TARGET_PGS 0x0a +/* values for maintenance out */ +#define MO_SET_TARGET_PGS 0x0a/* Values for T10/04-262r7 */ #define ATA_16 0x85/* 16-byte pass-thru */
PATCH 7/8 scsi_dh: attach to hardware handler from dm-mpath
In reply to Chandra Seetharamanmultipath keeps a separate device table which may be more current than the built-in one.
So we should make sure to always call ->attach whenever a multipath map with hardware handler is instantiated. And we should call ->detach on removal, too.
--- drivers/md/dm-mpath.c | 13 +++++++ drivers/scsi/device_handler/scsi_dh.c | 64 +++++++++++++++++++++++++++++++++ include/scsi/scsi_dh.h | 2 + 3 files changed, 79 insertions(+), 0 deletions(-)
drivers/md/dm-mpath.c +13 -0
@@ -147,9 +147,12 @@ static struct priority_group *alloc_priostatic void free_pgpaths (struct list_head *pgpaths,struct dm_target *ti) {struct pgpath *pgpath, *tmp; +struct multipath *m = (struct multipath *) ti->private;list_for_each_entry_safe (pgpath, tmp, pgpaths, list) {list_del (&pgpath->list); +if (m->hw_handler_name) +scsi_dh_detach (bdev_get_queue (pgpath->path.dev->bdev));dm_put_device (ti, pgpath->path.dev);free_pgpath (pgpath); }
@@ -546,6 +549,7 @@ static struct pgpath *parse_path(struct {int r;struct pgpath *p; +struct multipath *m = (struct multipath *) ti->private;/* we need at least a path arg */ if (as->argc <1 ) {
@@ -564,6 +568,15 @@ static struct pgpath *parse_path(struct goto bad; } +if (m->hw_handler_name) { + r =scsi_dh_attach (bdev_get_queue (p->path.dev->bdev), + m->hw_handler_name); +if (r <0 ) { +dm_put_device (ti, p->path.dev); + goto bad; + } + } + r = ps->type->add_path (ps, &p->path, as->argc, as->argv, &ti->error);if (r) {dm_put_device (ti, p->path.dev);
drivers/scsi/device_handler/scsi_dh.c +64 -0
70 lines not on this page · raw message
include/scsi/scsi_dh.h +10 -0
@@ -58,6 +58,8 @@ enum {#if defined(CONFIG_SCSI_DH ) || defined(CONFIG_SCSI_DH_MODULE )extern int scsi_dh_activate (struct request_queue *);extern int scsi_dh_handler_exist (const char *); +extern int scsi_dh_attach (struct request_queue *,const char *); +extern void scsi_dh_detach (struct request_queue *);#else static inline int scsi_dh_activate (struct request_queue *req) {
@@ -67,4 +69,12 @@ static inline int scsi_dh_handler_exist( {return 0 ; } +static inline int scsi_dh_attach (struct request_queue *req,const char *name) +{ +return SCSI_DH_NOSYS ; +} +static inline void scsi_dh_detach (struct request_queue *q) +{ +return ; +}#endif
Alasdair G Kergon
maintainerRe: [PATCH 7/8] scsi_dh: attach to hardware handler from dm-mpath
drivers/md/dm-mpath.c static struct pgpath *parse_path(struct · line 552
Quoted 12 lines · Chandra Seetharaman
+++
linux-2.6.26-git5/drivers/md/dm-mpath.cdrivers/md/dm-mpath.c +2
-0@@ -147,9 +147,12 @@ static struct priority_group *alloc_priostatic void free_pgpaths (struct list_head *pgpaths,struct dm_target *ti) {struct pgpath *pgpath, *tmp; +struct multipath *m = (struct multipath *) ti->private;@@ -546,6 +549,7 @@ static struct pgpath *parse_path(struct {int r;struct pgpath *p; +struct multipath *m = (struct multipath *) ti->private;
FYI We're not writing explicit casts in cases like that in new dm code.
Alasdair
Signature · 1 line
[email protected]
Re: [dm-devel] [PATCH 7/8] scsi_dh: attach to hardware handler from dm-mpath
Here is the modified patch as per Alasdair's comment.
Thanks Alasdair.
chandra
Quoted 16 lines · Alasdair G Kergon
Review static struct pgpath *parse_path(struct · line 552
Quoted 12 lines · Chandra Seetharaman
+++
linux-2.6.26-git5/drivers/md/dm-mpath.c(quoted diff) +2
-0@@ -147,9 +147,12 @@ static struct priority_group *alloc_prio static void free_pgpaths(struct list_head *pgpaths, struct dm_target *ti) { struct pgpath *pgpath, *tmp; + struct multipath *m = (struct multipath *) ti->private;@@ -546,6 +549,7 @@ static struct pgpath *parse_path(struct { int r; struct pgpath *p; + struct multipath *m = (struct multipath *) ti->private;FYI We're not writing explicit casts in cases like that in new dm code.
Quoted 1 line
Alasdair
-------------------------------------
Subject: [PATCH 7/8] scsi_dh: attach to hardware handler from dm-mpath
multipath keeps a separate device table which may be more current than the built-in one.
So we should make sure to always call ->attach whenever a multipath map with hardware handler is instantiated. And we should call ->detach on removal, too.
--- drivers/md/dm-mpath.c | 13 +++++++ drivers/scsi/device_handler/scsi_dh.c | 64 +++++++++++++++++++++++++++++++++ include/scsi/scsi_dh.h | 2 + 3 files changed, 79 insertions(+), 0 deletions(-)
drivers/md/dm-mpath.c +13 -0
@@ -147,9 +147,12 @@ static struct priority_group *alloc_priostatic void free_pgpaths (struct list_head *pgpaths,struct dm_target *ti) {struct pgpath *pgpath, *tmp; +struct multipath *m = ti->private;list_for_each_entry_safe (pgpath, tmp, pgpaths, list) {list_del (&pgpath->list); +if (m->hw_handler_name) +scsi_dh_detach (bdev_get_queue (pgpath->path.dev->bdev));dm_put_device (ti, pgpath->path.dev);free_pgpath (pgpath); }
@@ -546,6 +549,7 @@ static struct pgpath *parse_path(struct {int r;struct pgpath *p; +struct multipath *m = ti->private;/* we need at least a path arg */ if (as->argc <1 ) {
@@ -564,6 +568,15 @@ static struct pgpath *parse_path(struct goto bad; } +if (m->hw_handler_name) { + r =scsi_dh_attach (bdev_get_queue (p->path.dev->bdev), + m->hw_handler_name); +if (r <0 ) { +dm_put_device (ti, p->path.dev); + goto bad; + } + } + r = ps->type->add_path (ps, &p->path, as->argc, as->argv, &ti->error);if (r) {dm_put_device (ti, p->path.dev);
drivers/scsi/device_handler/scsi_dh.c +64 -0
70 lines not on this page · raw message
include/scsi/scsi_dh.h +10 -0
@@ -58,6 +58,8 @@ enum {#if defined(CONFIG_SCSI_DH ) || defined(CONFIG_SCSI_DH_MODULE )extern int scsi_dh_activate (struct request_queue *);extern int scsi_dh_handler_exist (const char *); +extern int scsi_dh_attach (struct request_queue *,const char *); +extern void scsi_dh_detach (struct request_queue *);#else static inline int scsi_dh_activate (struct request_queue *req) {
@@ -67,4 +69,12 @@ static inline int scsi_dh_handler_exist( {return 0 ; } +static inline int scsi_dh_attach (struct request_queue *req,const char *name) +{ +return SCSI_DH_NOSYS ; +} +static inline void scsi_dh_detach (struct request_queue *q) +{ +return ; +}#endif
PATCH 8/8 scsi_dh: create lookup cache
In reply to Chandra SeetharamanCreate a cache of devices that are seen in a system. This will avoid the unnecessary traversal of the device list in the scsi_dh when there are multiple luns of a same type.
--- drivers/scsi/device_handler/scsi_dh.c | 129 +++++++++++++++++++++++++++------ 1 files changed, 105 insertions(+), 24 deletions(-)
drivers/scsi/device_handler/scsi_dh.c +104 -23
@@ -24,8 +24,16 @@#include <scsi/scsi_dh.h> #include "../scsi_priv.h" +struct scsi_dh_devinfo_list { +struct list_head node; +char vendor[9 ]; +char model[17 ]; +struct scsi_device_handler *handler; +}; +static DEFINE_SPINLOCK (list_lock);static LIST_HEAD (scsi_dh_list); +static LIST_HEAD (scsi_dh_dev_list);static struct scsi_device_handler *get_device_handler (const char *name) {
@@ -42,21 +50,94 @@ static struct scsi_device_handler *get_dreturn found; } -static int device_handler_match (struct scsi_device_handler *tmp, -struct scsi_device *sdev) + +static struct scsi_device_handler * +scsi_dh_cache_lookup (struct scsi_device *sdev) { -int i; +struct scsi_dh_devinfo_list *tmp; +struct scsi_device_handler *found_dh =NULL ; -for (i =0 ; tmp->devlist[i].vendor; i++) { -if (!strncmp (sdev->vendor, tmp->devlist[i].vendor, -strlen (tmp->devlist[i].vendor)) && - !strncmp (sdev->model, tmp->devlist[i].model, -strlen (tmp->devlist[i].model))) { -return 1 ; +spin_lock (&list_lock); +list_for_each_entry (tmp, &scsi_dh_dev_list, node) { +if (!strncmp (sdev->vendor, tmp->vendor,strlen (tmp->vendor)) && + !strncmp (sdev->model, tmp->model,strlen (tmp->model))) { + found_dh = tmp->handler; +break ; } } +spin_unlock (&list_lock); -return 0 ; +return found_dh; +} + +static int scsi_dh_handler_lookup (struct scsi_device_handler *scsi_dh, +struct scsi_device *sdev) +{ +int i, found =0 ; + +for (i =0 ; scsi_dh->devlist[i].vendor; i++) { +if (!strncmp (sdev->vendor, scsi_dh->devlist[i].vendor, +strlen (scsi_dh->devlist[i].vendor)) && + !strncmp (sdev->model, scsi_dh->devlist[i].model, +strlen (scsi_dh->devlist[i].model))) { + found =1 ; +break ; + } + } +return found; +} + +/* +* device_handler_match - Attach a device handler to a device +* @scsi_dh - The device handler to match against or NULL +* @sdev - SCSI device to be tested against @scsi_dh +* +* Tests @sdev against the device handler @scsi_dh or against +* all registered device_handler if @scsi_dh == NULL. +* Returns the found device handler or NULL if not found. +*/ +static struct scsi_device_handler * +device_handler_match (struct scsi_device_handler *scsi_dh, +struct scsi_device *sdev) +{ +struct scsi_device_handler *found_dh =NULL ; +struct scsi_dh_devinfo_list *tmp; + + found_dh =scsi_dh_cache_lookup (sdev); +if (found_dh) +return found_dh; + +if (scsi_dh) { +if (scsi_dh_handler_lookup (scsi_dh, sdev)) + found_dh = scsi_dh; + }else { +struct scsi_device_handler *tmp_dh; + +spin_lock (&list_lock); +list_for_each_entry (tmp_dh, &scsi_dh_list, list) { +if (scsi_dh_handler_lookup (tmp_dh, sdev)) + found_dh = tmp_dh; + } +spin_unlock (&list_lock); + } + +if (found_dh) {/* If device is found, add it to the cache */ + tmp =kmalloc (sizeof (*tmp),GFP_KERNEL ); +if (tmp) { +strncpy (tmp->vendor, sdev->vendor,8 ); +strncpy (tmp->model, sdev->model,16 ); + tmp->vendor[8 ] ='\0' ; + tmp->model[16 ] ='\0' ; + tmp->handler = found_dh; +spin_lock (&list_lock); +list_add (&tmp->node, &scsi_dh_dev_list); +spin_unlock (&list_lock); + }else { + found_dh =NULL ; + } + } + +return found_dh; }/*
@@ -203,26 +284,18 @@ static int scsi_dh_notifier(struct notifstruct device *dev = data;struct scsi_device *sdev;int err =0 ; -struct scsi_device_handler *tmp, *devinfo =NULL ; +struct scsi_device_handler *devinfo =NULL ;if (!scsi_is_sdev_device (dev))return 0 ; sdev =to_scsi_device (dev); -spin_lock (&list_lock); -list_for_each_entry (tmp, &scsi_dh_list, list) { -if (device_handler_match (tmp, sdev)) { - devinfo = tmp; -break ; - } - } -spin_unlock (&list_lock); - -if (!devinfo) - goto out; -if (action ==BUS_NOTIFY_ADD_DEVICE ) { + devinfo =device_handler_match (NULL , sdev); +if (!devinfo) + goto out; + err =scsi_dh_handler_attach (sdev, devinfo);if (!err) err =device_create_file (dev, &scsi_dh_state_attr);
@@ -312,6 +385,8 @@ EXPORT_SYMBOL_GPL(scsi_register_device_h*/ int scsi_unregister_device_handler (struct scsi_device_handler *scsi_dh) { +struct scsi_dh_devinfo_list *tmp, *pos; +if (!get_device_handler (scsi_dh->name))return -ENODEV ;
@@ -320,6 +395,12 @@ int scsi_unregister_device_handler(strucspin_lock (&list_lock);list_del (&scsi_dh->list); +list_for_each_entry_safe (pos, tmp, &scsi_dh_dev_list, node) { +if (pos->handler == scsi_dh) { +list_del (&pos->node); +kfree (pos); + } + }spin_unlock (&list_lock);printk (KERN_INFO "%s: device handler unregistered\n" , scsi_dh->name);