scsi host/scsi device ref count cleanup 0/4
Subsystems (5)
PATCH 1/1 scsi host/scsi device ref count cleanup 0/4
This patch set is against scsi-misc-2.5
This set contains the following patches.
stern_present - refresh of Alan's previous patch. shost_present - reduce users of shost_present. shost_state - Add some state flags and reorder cleanup. sdev_state - Add some state flags and reorder cleanup.
I still have a couple of outstanding issues
- sd_shutdown errors on surprise removal.
- scsi_remove_single_device / scsi_remove_device cleanup around the usage of access_count.
I tested the surprise removal using the scsi_debug add_host attribute. I created two tgts on each host. One target I created a file system and the other target I ran dd's. Post "-1" into add_host I did a umount -f on the mounted file system while monitoring ref counts. I also checked the reboot notifier list on shutdown to ensure it appeared correct.
-andmike
--
Michael Anderson
[email protected]
PATCH 1/1 scsi host/scsi device ref count cleanup 1/4
-andmike
--
Michael Anderson
[email protected]
DESC
This is a refresh of a patch by Alan Stern to correct the removal of scsi procfs host enteries
http://marc.theaimsgroup.com/?l=linux-scsi&m=105545175600506&w=2
EDESC
drivers/scsi/hosts.c | 4 +-- drivers/scsi/scsi_priv.h | 4 +++ drivers/scsi/scsi_proc.c | 49 ++++++++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 19 deletions(-)
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~stern_present +2 -2
@@ -112,7 +112,7 @@ void scsi_free_shost(struct Scsi_Host *s shost->eh_notify =NULL ; } - shost->hostt->present--; +scsi_proc_hostdir_rm (shost->hostt);scsi_destroy_command_freelist (shost);kfree (shost); }
@@ -219,7 +219,7 @@ struct Scsi_Host *scsi_host_alloc(structkernel_thread ((int (*)(void *))scsi_error_handler, shost,0 );wait_for_completion (&complete); shost->eh_notify =NULL ; - shost->hostt->present++; +scsi_proc_hostdir_add (shost->hostt);return shost; fail:kfree (shost);
drivers/scsi/scsi_priv.h renamed from drivers/scsi/scsi_priv.h~stern_present +4 -0
@@ -90,11 +90,15 @@ extern void scsi_exit_queue(void);/* scsi_proc.c */ #ifdef CONFIG_PROC_FS +extern void scsi_proc_hostdir_add (struct scsi_host_template *); +extern void scsi_proc_hostdir_rm (struct scsi_host_template *);extern void scsi_proc_host_add (struct Scsi_Host *);extern void scsi_proc_host_rm (struct Scsi_Host *);extern int scsi_init_procfs (void );extern void scsi_exit_procfs (void );#else +# define scsi_proc_hostdir_add (sht) do { } while (0) +# define scsi_proc_hostdir_rm (sht) do { } while (0)# define scsi_proc_host_add (shost) do { } while (0)# define scsi_proc_host_rm (shost) do { } while (0)# define scsi_init_procfs () (0)
drivers/scsi/scsi_proc.c renamed from drivers/scsi/scsi_proc.c~stern_present +32 -17
80 lines not on this page · raw message
_
PATCH 1/1 scsi host/scsi device ref count cleanup 2/4
-andmike
--
Michael Anderson
[email protected]
DESC
This patch reduces the user of scsi_host present.
aic79xx_osm and aic7xxx_osm are 2.4 code. ioctl_probe has side effect of needing present value.
EDESC
drivers/scsi/NCR53c406a.c | 5 +++-- drivers/scsi/aacraid/linit.c | 1 - drivers/scsi/scsi_module.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/scsi/aacraid/linit.c renamed from drivers/scsi/aacraid/linit.c~shost_present +0 -1
@@ -295,7 +295,6 @@ static int aac_detect(Scsi_Host_Templateprintk (KERN_WARNING "aacraid: unable to register \"aac\" device.\n" ); } - template->present = aac_count;/* # of cards of this type found */ return aac_count; }
drivers/scsi/NCR53c406a.c renamed from drivers/scsi/NCR53c406a.c~shost_present +3 -2
@@ -450,6 +450,7 @@ static __inline__ int NCR53c406a_pio_wristatic int __init NCR53c406a_detect (Scsi_Host_Template * tpnt) { +int present =0 ;struct Scsi_Host *shpnt =NULL ;#ifndef PORT_BASE int i;
@@ -522,7 +523,7 @@ static int __init NCR53c406a_detect(ScsiDEB (printk ("NCR53c406a: using port_base 0x%x\n" , port_base)); - tpnt->present =1 ; + present =1 ; tpnt->proc_name ="NCR53c406a" ; shpnt =scsi_register (tpnt,0 );
@@ -576,7 +577,7 @@ static int __init NCR53c406a_detect(Scsisprintf (info_msg,"NCR53c406a at 0x%x, IRQ %d, %s PIO mode." , port_base, irq_level, fast_pio ?"fast" :"slow" );#endif -return (tpnt->present); +return (present);#if USE_DMA err_free_irq:
drivers/scsi/scsi_module.c renamed from drivers/scsi/scsi_module.c~shost_present +1 -1
@@ -33,7 +33,7 @@ static int __init init_this_scsi_driver(INIT_LIST_HEAD (&sht->legacy_hosts); sht->detect (sht); -if (!sht->present) +if (list_empty (&sht->legacy_hosts))return -ENODEV ;list_for_each_entry (shost, &sht->legacy_hosts, sht_legacy_list) {
_
PATCH 1/1 scsi host/scsi device ref count cleanup 3/4
-andmike
--
Michael Anderson
[email protected]
DESC
This is a cleanup patch for scsi_host removal.
- Addition of a host_flags member to the scsi_host strucuture to contain "state" of the host instance.
- Added SHOST_ADD, SHOST_DEL, SHOST_CANCEL, SHOST_RECOVERY states for a scsi host
- Addtion / rename of a new function scsi_host_cancel to cancel IOs in flight.
- Usage of the host_flags flags member to stop scsi_host_get's and calls to LLDD queucommand under certain states.
- Reordered some of the scsi host sysfs unregistration.
EDESC
drivers/scsi/hosts.c | 62 +++++++++++++++++++++++++++------------------ drivers/scsi/scsi.c | 31 +++++++++++++++------- drivers/scsi/scsi_debug.c | 5 --- drivers/scsi/scsi_error.c | 7 ++--- drivers/scsi/scsi_lib.c | 5 ++- drivers/scsi/scsi_proc.c | 12 ++++---- drivers/scsi/scsi_syms.c | 2 - drivers/scsi/scsi_sysfs.c | 44 ++++++++++++++++++++++--------- drivers/scsi/sg.c | 3 +- drivers/usb/storage/usb.c | 7 ----- include/scsi/scsi_device.h | 2 - include/scsi/scsi_host.h | 16 +++++++++-- 12 files changed, 122 insertions(+), 74 deletions(-)
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +38 -24
@@ -39,30 +39,35 @@static int scsi_host_next_hn;/* host_no for next new host */ +/** -* scsi_remove_host - check a scsi host for release and release -* @shost: a pointer to a scsi host to release -* -* Return value: -* 0 on Success / 1 on Failure +* scsi_host_cancel - cancel outstanding IO to this host +* @shost: pointer to struct Scsi_Host +* recovery: recovery requested to run. **/ -int scsi_remove_host (struct Scsi_Host *shost) +void scsi_host_cancel (struct Scsi_Host *shost,int recovery) { -struct scsi_device *sdev; +unsigned long flags; -/* -* FIXME Do ref counting. We force all of the devices offline to -* help prevent race conditions where other hosts/processors could -* try and get in and queue a command. -*/ -list_for_each_entry (sdev, &shost->my_devices, siblings) - sdev->online = FALSE; +spin_lock_irqsave (shost->host_lock, flags); +__set_bit (SHOST_CANCEL , &shost->host_flags); +spin_unlock_irqrestore (shost->host_lock, flags); +device_for_each_child (&shost->host_gendev, &recovery, + scsi_device_cancel); +wait_event (shost->host_wait, (!test_bit (SHOST_RECOVERY , + &shost->host_flags))); +} +/** +* scsi_remove_host - remove a scsi host +* @shost: a pointer to a scsi host to remove +**/ +void scsi_remove_host (struct Scsi_Host *shost) +{ +scsi_host_cancel (shost,0 );scsi_proc_host_rm (shost);scsi_forget_host (shost);scsi_sysfs_remove_host (shost); - -return 0 ; }/**
@@ -93,7 +98,7 @@ int scsi_add_host(struct Scsi_Host *shosscsi_proc_host_add (shost);scsi_scan_host (shost); } - +return error; }
@@ -259,21 +264,21 @@ struct Scsi_Host *scsi_host_lookup(unsig {struct class *class =class_get (&shost_class);struct class_device *cdev; -struct Scsi_Host *shost =NULL , *p; +struct Scsi_Host *shost =ERR_PTR (-ENXIO ), *p;if (class) {down_read (&class->subsys.rwsem);list_for_each_entry (cdev, &class->children, node) { p =class_to_shost (cdev);if (p->host_no == hostnum) { -scsi_host_get (p); - shost = p; + shost =scsi_host_get (p);break ; } }up_read (&class->subsys.rwsem); } +class_put (&shost_class);return shost; }
@@ -281,10 +286,20 @@ struct Scsi_Host *scsi_host_lookup(unsig* *scsi_host_get - inc a Scsi_Host ref count * @shost: Pointer to Scsi_Host to inc. **/ -void scsi_host_get (struct Scsi_Host *shost) +struct Scsi_Host *scsi_host_get (struct Scsi_Host *shost) { -get_device (&shost->host_gendev); -class_device_get (&shost->class_dev); +struct Scsi_Host *res_shost = shost; + +if (res_shost) { +if (!test_bit (SHOST_DEL , &shost->host_flags)) { +if (!get_device (&res_shost->host_gendev)) + res_shost =ERR_PTR (-ENXIO ); + }else { + res_shost =ERR_PTR (-ENXIO ); + } + } + +return res_shost; }/**
@@ -293,6 +308,5 @@ void scsi_host_get(struct Scsi_Host *sho**/ void scsi_host_put (struct Scsi_Host *shost) { -class_device_put (&shost->class_dev);put_device (&shost->host_gendev); }
drivers/scsi/scsi.c renamed from drivers/scsi/scsi.c~shost_state +22 -9
@@ -370,7 +370,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *struct Scsi_Host *host = cmd->device->host;unsigned long flags =0 ;unsigned long timeout; -int rtn =1 ; +int rtn =0 ;/* Assign a unique nonzero serial_number. */ /* XXX(hch): this is racy */
@@ -444,7 +444,12 @@ int scsi_dispatch_cmd(struct scsi_cmnd * host->hostt->queuecommand));spin_lock_irqsave (host->host_lock, flags); - rtn = host->hostt->queuecommand (cmd, scsi_done); +if (unlikely (test_bit (SHOST_CANCEL , &host->host_flags))) { + cmd->result = (DID_NO_CONNECT <<16 ); +scsi_done (cmd); + }else { + rtn = host->hostt->queuecommand (cmd, scsi_done); + }spin_unlock_irqrestore (host->host_lock, flags);if (rtn) { scsi_queue_insert(cmd,
@@ -902,17 +907,19 @@ void scsi_device_put(struct scsi_device }/** -* scsi_set_device_offline - set scsi_device offline -* @sdev: pointer to struct scsi_device to offline. +* scsi_device_cancel - cancel outstanding IO to this device +* @sdev: pointer to struct scsi_device +* @data: pointer to cancel value. * -* Locks: host_lock held on entry. **/ -void scsi_set_device_offline (struct scsi_device *sdev) +int scsi_device_cancel (struct device *dev,void *data) {struct scsi_cmnd *scmd;LIST_HEAD (active_list);struct list_head *lh, *lh_sf;unsigned long flags; +struct scsi_device *sdev =to_scsi_device (dev); +unsigned int recovery = *(unsigned int *)data; sdev->online =0 ;
@@ -934,11 +941,17 @@ void scsi_set_device_offline(struct scsiif (!list_empty (&active_list)) {list_for_each_safe (lh, lh_sf, &active_list) { scmd = list_entry(lh, struct scsi_cmnd, eh_entry); -scsi_eh_scmd_add (scmd,SCSI_EH_CANCEL_CMD ); +list_del_init (lh); +if (recovery) { +scsi_eh_scmd_add (scmd,SCSI_EH_CANCEL_CMD ); + }else { + scmd->result = (DID_ABORT <<16 ); +scsi_finish_command (scmd); + } } - }else { -/* FIXME: Send online state change hotplug event */ } + +return 0 ; }MODULE_DESCRIPTION ("SCSI core" );
drivers/scsi/scsi_debug.c renamed from drivers/scsi/scsi_debug.c~shost_state +1 -4
@@ -1721,10 +1721,7 @@ static int sdebug_driver_remove(struct dreturn -ENODEV ; } -if (scsi_remove_host (sdbg_host->shost)) { -printk (KERN_ERR "%s: scsi_remove_host failed\n" , __FUNCTION__); -return -EBUSY ; - } +scsi_remove_host (sdbg_host->shost);list_for_each_safe (lh, lh_sf, &sdbg_host->dev_info_list) { sdbg_devinfo = list_entry(lh, struct sdebug_dev_info,
drivers/scsi/scsi_error.c renamed from drivers/scsi/scsi_error.c~shost_state +3 -4
@@ -84,7 +84,7 @@ int scsi_eh_scmd_add(struct scsi_cmnd *s*/ scmd->serial_number_at_timeout = scmd->serial_number;list_add_tail (&scmd->eh_entry, &shost->eh_cmd_q); - shost->in_recovery =1 ; +set_bit (SHOST_RECOVERY , &shost->host_flags); shost->host_failed++;scsi_eh_wakeup (shost);spin_unlock_irqrestore (shost->host_lock, flags);
@@ -187,7 +187,7 @@ void scsi_times_out(struct scsi_cmnd *sc**/ int scsi_block_when_processing_errors (struct scsi_device *sdev) { -wait_event (sdev->host->host_wait, (sdev->host->in_recovery ==0 )); +wait_event (sdev->host->host_wait, (!test_bit (SHOST_RECOVERY , &sdev->host->host_flags)));SCSI_LOG_ERROR_RECOVERY (5 ,printk ("%s: rtn: %d\n" , __FUNCTION__, sdev->online));
@@ -1389,7 +1389,7 @@ static void scsi_restart_operations(struSCSI_LOG_ERROR_RECOVERY (3 ,printk ("%s: waking up host to restart\n" , __FUNCTION__)); - shost->in_recovery =0 ; +clear_bit (SHOST_RECOVERY , &shost->host_flags);wake_up (&shost->host_wait);
@@ -1599,7 +1599,6 @@ void scsi_error_handler(void *data)* that's fine. If the user sent a signal to this thing, we are * potentially in real danger. */ - shost->in_recovery =0 ; shost->eh_active =0 ; shost->ehandler =NULL ;
drivers/scsi/scsi_lib.c renamed from drivers/scsi/scsi_lib.c~shost_state +3 -2
@@ -318,7 +318,8 @@ void scsi_device_unbusy(struct scsi_devispin_lock_irqsave (shost->host_lock, flags); shost->host_busy--; -if (unlikely (shost->in_recovery && shost->host_failed)) +if (unlikely (test_bit (SHOST_RECOVERY , &shost->host_flags) && + shost->host_failed))scsi_eh_wakeup (shost);spin_unlock (shost->host_lock);spin_lock (&sdev->sdev_lock);
@@ -1080,7 +1081,7 @@ static inline int scsi_host_queue_ready( struct Scsi_Host *shost, struct scsi_device *sdev) { -if (shost->in_recovery) + if (test_bit(SHOST_RECOVERY, &shost->host_flags)) return 0; if (shost->host_busy == 0 && shost->host_blocked) { /*
drivers/scsi/scsi_proc.c renamed from drivers/scsi/scsi_proc.c~shost_state +6 -6
@@ -190,11 +190,11 @@ static int scsi_add_single_device(uint h {struct Scsi_Host *shost;struct scsi_device *sdev; -int error = -ENODEV ; +int error = -ENXIO ; shost =scsi_host_lookup (host); -if (!shost) -return -ENODEV ; +if (IS_ERR (shost)) +return PTR_ERR (shost);if (!scsi_find_device (shost, channel, id, lun)) { sdev =scsi_add_device (shost, channel, id, lun);
@@ -212,11 +212,11 @@ static int scsi_remove_single_device(uin {struct scsi_device *sdev;struct Scsi_Host *shost; -int error = -ENODEV ; +int error = -ENXIO ; shost =scsi_host_lookup (host); -if (!shost) -return -ENODEV ; +if (IS_ERR (shost)) +return PTR_ERR (shost); sdev =scsi_find_device (shost, channel, id, lun);if (!sdev) goto out;
drivers/scsi/scsi_syms.c renamed from drivers/scsi/scsi_syms.c~shost_state +1 -1
@@ -85,7 +85,7 @@ EXPORT_SYMBOL(scsi_device_get);EXPORT_SYMBOL (scsi_device_put);EXPORT_SYMBOL (scsi_add_device);EXPORT_SYMBOL (scsi_remove_device); -EXPORT_SYMBOL (scsi_set_device_offline); +EXPORT_SYMBOL (scsi_device_cancel);EXPORT_SYMBOL (__scsi_mode_sense);EXPORT_SYMBOL (scsi_mode_sense);
drivers/scsi/scsi_sysfs.c renamed from drivers/scsi/scsi_sysfs.c~shost_state +31 -13
91 lines not on this page · raw message
drivers/scsi/sg.c renamed from drivers/scsi/sg.c~shost_state +2 -1
@@ -954,7 +954,8 @@ sg_ioctl(struct inode *inode, struct filif (sdp->detached)return -ENODEV ;if (filp->f_flags &O_NONBLOCK ) { -if (sdp->device->host->in_recovery) +if (test_bit (SHOST_RECOVERY , + &sdp->device->host->host_flags))return -EBUSY ; }else if (!scsi_block_when_processing_errors (sdp->device))return -EBUSY ;
include/scsi/scsi_device.h renamed from include/scsi/scsi_device.h~shost_state +1 -1
@@ -94,7 +94,7 @@ struct scsi_device {extern struct scsi_device *scsi_add_device (struct Scsi_Host *,uint ,uint ,uint );extern int scsi_remove_device (struct scsi_device *); -extern void scsi_set_device_offline (struct scsi_device *); +extern int scsi_device_cancel (struct device *,void *);extern int scsi_device_get (struct scsi_device *);extern void scsi_device_put (struct scsi_device *);
include/scsi/scsi_host.h renamed from include/scsi/scsi_host.h~shost_state +13 -3
@@ -348,6 +348,14 @@ struct scsi_host_template {struct list_head legacy_hosts; }; +/* +* shost flags +*/ +#define SHOST_ADD 1 +#define SHOST_DEL 2 +#define SHOST_CANCEL 3 +#define SHOST_RECOVERY 4 +struct Scsi_Host {struct list_head my_devices;struct scsi_host_cmd_pool *cmd_pool;
@@ -413,7 +421,6 @@ struct Scsi_Host {short unsigned int sg_tablesize;short unsigned int max_sectors; - unsigned in_recovery:1; unsigned unchecked_isa_dma:1; unsigned use_clustering:1; unsigned highmem_io:1;
@@ -454,6 +461,9 @@ struct Scsi_Host {unsigned char n_io_port;unsigned char dma_channel;unsigned int irq; + + +unsigned long host_flags;/*
@@ -480,8 +490,8 @@ struct Scsi_Host {extern struct Scsi_Host *scsi_host_alloc (struct scsi_host_template *,int );extern int scsi_add_host (struct Scsi_Host *,struct device *); -extern int scsi_remove_host (struct Scsi_Host *); -extern void scsi_host_get (struct Scsi_Host *); +extern void scsi_remove_host (struct Scsi_Host *); +extern struct Scsi_Host *scsi_host_get (struct Scsi_Host *);extern void scsi_host_put (struct Scsi_Host *t);extern struct Scsi_Host *scsi_host_lookup (unsigned short );
drivers/usb/storage/usb.c renamed from drivers/usb/storage/usb.c~shost_state +1 -6
@@ -993,12 +993,7 @@ static void storage_disconnect(struct us/* Dissociate from the USB device */ dissociate_dev (us); -/* Begin the SCSI host removal sequence */ -if (scsi_remove_host (us->host)) { -US_DEBUGP ("-- SCSI refused to remove the host\n" ); -BUG (); -return ; - } +scsi_remove_host (us->host);/* TODO: somehow, wait for the device to * be 'idle' (tasklet completion) */
_
PATCH 1/1 scsi host/scsi device ref count cleanup 4/4
-andmike
--
Michael Anderson
[email protected]
DESC
This is a cleanup patch for scsi_device removal.
- Addition of device_flags member to the scsi_device strucuture to contain "state" of the device instance.
- Added SDEV_ADD, SDEV_DEL, SDEV_CANCEL, SDEV_RECOVERY states for a scsi device
- Built on previous patch that renamed scsi_set_device_offline to scsi_device_cancel to use SDEV_CANCEL value.
- Usage of the device_flags flags member to stop scsi_device_get's and final cleanup on access_count going to zero.
- Added newer release functions and reordered scsi device sysfs unregister.
EDESC
drivers/scsi/scsi.c | 36 ++++++++++++++++++++++----- drivers/scsi/scsi_priv.h | 1 drivers/scsi/scsi_sysfs.c | 60 ++++++++++++++++++++++++++++++--------------- include/scsi/scsi_device.h | 13 +++++++++ 4 files changed, 84 insertions(+), 26 deletions(-)
drivers/scsi/scsi.c renamed from drivers/scsi/scsi.c~sdev_state +30 -6
@@ -893,17 +893,41 @@ int scsi_track_queue_full(struct scsi_deint scsi_device_get (struct scsi_device *sdev) { -if (!try_module_get (sdev->host->hostt->module)) -return -ENXIO ; +struct class *class =class_get (&sdev_class); +int error = -ENXIO ; - sdev->access_count++; -return 0 ; +if (class) { +down_write (&class->subsys.rwsem); +if (!test_bit (SDEV_DEL , &sdev->device_flags)) +if (try_module_get (sdev->host->hostt->module)) +if (get_device (&sdev->sdev_driverfs_dev)) { + sdev->access_count++; + error =0 ; + } +up_write (&class->subsys.rwsem); +class_put (&sdev_class); + } + +return error; }void scsi_device_put (struct scsi_device *sdev) { - sdev->access_count--; +struct class *class =class_get (&sdev_class); + +if (!class) +return ; + +down_write (&class->subsys.rwsem);module_put (sdev->host->hostt->module); +if (--sdev->access_count ==0 ) { +if (test_bit (SDEV_DEL , &sdev->device_flags)) +device_del (&sdev->sdev_driverfs_dev); + } +put_device (&sdev->sdev_driverfs_dev); +up_write (&class->subsys.rwsem); + +class_put (&sdev_class); }/**
@@ -921,7 +945,7 @@ int scsi_device_cancel(struct device *destruct scsi_device *sdev =to_scsi_device (dev);unsigned int recovery = *(unsigned int *)data; - sdev->online =0 ; +set_bit (SDEV_CANCEL , &sdev->device_flags);spin_lock_irqsave (&sdev->list_lock, flags);list_for_each_entry (scmd, &sdev->cmd_list, list) {
drivers/scsi/scsi_sysfs.c renamed from drivers/scsi/scsi_sysfs.c~sdev_state +41 -19
133 lines not on this page · raw message
include/scsi/scsi_device.h renamed from include/scsi/scsi_device.h~sdev_state +12 -1
@@ -10,6 +10,14 @@ struct scsi_cmnd;struct scsi_mode_data ; +/* +* sdev flags +*/ +#define SDEV_ADD 1 +#define SDEV_DEL 2 +#define SDEV_CANCEL 3 +#define SDEV_RECOVERY 4 +struct scsi_device {struct class_device sdev_classdev;
@@ -87,9 +95,13 @@ struct scsi_device {#define SCSI_DEFAULT_DEVICE_BLOCKED 3struct device sdev_driverfs_dev; + +unsigned long device_flags; };#define to_scsi_device (d) \ container_of(d, struct scsi_device, sdev_driverfs_dev) +#define class_to_sdev (d) \ + container_of(d, struct scsi_device, sdev_classdev)extern struct scsi_device *scsi_add_device (struct Scsi_Host *,uint ,uint ,uint );
@@ -107,5 +119,4 @@ extern int scsi_set_medium_removal(strucextern int scsi_mode_sense (struct scsi_device *sdev,int dbd,int modepage,unsigned char *buffer,int len,int timeout,int retries,struct scsi_mode_data *data); -#endif /* _SCSI_SCSI_DEVICE_H */
drivers/scsi/scsi_priv.h renamed from drivers/scsi/scsi_priv.h~sdev_state +1 -0
@@ -127,6 +127,7 @@ extern struct class_device_attribute *scextern struct device_attribute *scsi_sysfs_sdev_attrs[];extern struct class shost_class; +extern struct class sdev_class;extern struct bus_type scsi_bus_type;#endif /* _SCSI_PRIV_H */
_
Re: [PATCH] scsi host/scsi device ref count cleanup 3/4
In reply to Mike AndersonQuoted 11 lines · Mike Anderson
-andmike
--
Michael Anderson
[email protected]DESC
This is a cleanup patch forscsi_hostremoval.
- Addition of ahost_flagsmember to thescsi_hoststrucuture to contain "state" of the host instance.
- AddedSHOST_ADD,SHOST_DEL,SHOST_CANCEL,SHOST_RECOVERYstates for a scsi host
Hmm, I'd call this shost_state.
drivers/scsi/hosts.c line 58
Quoted 7 lines
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +7
-0+spin_lock_irqsave (shost->host_lock, flags); +__set_bit (SHOST_CANCEL , &shost->host_flags); +spin_unlock_irqrestore (shost->host_lock, flags); +device_for_each_child (&shost->host_gendev, &recovery, + scsi_device_cancel); +wait_event (shost->host_wait, (!test_bit (SHOST_RECOVERY , + &shost->host_flags)));
Using the non-atomic and the atomic bitops on one variable doesn't get you atomicity. Always use the atomic ones if you need them sometimes.
drivers/scsi/hosts.c line 65
Quoted 5 lines
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +5
-0+/** +* scsi_remove_host - remove a scsi host +* @shost: a pointer to a scsi host to remove +**/ +void scsi_remove_host (struct Scsi_Host *shost)
A, cool I already had a patch pending to make this a void retval.
drivers/scsi/hosts.c struct Scsi_Host *scsi_host_lookup(unsig · line 289
Quoted 2 lines
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +1
-1-void scsi_host_get (struct Scsi_Host *shost) +struct Scsi_Host *scsi_host_get (struct Scsi_Host *shost)
struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost)
drivers/scsi/hosts.c struct Scsi_Host *scsi_host_lookup(unsig · line 293
Quoted 6 lines
{
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +3
-2-get_device (&shost->host_gendev); -class_device_get (&shost->class_dev); +struct Scsi_Host *res_shost = shost; + +if (res_shost) {
I don't think we should allow for a NULL argument here. Also can't we just return NULL in the error case? That would simplify the code to:
struct Scsi_Host *scsi_host_get(struct Scsi_Host *shost)
{
if (test_bit(SHOST_DEL, &shost->host_flags) ||
!get_device(&res_shost->host_gendev))
return NULL;
return shost;
}drivers/scsi/hosts.c void scsi_host_get(struct Scsi_Host *sho · line 296
Quoted 3 lines
void
scsi_host_put(struct Scsi_Host *shost)
{drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +0
-1-class_device_put (&shost->class_dev);
Can you explain why we don't need that anymore? /me wants to learn a bit more about deep LDM magic..
drivers/scsi/scsi.c void scsi_device_put(struct scsi_device · line 922
Quoted 9 lines
drivers/scsi/scsi.c renamed from drivers/scsi/scsi.c~shost_state +3
-1-void scsi_set_device_offline (struct scsi_device *sdev) +int scsi_device_cancel (struct device *dev,void *data) {struct scsi_cmnd *scmd;LIST_HEAD (active_list);struct list_head *lh, *lh_sf;unsigned long flags; +struct scsi_device *sdev =to_scsi_device (dev); +unsigned int recovery = *(unsigned int *)data;
I think the prototype should be
int scsi_device_cancel(struct scsi_device *sdev, int recovery)
and there should be a small wrapper for the LDM iterator.
Quoted 1 line
+shost_rd_attr(host_flags, "%lx\n");
Shouldn't these better be printed in ascii instead of the binary presentation that might aswell change form one kernelrelease to another?
include/scsi/scsi_host.h struct scsi_host_template { · line 357
Quoted 7 lines
include/scsi/scsi_host.h renamed from include/scsi/scsi_host.h~shost_state +7
-0+/* +* shost flags +*/ +#define SHOST_ADD 1 +#define SHOST_DEL 2 +#define SHOST_CANCEL 3 +#define SHOST_RECOVERY 4
Make this an enum?
drivers/usb/storage/usb.c static void storage_disconnect(struct us · line 996
Quoted 10 lines
drivers/usb/storage/usb.c renamed from drivers/usb/storage/usb.c~shost_state +1
-6/* Dissociate from the USB device */ dissociate_dev (us); -/* Begin the SCSI host removal sequence */ -if (scsi_remove_host (us->host)) { -US_DEBUGP ("-- SCSI refused to remove the host\n" ); -BUG (); -return ; - } +scsi_remove_host (us->host);
Also in usb-storage the loop over my_devices to set them offline just before scsi_remove_host should be nuked now, shouldn't it?
(unknown)
In reply to Mike Andersondrivers/scsi/scsi_sysfs.c int scsi_device_register(struct scsi_dev · line 272
Quoted 1 line
drivers/scsi/scsi_sysfs.c renamed from drivers/scsi/scsi_sysfs.c~sdev_state +1
-0+__set_bit (SDEV_ADD , &sdev->device_flags);
Same atomic vs non atomic issue as in the previous patch.
include/scsi/scsi_device.h struct scsi_cmnd; · line 19
Quoted 7 lines
include/scsi/scsi_device.h renamed from include/scsi/scsi_device.h~sdev_state +7
-0+/* +* sdev flags +*/ +#define SDEV_ADD 1 +#define SDEV_DEL 2 +#define SDEV_CANCEL 3 +#define SDEV_RECOVERY 4
Enum again?
include/scsi/scsi_device.h struct scsi_device { · line 99
Quoted 1 line
include/scsi/scsi_device.h renamed from include/scsi/scsi_device.h~sdev_state +1
-0+unsigned long device_flags;
sdev_state?
Re: [PATCH] scsi host/scsi device ref count cleanup 2/4
In reply to Mike AndersonQuoted 2 lines · Mike Anderson
aic79xx_osmandaic7xxx_osmare 2.4 code.ioctl_probehas side effect of needing present value.
ioctl_probe is pretty buggy anyways. I wonder whether we should just kill it.
Re: [PATCH] scsi host/scsi device ref count cleanup 3/4
In reply to Christoph HellwigQuoted 6 lines · Christoph Hellwig [[email protected]] wrote:
Quoted 5 lines · Mike Anderson
-andmike
--
Michael Anderson
[email protected]
Quoted 9 lines
Quoted 6 lines
DESC
This is a cleanup patch forscsi_hostremoval.
- Addition of ahost_flagsmember to thescsi_hoststrucuture to contain "state" of the host instance.
- AddedSHOST_ADD,SHOST_DEL,SHOST_CANCEL,SHOST_RECOVERYstates for a scsi hostHmm, I'd call this
shost_state.
Done.
Quoted 11 lines
drivers/scsi/hosts.c line 58
Quoted 8 lines
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +7
-0+spin_lock_irqsave (shost->host_lock, flags); +__set_bit (SHOST_CANCEL , &shost->host_flags); +spin_unlock_irqrestore (shost->host_lock, flags); +device_for_each_child (&shost->host_gendev, &recovery, + scsi_device_cancel); +wait_event (shost->host_wait, (!test_bit (SHOST_RECOVERY , + &shost->host_flags)));Using the non-atomic and the atomic bitops on one variable doesn't get you atomicity. Always use the atomic ones if you need them sometimes.
Yes, I will clean this up. I went through many different iterations of state implementations and got sloppy.
Quoted 16 lines
drivers/scsi/hosts.c struct Scsi_Host *scsi_host_lookup(unsig · line 289
Quoted 2 lines
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +1
-1-void scsi_host_get (struct Scsi_Host *shost) +struct Scsi_Host *scsi_host_get (struct Scsi_Host *shost)struct
Scsi_Host*scsi_host_get(structScsi_Host*shost)drivers/scsi/hosts.c struct Scsi_Host *scsi_host_lookup(unsig · line 293
Quoted 6 lines
{
drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +3
-2-get_device (&shost->host_gendev); -class_device_get (&shost->class_dev); +struct Scsi_Host *res_shost = shost; + +if (res_shost) {I don't think we should allow for a NULL argument here. Also can't we just return NULL in the error case? That would simplify the code to:
Quoted 8 lines
struct
Scsi_Host*scsi_host_get(structScsi_Host*shost){ if (test_bit(SHOST_DEL, &shost->host_flags) || !get_device(&res_shost->host_gendev)) return NULL; return shost; }
Done.
Quoted 7 lines
drivers/scsi/hosts.c void scsi_host_get(struct Scsi_Host *sho · line 296
Quoted 3 lines
void
scsi_host_put(struct Scsi_Host *shost)
{drivers/scsi/hosts.c renamed from drivers/scsi/hosts.c~shost_state +0
-1-class_device_put (&shost->class_dev);Can you explain why we don't need that anymore? /me wants to learn a bit more about deep LDM magic..
I do not know if I can reveal the magic as some of this is bread crumbs created by previous bad paths taken :-).
I think SCSI core has unique issues stuck between the bus layer struct device LDM registration and the block layer pure kobjects.
I removed the class get/puts to simplify the scsi_host_get code and reduce ordering problems between the class and device release methods. We could have chosen either the structure device or the class device to ref count on. The struct device appears to be a better object to ref count against as it is the child of the adapter struct device and the parent of the scsi device struct device.
We also had an issue previously discussed by Alan of no class device release method which could cause a problem if a user had an open on a scsi_host class attribute..
So now our scsi host ref counting is like the following:
(Note: scsi_sysfs_remove_host has device_del as the patch I sent out was wrong in this area and had some old code used to debug a issue with
scsi_sysfs_init_host:
(1) device_initialize host_gendev (ref = 1)
(2) class_device_initialize shost_classdev (ref = 1)
(3) get_device on host_gendev (ref+1 (2)) (This will keep the host_gendev in place until release of the shost_classdev)
scsi_sysfs_add_host
(1) device_add on host_gendev (ref+1 (3)) and (ref+1) on parent (2) get_device on parent to hold them in place post device_del. (3) class_device_add on shost_classdev (ref+1 (2))
scsi_sysfs_remove_host
(1) class_device_unregister on shost_classdev (ref-2) (del and put will result in release if no users have opens on host class attributes)
(2) device_del on shost_gendev (ref-1) and (ref-1) on parent
scsi_host_cls_release
put_device on host_gendev (ref-1) (This will allow the host_gendev release to be called)
scsi_host_dev_release
(1) put_device on parent (ref-1) (2) scsi_free_shost
scsi_host_get
get_device on host_gendev (ref+1)
scsi_host_put
put_device on shost_gendev (ref-1)
Each scsi_device_register / scsi_device_unregister will incr / dec the host_gendev ref.
Quoted 12 lines
drivers/scsi/scsi.c void scsi_device_put(struct scsi_device · line 922
Quoted 9 lines
drivers/scsi/scsi.c renamed from drivers/scsi/scsi.c~shost_state +3
-1-void scsi_set_device_offline (struct scsi_device *sdev) +int scsi_device_cancel (struct device *dev,void *data) {struct scsi_cmnd *scmd;LIST_HEAD (active_list);struct list_head *lh, *lh_sf;unsigned long flags; +struct scsi_device *sdev =to_scsi_device (dev); +unsigned int recovery = *(unsigned int *)data;I think the prototype should be
Quoted 4 lines
int
scsi_device_cancel(struct scsi_device *sdev, int recovery)and there should be a small wrapper for the LDM iterator.
ok I created a wrapper function called scsi_device_cancel_cb (seems like others where using callback but that seemed to long).
Quoted 6 lines
Quoted 1 line
+shost_rd_attr(host_flags, "%lx\n");
Shouldn't these better be printed in ascii instead of the binary presentation that might aswell change form one kernelrelease to another?
Yes, I was lazy and did this initially for debug. Do have a suggested format (i.e., comma separated or colon separated or ??).
Quoted 10 lines
include/scsi/scsi_host.h struct scsi_host_template { · line 357
Quoted 7 lines
include/scsi/scsi_host.h renamed from include/scsi/scsi_host.h~shost_state +7
-0+/* +* shost flags +*/ +#define SHOST_ADD 1 +#define SHOST_DEL 2 +#define SHOST_CANCEL 3 +#define SHOST_RECOVERY 4Make this an enum?
Done. I guess also since I am using set_bit that I should use the zero shift (not that we will need all these states).
Quoted 13 lines
drivers/usb/storage/usb.c static void storage_disconnect(struct us · line 996
Quoted 10 lines
drivers/usb/storage/usb.c renamed from drivers/usb/storage/usb.c~shost_state +1
-6/* Dissociate from the USB device */ dissociate_dev (us); -/* Begin the SCSI host removal sequence */ -if (scsi_remove_host (us->host)) { -US_DEBUGP ("-- SCSI refused to remove the host\n" ); -BUG (); -return ; - } +scsi_remove_host (us->host);Also in usb-storage the loop over
my_devicesto set them offline just beforescsi_remove_hostshould be nuked now, shouldn't it?
Yes it should. I made this a separate patch in the series in case Matthew / Alan see other changes needed with usb storage shutdown.
-andmike
--
Michael Anderson
[email protected]
Re: [PATCH] scsi host/scsi device ref count cleanup 3/4
Quoted 6 lines · Mike Anderson
Quoted 3 lines
Can you explain why we don't need that anymore? /me wants to learn a bit more about deep LDM magic..
I do not know if I can reveal the magic as some of this is bread crumbs created by previous bad paths taken :-).
Hehe.
Quoted 9 lines
I think SCSI core has unique issues stuck between the bus layer struct device LDM registration and the block layer pure kobjects.
I removed the class get/puts to simplify the
scsi_host_getcode and reduce ordering problems between the class and device release methods. We could have chosen either the structure device or the class device to ref count on. The struct device appears to be a better object to ref count against as it is the child of the adapter struct device and the parent of the scsi device struct device.
Agreed. What do we need the classdev for at all?
Quoted 2 lines
ok I created a wrapper function called
scsi_device_cancel_cb(seems like others where using callback but that seemed to long).
or just name it cancel_callback (I assume it's static)
Quoted 7 lines
Quoted 4 lines
Shouldn't these better be printed in ascii instead of the binary presentation that might aswell change form one kernelrelease to another?
Yes, I was lazy and did this initially for debug. Do have a suggested format (i.e., comma separated or colon separated or ??).
coma separated looks fine to me.
Quoted 4 lines
Yes it should. I made this a separate patch in the series in case Matthew / Alan see other changes needed with usb storage shutdown.
Ok.