proper scsi_devicelist handling
PATCH 1/1 proper scsi_devicelist handling
Factor out code calling methods of all device template on a scsi_device out to three helper functions in scsi.c, make scsi_devicelist static to it and add a r/w semaphore to protect it.
Make scsi_host_list and scsi_host_hn_list static to hosts.c and remove the never used scsi_host_tmpl_list (we only add to it and remove from it but never traverse it)
drivers/scsi/hosts.c +6 -43
@@ -45,13 +45,9 @@#include "scsi.h" #include "hosts.h" -LIST_HEAD (scsi_host_tmpl_list); -LIST_HEAD (scsi_host_hn_list); - -LIST_HEAD (scsi_host_list); -spinlock_t scsi_host_list_lock =SPIN_LOCK_UNLOCKED ; - -struct Scsi_Device_Template * scsi_devicelist; +static LIST_HEAD (scsi_host_hn_list); +static LIST_HEAD (scsi_host_list); +static spinlock_t scsi_host_list_lock =SPIN_LOCK_UNLOCKED ;static int scsi_host_next_hn;/* host_no for next new host */ static int scsi_hosts_registered;/* cnt of registered scsi hosts */
@@ -115,7 +111,6 @@ {int pcount;Scsi_Device *sdev; -struct Scsi_Device_Template *sdev_tp;Scsi_Cmnd *scmd;/*
@@ -175,10 +170,7 @@* structures */ for (sdev = shost->host_queue; sdev; sdev = sdev->next) { -for (sdev_tp = scsi_devicelist; sdev_tp; - sdev_tp = sdev_tp->next) -if (sdev_tp->detach) - (*sdev_tp->detach) (sdev); +scsi_detach_device (sdev);/* If something still attached, punt */ if (sdev->attached) {
@@ -471,12 +463,9 @@ {int cur_cnt;Scsi_Device *sdev; -struct Scsi_Device_Template *sdev_tp;struct list_head *lh;struct Scsi_Host *shost; -INIT_LIST_HEAD (&shost_tp->shtp_list); -/* * Check no detect routine. */
@@ -526,8 +515,6 @@ } } -list_add_tail (&shost_tp->shtp_list, &scsi_host_tmpl_list); -/* The next step is to call scan_scsis here. This generates the * Scsi_Devices entries */
@@ -549,31 +536,15 @@ } } -for (sdev_tp = scsi_devicelist; sdev_tp; - sdev_tp = sdev_tp->next) { -if (sdev_tp->init && sdev_tp->dev_noticed) - (*sdev_tp->init) (); - } -/* * Next we create the Scsi_Cmnd structures for this host */ list_for_each (lh, &scsi_host_list) { shost = list_entry(lh, struct Scsi_Host, sh_list);for (sdev = shost->host_queue; sdev; sdev = sdev->next) -if (sdev->host->hostt == shost_tp) { -scsi_build_commandblocks (sdev); -if (sdev->current_queue_depth ==0 ) +if (sdev->host->hostt == shost_tp) +if (scsi_attach_device (sdev)) goto out_of_space; -for (sdev_tp = scsi_devicelist; - sdev_tp; - sdev_tp = sdev_tp->next) -if (sdev_tp->attach) - (*sdev_tp->attach) (sdev); -if (!sdev->attached) { -scsi_release_commandblocks (sdev); - } - } } }
@@ -613,14 +584,6 @@if (pcount != scsi_hosts_registered)printk (KERN_INFO "scsi : %d host%s left.\n" , scsi_hosts_registered, (scsi_hosts_registered ==1 ) ?"" :"s" ); - -/* -* Remove it from the list if all -* hosts were successfully removed (ie preset == 0) -*/ -if (!shost_tp->present) { -list_del (&shost_tp->shtp_list); - }MOD_DEC_USE_COUNT ;
drivers/scsi/hosts.h +0 -5
@@ -57,9 +57,6 @@ typedef struct SHT { - - struct list_head shtp_list; - /* Used with loadable modules so that we know when it is safe to unload */ struct module * module;
@@ -520,8 +517,6 @@unsigned short host_registered; } Scsi_Host_Name; -extern struct Scsi_Device_Template * scsi_devicelist; -extern void scsi_proc_host_mkdir (Scsi_Host_Template *);extern void scsi_proc_host_add (struct Scsi_Host *);extern void scsi_proc_host_rm (struct Scsi_Host *);
drivers/scsi/scsi.c +61 -7
112 lines not on this page · raw message
drivers/scsi/scsi.h +3 -0
@@ -481,6 +481,9 @@ int timeout, int retries);extern int scsi_dev_init (void );extern int scsi_mlqueue_insert (struct scsi_cmnd *,int ); +extern void scsi_detect_device (struct scsi_device *); +extern int scsi_attach_device (struct scsi_device *); +extern void scsi_detach_device (struct scsi_device *);/* * Newer request-based interfaces.
drivers/scsi/scsi_scan.c +2 -23
@@ -1322,7 +1322,6 @@ Scsi_Request *sreq, char *inq_result, int *bflags) {Scsi_Device *sdev; -struct Scsi_Device_Template *sdt;char devname[64 ];extern devfs_handle_t scsi_devfs_handle;
@@ -1479,9 +1478,7 @@* function */ sdev->max_device_blocked =SCSI_DEFAULT_DEVICE_BLOCKED ; -for (sdt = scsi_devicelist; sdt; sdt = sdt->next) -if (sdt->detect) - sdev->attached += (*sdt->detect) (sdev); +scsi_detect_device (sdev);if (sdev->host->hostt->slave_attach !=NULL ) {if (sdev->host->hostt->slave_attach (sdev) !=0 ) {
@@ -2010,7 +2007,6 @@ uint id, uint lun) {Scsi_Device *sdevscan, *sdev =NULL ; -struct Scsi_Device_Template *sdt;int res; if ((channel > shost->max_channel) || (id >= shost->max_id) ||
@@ -2028,24 +2024,7 @@if (res !=SCSI_SCAN_LUN_PRESENT )return ; -BUG_ON (sdev ==NULL ); - -scsi_build_commandblocks (sdev); -if (sdev->current_queue_depth ==0 ) { -printk (ALLOC_FAILURE_MSG , __FUNCTION__); -return ; - } - -for (sdt = scsi_devicelist; sdt; sdt = sdt->next) -if (sdt->init && sdt->dev_noticed) - (*sdt->init) (); - -for (sdt = scsi_devicelist; sdt; sdt = sdt->next) -if (sdt->attach) - (*sdt->attach) (sdev); - -if (!sdev->attached) -scsi_release_commandblocks (sdev); +scsi_attach_device (sdev); }/**
drivers/scsi/scsi_syms.c +0 -1
@@ -92,7 +92,6 @@EXPORT_SYMBOL (scsi_host_get_next);EXPORT_SYMBOL (scsi_host_hn_get);EXPORT_SYMBOL (scsi_host_put); -EXPORT_SYMBOL (scsi_devicelist);EXPORT_SYMBOL (scsi_device_types);/*