device handler cleanups
This series contains a couple easy cleanups for the device handler infrastructure. I think some more work could be done in the longer run, e.g. by using a class_device interface to attach to the scsi_device, similar to how the /dev/sg devices work.
PATCH 1/6 scsi_dh: get module reference outside of device handler
We need to grab a reference to the module before calling the attach routines to avoid a small race vs module removal. It also cleans up the code significantly as a side effect.
--- drivers/scsi/device_handler/scsi_dh.c | 31 ++++++++++++++++++++--------- drivers/scsi/device_handler/scsi_dh_alua.c | 4 ---- drivers/scsi/device_handler/scsi_dh_emc.c | 4 ---- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 4 ---- drivers/scsi/device_handler/scsi_dh_rdac.c | 4 ---- 5 files changed, 22 insertions(+), 25 deletions(-)
drivers/scsi/device_handler/scsi_dh.c +22 -9
@@ -102,23 +102,36 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,if (sdev->scsi_dh_data) {if (sdev->scsi_dh_data->scsi_dh != scsi_dh) - err = -EBUSY ; -else -kref_get (&sdev->scsi_dh_data->kref); - }else if (scsi_dh->attach) { +return -EBUSY ; + +kref_get (&sdev->scsi_dh_data->kref); +return 0 ; + } + +if (scsi_dh->attach) { +if (!try_module_get (scsi_dh->module)) +return -EINVAL ; + err = scsi_dh->attach (sdev); -if (!err) { -kref_init (&sdev->scsi_dh_data->kref); - sdev->scsi_dh_data->sdev = sdev; +if (err) { +module_put (scsi_dh->module); +return err; } + +kref_init (&sdev->scsi_dh_data->kref); + sdev->scsi_dh_data->sdev = sdev; }return err; }static void __detach_handler (struct kref *kref) { - struct scsi_dh_data *scsi_dh_data = container_of(kref, struct scsi_dh_data, kref); - scsi_dh_data->scsi_dh->detach (scsi_dh_data->sdev); +struct scsi_dh_data *scsi_dh_data = + container_of(kref, struct scsi_dh_data, kref); +struct scsi_device_handler *scsi_dh = scsi_dh_data->scsi_dh; + + scsi_dh->detach (scsi_dh_data->sdev); +module_put (scsi_dh->module); }/*
drivers/scsi/device_handler/scsi_dh_alua.c +0 -4
@@ -866,9 +866,6 @@ static int alua_bus_attach(struct scsi_device *sdev)if ((err !=SCSI_DH_OK ) && (err !=SCSI_DH_DEV_OFFLINED )) 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);
@@ -901,7 +898,6 @@ static void alua_bus_detach(struct scsi_device *sdev)if (h->buff && h->inq != h->buff)kfree (h->buff);kfree (scsi_dh_data); -module_put (THIS_MODULE );sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,ALUA_DH_NAME ); }
drivers/scsi/device_handler/scsi_dh_emc.c +0 -4
@@ -692,9 +692,6 @@ static int clariion_bus_attach(struct scsi_device *sdev)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);
@@ -728,7 +725,6 @@ static void clariion_bus_detach(struct scsi_device *sdev) CLARIION_NAME);kfree (scsi_dh_data); -module_put (THIS_MODULE ); }static int __init clariion_init (void )
drivers/scsi/device_handler/scsi_dh_hp_sw.c +0 -4
@@ -377,9 +377,6 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)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);
@@ -406,7 +403,6 @@ static void hp_sw_bus_detach( struct scsi_device *sdev ) scsi_dh_data = sdev->scsi_dh_data; sdev->scsi_dh_data =NULL ;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); -module_put (THIS_MODULE );sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,HP_SW_NAME );
drivers/scsi/device_handler/scsi_dh_rdac.c +0 -4
@@ -878,9 +878,6 @@ static int rdac_bus_attach(struct scsi_device *sdev)if (err !=SCSI_DH_OK ) goto clean_ctlr; -if (!try_module_get (THIS_MODULE )) - goto clean_ctlr; -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);
@@ -924,7 +921,6 @@ static void rdac_bus_detach( struct scsi_device *sdev )kref_put (&h->ctlr->kref, release_controller);spin_unlock (&list_lock);kfree (scsi_dh_data); -module_put (THIS_MODULE );sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,RDAC_NAME ); }
Signature · 1 line
1.9.1
Re: [PATCH 1/6] scsi_dh: get module reference outside of device handler
Quoted 53 lines · Christoph Hellwig
We need to grab a reference to the module before calling the attach routines to avoid a small race vs module removal. It also cleans up the code significantly as a side effect.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/scsi/device_handler/scsi_dh.c | 31 ++++++++++++++++++++--------- drivers/scsi/device_handler/scsi_dh_alua.c | 4 ---- drivers/scsi/device_handler/scsi_dh_emc.c | 4 ---- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 4 ---- drivers/scsi/device_handler/scsi_dh_rdac.c | 4 ---- 5 files changed, 22 insertions(+), 25 deletions(-)drivers/scsi/device_handler/scsi_dh.c +16
-8@@ -102,23 +102,36 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,if (sdev->scsi_dh_data) {if (sdev->scsi_dh_data->scsi_dh != scsi_dh) - err = -EBUSY ; -else -kref_get (&sdev->scsi_dh_data->kref); - }else if (scsi_dh->attach) { +return -EBUSY ; + +kref_get (&sdev->scsi_dh_data->kref); +return 0 ; + } + +if (scsi_dh->attach) { +if (!try_module_get (scsi_dh->module)) +return -EINVAL ; + err = scsi_dh->attach (sdev); -if (!err) { -kref_init (&sdev->scsi_dh_data->kref); - sdev->scsi_dh_data->sdev = sdev; +if (err) { +module_put (scsi_dh->module); +return err; } + +kref_init (&sdev->scsi_dh_data->kref); + sdev->scsi_dh_data->sdev = sdev; }return err; }static void __detach_handler (struct kref *kref) { - struct scsi_dh_data *scsi_dh_data = container_of(kref, struct scsi_dh_data, kref);
drivers/scsi/device_handler/scsi_dh.c static int scsi_dh_handler_attach(struct scsi_device *sdev, · line 137
Quoted 10 lines
drivers/scsi/device_handler/scsi_dh.c +6
-1- scsi_dh_data->scsi_dh->detach (scsi_dh_data->sdev); +struct scsi_dh_data *scsi_dh_data = + container_of(kref, struct scsi_dh_data, kref); +struct scsi_device_handler *scsi_dh = scsi_dh_data->scsi_dh; + + scsi_dh->detach (scsi_dh_data->sdev); +module_put (scsi_dh->module); }/*
Is it guaranteed that you cannot call ->attach() for devices which already have a device_handler attached?
You've skipped the case
scsi_dh != sdev->scsi_dh_data->scsi_dh
IE someone called 'attach()' on a device which already has a different device_handler attached to it.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [PATCH 1/6] scsi_dh: get module reference outside of device handler
Quoted 5 lines · Hannes Reinecke
Is it guaranteed that you cannot call ->attach() for devices which already have a
device_handlerattached?
You've skipped the case
scsi_dh!=sdev->scsi_dh_data->scsi_dh
No. Just instead of an if / else it's an if with an early return in the new code.
Hannes Reinecke
Reviewed-byRe: [PATCH 1/6] scsi_dh: get module reference outside of device handler
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Hannes Reinecke
Is it guaranteed that you cannot call ->attach() for devices which already have a
device_handlerattached?
You've skipped the case
scsi_dh!=sdev->scsi_dh_data->scsi_dhNo. Just instead of an if / else it's an if with an early return in the new code.
right. Indeed.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH 2/6 scsi: use container_of to get at device handler private data
In reply to Christoph Hellwig--- drivers/scsi/device_handler/scsi_dh_alua.c | 25 +++++++++---------------- drivers/scsi/device_handler/scsi_dh_emc.c | 24 ++++++++++-------------- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 23 +++++++++-------------- drivers/scsi/device_handler/scsi_dh_rdac.c | 25 +++++++++---------------- include/scsi/scsi_device.h | 1 - 5 files changed, 37 insertions(+), 61 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +9 -16
@@ -62,6 +62,7 @@#define ALUA_OPTIMIZE_STPG 1struct alua_dh_data { +struct scsi_dh_data dh_data;int group_id;int rel_port;int tpgs;
@@ -87,9 +88,7 @@ static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *);static inline struct alua_dh_data *get_alua_data (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; -BUG_ON (scsi_dh_data ==NULL ); -return ((struct alua_dh_data *) scsi_dh_data->buf); + return container_of(sdev->scsi_dh_data, struct alua_dh_data, dh_data); }static int realloc_buffer (struct alua_dh_data *h,unsigned len)
@@ -839,21 +838,18 @@ static struct scsi_device_handler alua_dh = {*/ static int alua_bus_attach (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data;struct alua_dh_data *h;unsigned long flags;int err =SCSI_DH_OK ; - scsi_dh_data =kzalloc (sizeof (*scsi_dh_data) - +sizeof (*h) ,GFP_KERNEL ); -if (!scsi_dh_data) { + h =kzalloc (sizeof (*h) ,GFP_KERNEL ); +if (!h) {sdev_printk (KERN_ERR , sdev,"%s: Attach failed\n" ,ALUA_DH_NAME );return -ENOMEM ; } - scsi_dh_data->scsi_dh = &alua_dh; - h = (struct alua_dh_data *) scsi_dh_data->buf; + h->dh_data.scsi_dh = &alua_dh; h->tpgs =TPGS_MODE_UNINITIALIZED ; h->state =TPGS_STATE_OPTIMIZED ; h->group_id =-1 ;
@@ -867,14 +863,14 @@ static int alua_bus_attach(struct scsi_device *sdev) goto failed;spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - sdev->scsi_dh_data = scsi_dh_data; + sdev->scsi_dh_data = &h->dh_data;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags);sdev_printk (KERN_NOTICE , sdev,"%s: Attached\n" ,ALUA_DH_NAME );return 0 ; failed: -kfree (scsi_dh_data); +kfree (h);sdev_printk (KERN_ERR , sdev,"%s: not attached\n" ,ALUA_DH_NAME );return -EINVAL ; }
@@ -885,19 +881,16 @@ failed:*/ static void alua_bus_detach (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data; -struct alua_dh_data *h; +struct alua_dh_data *h =get_alua_data (sdev);unsigned long flags;spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - scsi_dh_data = sdev->scsi_dh_data; sdev->scsi_dh_data =NULL ;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); - h = (struct alua_dh_data *) scsi_dh_data->buf;if (h->buff && h->inq != h->buff)kfree (h->buff); -kfree (scsi_dh_data); +kfree (h);sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,ALUA_DH_NAME ); }
drivers/scsi/device_handler/scsi_dh_emc.c +10 -14
@@ -72,6 +72,7 @@ static const char * lun_state[] = };struct clariion_dh_data { +struct scsi_dh_data dh_data;/* * Flags: * CLARIION_SHORT_TRESPASS
@@ -116,9 +117,8 @@ struct clariion_dh_data {static inline struct clariion_dh_data *get_clariion_data (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; -BUG_ON (scsi_dh_data ==NULL ); -return ((struct clariion_dh_data *) scsi_dh_data->buf); + return container_of(sdev->scsi_dh_data, struct clariion_dh_data, + dh_data); }/*
@@ -665,21 +665,18 @@ static struct scsi_device_handler clariion_dh = {static int clariion_bus_attach (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data;struct clariion_dh_data *h;unsigned long flags;int err; - scsi_dh_data =kzalloc (sizeof (*scsi_dh_data) - +sizeof (*h) ,GFP_KERNEL ); -if (!scsi_dh_data) { + h =kzalloc (sizeof (*h) ,GFP_KERNEL ); +if (!h) {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->dh_data.scsi_dh = &clariion_dh; h->lun_state =CLARIION_LUN_UNINITIALIZED ; h->default_sp =CLARIION_UNBOUND_LU ; h->current_sp =CLARIION_UNBOUND_LU ;
@@ -693,7 +690,7 @@ static int clariion_bus_attach(struct scsi_device *sdev) goto failed;spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - sdev->scsi_dh_data = scsi_dh_data; + sdev->scsi_dh_data = &h->dh_data;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); sdev_printk(KERN_INFO, sdev,
@@ -705,7 +702,7 @@ static int clariion_bus_attach(struct scsi_device *sdev)return 0 ; failed: -kfree (scsi_dh_data); +kfree (h);sdev_printk (KERN_ERR , sdev,"%s: not attached\n" ,CLARIION_NAME );return -EINVAL ;
@@ -713,18 +710,17 @@ failed:static void clariion_bus_detach (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data; +struct clariion_dh_data *h =get_clariion_data (sdev);unsigned long flags;spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - scsi_dh_data = sdev->scsi_dh_data; sdev->scsi_dh_data =NULL ;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags);sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,CLARIION_NAME ); -kfree (scsi_dh_data); +kfree (h); }static int __init clariion_init (void )
drivers/scsi/device_handler/scsi_dh_hp_sw.c +9 -14
@@ -38,6 +38,7 @@#define HP_SW_PATH_PASSIVE 1struct hp_sw_dh_data { +struct scsi_dh_data dh_data;unsigned char sense[SCSI_SENSE_BUFFERSIZE ];int path_state;int retries;
@@ -51,9 +52,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *);static inline struct hp_sw_dh_data *get_hp_sw_data (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; -BUG_ON (scsi_dh_data ==NULL ); -return ((struct hp_sw_dh_data *) scsi_dh_data->buf); + return container_of(sdev->scsi_dh_data, struct hp_sw_dh_data, dh_data); }/*
@@ -354,21 +353,18 @@ static struct scsi_device_handler hp_sw_dh = {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 (*scsi_dh_data) - +sizeof (*h) ,GFP_KERNEL ); -if (!scsi_dh_data) { + h =kzalloc (sizeof (*h),GFP_KERNEL ); +if (!h) {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->dh_data.scsi_dh = &hp_sw_dh; h->path_state =HP_SW_PATH_UNINITIALIZED ; h->retries =HP_SW_RETRIES ; h->sdev = sdev;
@@ -378,7 +374,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev) goto failed;spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - sdev->scsi_dh_data = scsi_dh_data; + sdev->scsi_dh_data = &h->dh_data;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n",
@@ -388,7 +384,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)return 0 ; failed: -kfree (scsi_dh_data); +kfree (h);sdev_printk (KERN_ERR , sdev,"%s: not attached\n" ,HP_SW_NAME );return -EINVAL ;
@@ -396,17 +392,16 @@ failed:static void hp_sw_bus_detach (struct scsi_device *sdev ) { -struct scsi_dh_data *scsi_dh_data; +struct hp_sw_dh_data *h =get_hp_sw_data (sdev);unsigned long flags;spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - scsi_dh_data = sdev->scsi_dh_data; sdev->scsi_dh_data =NULL ;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags);sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,HP_SW_NAME ); -kfree (scsi_dh_data); +kfree (h); }static int __init hp_sw_init (void )
drivers/scsi/device_handler/scsi_dh_rdac.c +9 -16
@@ -181,6 +181,7 @@ struct c2_inquiry { };struct rdac_dh_data { +struct scsi_dh_data dh_data;struct rdac_controller *ctlr;#define UNINITIALIZED_LUN (1 << 8)unsigned lun;
@@ -261,9 +262,7 @@ do { \static inline struct rdac_dh_data *get_rdac_data (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; -BUG_ON (scsi_dh_data ==NULL ); -return ((struct rdac_dh_data *) scsi_dh_data->buf); + return container_of(sdev->scsi_dh_data, struct rdac_dh_data, dh_data); } static struct request *get_rdac_req(struct scsi_device *sdev,
@@ -842,23 +841,20 @@ static struct scsi_device_handler rdac_dh = {static int rdac_bus_attach (struct scsi_device *sdev) { -struct scsi_dh_data *scsi_dh_data;struct rdac_dh_data *h;unsigned long flags;int err;char array_name[ARRAY_LABEL_LEN ];char array_id[UNIQUE_ID_LEN ]; - scsi_dh_data =kzalloc (sizeof (*scsi_dh_data) - +sizeof (*h) ,GFP_KERNEL ); -if (!scsi_dh_data) { + h =kzalloc (sizeof (*h) ,GFP_KERNEL ); +if (!h) {sdev_printk (KERN_ERR , sdev,"%s: Attach failed\n" ,RDAC_NAME );return -ENOMEM ; } - scsi_dh_data->scsi_dh = &rdac_dh; - h = (struct rdac_dh_data *) scsi_dh_data->buf; + h->dh_data.scsi_dh = &rdac_dh; h->lun =UNINITIALIZED_LUN ; h->state =RDAC_STATE_ACTIVE ;
@@ -879,7 +875,7 @@ static int rdac_bus_attach(struct scsi_device *sdev) goto clean_ctlr;spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - sdev->scsi_dh_data = scsi_dh_data; + sdev->scsi_dh_data = &h->dh_data;spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); sdev_printk(KERN_NOTICE, sdev,
@@ -895,7 +891,7 @@ clean_ctlr:spin_unlock (&list_lock); failed: -kfree (scsi_dh_data); +kfree (h);sdev_printk (KERN_ERR , sdev,"%s: not attached\n" ,RDAC_NAME );return -EINVAL ;
@@ -903,12 +899,9 @@ failed:static void rdac_bus_detach (struct scsi_device *sdev ) { -struct scsi_dh_data *scsi_dh_data; -struct rdac_dh_data *h; +struct rdac_dh_data *h =get_rdac_data (sdev);unsigned long flags; - scsi_dh_data = sdev->scsi_dh_data; - h = (struct rdac_dh_data *) scsi_dh_data->buf;if (h->ctlr && h->ctlr->ms_queued)flush_workqueue (kmpath_rdacd);
@@ -920,7 +913,7 @@ static void rdac_bus_detach( struct scsi_device *sdev )if (h->ctlr)kref_put (&h->ctlr->kref, release_controller);spin_unlock (&list_lock); -kfree (scsi_dh_data); +kfree (h);sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" ,RDAC_NAME ); }
include/scsi/scsi_device.h +0 -1
@@ -228,7 +228,6 @@ struct scsi_dh_data {struct scsi_device_handler *scsi_dh;struct scsi_device *sdev;struct kref kref; -char buf[0 ]; };#define to_scsi_device (d) \
Signature · 1 line
1.9.1
Re: [PATCH 2/6] scsi: use container_of to get at device handler private data
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH 3/6 scsi: remove struct scsi_dh_devlist
In reply to Christoph HellwigAll drivers now do their own matching, so there is no more need to expose a device list as part of the interface.
--- drivers/scsi/device_handler/scsi_dh_emc.c | 6 ++++-- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 6 ++++-- drivers/scsi/device_handler/scsi_dh_rdac.c | 6 ++++-- include/scsi/scsi_device.h | 6 ------ 4 files changed, 12 insertions(+), 12 deletions(-)
drivers/scsi/device_handler/scsi_dh_emc.c +4 -2
@@ -622,7 +622,10 @@ done:return result; } -static const struct scsi_dh_devlist clariion_dev_list[] = { +static const struct { +char *vendor; +char *model; +} clariion_dev_list[] = { {"DGC" ,"RAID" }, {"DGC" ,"DISK" }, {"DGC" ,"VRAID" },
@@ -653,7 +656,6 @@ static void clariion_bus_detach(struct scsi_device *sdev);static struct scsi_device_handler clariion_dh = { .name =CLARIION_NAME , .module =THIS_MODULE , - .devlist = clariion_dev_list, .attach = clariion_bus_attach, .detach = clariion_bus_detach, .check_sense = clariion_check_sense,
drivers/scsi/device_handler/scsi_dh_hp_sw.c +4 -2
@@ -311,7 +311,10 @@ static int hp_sw_activate(struct scsi_device *sdev,return 0 ; } -static const struct scsi_dh_devlist hp_sw_dh_data_list[] = { +static const struct { +char *vendor; +char *model; +} hp_sw_dh_data_list[] = { {"COMPAQ" ,"MSA1000 VOLUME" }, {"COMPAQ" ,"HSV110" }, {"HP" ,"HSV100" },
@@ -343,7 +346,6 @@ static void hp_sw_bus_detach(struct scsi_device *sdev);static struct scsi_device_handler hp_sw_dh = { .name =HP_SW_NAME , .module =THIS_MODULE , - .devlist = hp_sw_dh_data_list, .attach = hp_sw_bus_attach, .detach = hp_sw_bus_detach, .activate = hp_sw_activate,
drivers/scsi/device_handler/scsi_dh_rdac.c +4 -2
@@ -778,7 +778,10 @@ static int rdac_check_sense(struct scsi_device *sdev,return SCSI_RETURN_NOT_HANDLED ; } -static const struct scsi_dh_devlist rdac_dev_list[] = { +static const struct { +char *vendor; +char *model; +} rdac_dev_list[] = { {"IBM" ,"1722" }, {"IBM" ,"1724" }, {"IBM" ,"1726" },
@@ -830,7 +833,6 @@ static void rdac_bus_detach(struct scsi_device *sdev);static struct scsi_device_handler rdac_dh = { .name =RDAC_NAME , .module =THIS_MODULE , - .devlist = rdac_dev_list, .prep_fn = rdac_prep_fn, .check_sense = rdac_check_sense, .attach = rdac_bus_attach,
include/scsi/scsi_device.h +0 -6
@@ -201,11 +201,6 @@ struct scsi_device {unsigned long sdev_data[0 ]; } __attribute__((aligned(sizeof(unsigned long)))); -struct scsi_dh_devlist { -char *vendor; -char *model; -}; -typedef void (*activate_complete )(void *,int );struct scsi_device_handler {/* Used by the infrastructure */
@@ -214,7 +209,6 @@ struct scsi_device_handler {/* 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 *);
Signature · 1 line
1.9.1
Re: [PATCH 3/6] scsi: remove struct scsi_dh_devlist
Quoted 101 lines · Christoph Hellwig
All drivers now do their own matching, so there is no more need to expose a device list as part of the interface.
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/scsi/device_handler/scsi_dh_emc.c | 6 ++++-- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 6 ++++-- drivers/scsi/device_handler/scsi_dh_rdac.c | 6 ++++-- include/scsi/scsi_device.h | 6 ------ 4 files changed, 12 insertions(+), 12 deletions(-)drivers/scsi/device_handler/scsi_dh_emc.c +4
-2@@ -622,7 +622,10 @@ done:return result; } -static const struct scsi_dh_devlist clariion_dev_list[] = { +static const struct { +char *vendor; +char *model; +} clariion_dev_list[] = { {"DGC" ,"RAID" }, {"DGC" ,"DISK" }, {"DGC" ,"VRAID" },@@ -653,7 +656,6 @@ static void clariion_bus_detach(struct scsi_device *sdev);static struct scsi_device_handler clariion_dh = { .name =CLARIION_NAME , .module =THIS_MODULE , - .devlist = clariion_dev_list, .attach = clariion_bus_attach, .detach = clariion_bus_detach, .check_sense = clariion_check_sense,drivers/scsi/device_handler/scsi_dh_hp_sw.c +4
-2@@ -311,7 +311,10 @@ static int hp_sw_activate(struct scsi_device *sdev,return 0 ; } -static const struct scsi_dh_devlist hp_sw_dh_data_list[] = { +static const struct { +char *vendor; +char *model; +} hp_sw_dh_data_list[] = { {"COMPAQ" ,"MSA1000 VOLUME" }, {"COMPAQ" ,"HSV110" }, {"HP" ,"HSV100" },@@ -343,7 +346,6 @@ static void hp_sw_bus_detach(struct scsi_device *sdev);static struct scsi_device_handler hp_sw_dh = { .name =HP_SW_NAME , .module =THIS_MODULE , - .devlist = hp_sw_dh_data_list, .attach = hp_sw_bus_attach, .detach = hp_sw_bus_detach, .activate = hp_sw_activate,drivers/scsi/device_handler/scsi_dh_rdac.c +4
-2@@ -778,7 +778,10 @@ static int rdac_check_sense(struct scsi_device *sdev,return SCSI_RETURN_NOT_HANDLED ; } -static const struct scsi_dh_devlist rdac_dev_list[] = { +static const struct { +char *vendor; +char *model; +} rdac_dev_list[] = { {"IBM" ,"1722" }, {"IBM" ,"1724" }, {"IBM" ,"1726" },@@ -830,7 +833,6 @@ static void rdac_bus_detach(struct scsi_device *sdev);static struct scsi_device_handler rdac_dh = { .name =RDAC_NAME , .module =THIS_MODULE , - .devlist = rdac_dev_list, .prep_fn = rdac_prep_fn, .check_sense = rdac_check_sense, .attach = rdac_bus_attach,include/scsi/scsi_device.h +0
-5@@ -201,11 +201,6 @@ struct scsi_device {unsigned long sdev_data[0 ]; } __attribute__((aligned(sizeof(unsigned long)))); -struct scsi_dh_devlist { -char *vendor; -char *model; -}; -typedef void (*activate_complete )(void *,int );struct scsi_device_handler {/* Used by the infrastructure */
include/scsi/scsi_device.h struct scsi_device_handler { · line 214
Quoted 7 lines
include/scsi/scsi_device.h +0
-1@@ -214,7 +209,6 @@ struct scsi_device_handler {/* 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 *);
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH 4/6 scsi: device handlers must have attach and detach methods
In reply to Christoph Hellwig--- drivers/scsi/device_handler/scsi_dh.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
drivers/scsi/device_handler/scsi_dh.c +13 -12
@@ -108,19 +108,17 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,return 0 ; } -if (scsi_dh->attach) { -if (!try_module_get (scsi_dh->module)) -return -EINVAL ; - - err = scsi_dh->attach (sdev); -if (err) { -module_put (scsi_dh->module); -return err; - } +if (!try_module_get (scsi_dh->module)) +return -EINVAL ; -kref_init (&sdev->scsi_dh_data->kref); - sdev->scsi_dh_data->sdev = sdev; + err = scsi_dh->attach (sdev); +if (err) { +module_put (scsi_dh->module); +return err; } + +kref_init (&sdev->scsi_dh_data->kref); + sdev->scsi_dh_data->sdev = sdev;return err; }
@@ -154,7 +152,7 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev,if (!scsi_dh) scsi_dh = sdev->scsi_dh_data->scsi_dh; -if (scsi_dh && scsi_dh->detach) +if (scsi_dh)kref_put (&sdev->scsi_dh_data->kref, __detach_handler); }
@@ -343,6 +341,9 @@ int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)if (get_device_handler (scsi_dh->name))return -EBUSY ; +if (!scsi_dh->attach || !scsi_dh->detach) +return -EINVAL ; +spin_lock (&list_lock);list_add (&scsi_dh->list, &scsi_dh_list);spin_unlock (&list_lock);
Signature · 1 line
1.9.1
Re: [PATCH 4/6] scsi: device handlers must have attach and detach methods
Quoted 49 lines · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/scsi/device_handler/scsi_dh.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)drivers/scsi/device_handler/scsi_dh.c +10
-12@@ -108,19 +108,17 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,return 0 ; } -if (scsi_dh->attach) { -if (!try_module_get (scsi_dh->module)) -return -EINVAL ; - - err = scsi_dh->attach (sdev); -if (err) { -module_put (scsi_dh->module); -return err; - } +if (!try_module_get (scsi_dh->module)) +return -EINVAL ; -kref_init (&sdev->scsi_dh_data->kref); - sdev->scsi_dh_data->sdev = sdev; + err = scsi_dh->attach (sdev); +if (err) { +module_put (scsi_dh->module); +return err; } + +kref_init (&sdev->scsi_dh_data->kref); + sdev->scsi_dh_data->sdev = sdev;return err; }@@ -154,7 +152,7 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev,if (!scsi_dh) scsi_dh = sdev->scsi_dh_data->scsi_dh; -if (scsi_dh && scsi_dh->detach) +if (scsi_dh)kref_put (&sdev->scsi_dh_data->kref, __detach_handler); }
drivers/scsi/device_handler/scsi_dh.c int scsi_register_device_handler(struct scsi_device_handler *scsi_dh) · line 349
Quoted 9 lines
drivers/scsi/device_handler/scsi_dh.c +3
-0@@ -343,6 +341,9 @@ int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)if (get_device_handler (scsi_dh->name))return -EBUSY ; +if (!scsi_dh->attach || !scsi_dh->detach) +return -EINVAL ; +spin_lock (&list_lock);list_add (&scsi_dh->list, &scsi_dh_list);spin_unlock (&list_lock);
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH 5/6 scsi_dh_hp_sw: fix return value on failed allocation
In reply to Christoph Hellwig--- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/device_handler/scsi_dh_hp_sw.c +1 -1
@@ -363,7 +363,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)if (!h) {sdev_printk (KERN_ERR , sdev,"%s: Attach Failed\n" ,HP_SW_NAME ); -return 0 ; +return -ENOMEM ; } h->dh_data.scsi_dh = &hp_sw_dh;
Signature · 1 line
1.9.1
Re: [PATCH 5/6] scsi_dh_hp_sw: fix return value on failed allocation
Quoted 11 lines · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>--- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/scsi/device_handler/scsi_dh_hp_sw.c +0
-0
drivers/scsi/device_handler/scsi_dh_hp_sw.c static int hp_sw_bus_attach(struct scsi_device *sdev) · line 369
Quoted 8 lines
drivers/scsi/device_handler/scsi_dh_hp_sw.c +1
-1@@ -363,7 +363,7 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)if (!h) {sdev_printk (KERN_ERR , sdev,"%s: Attach Failed\n" ,HP_SW_NAME ); -return 0 ; +return -ENOMEM ; } h->dh_data.scsi_dh = &hp_sw_dh;
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH 6/6 scsi: handle more device handler setup/teardown in common code
In reply to Christoph HellwigMove all code to set up and tear down sdev->scsi_dh_data to common code.
--- drivers/scsi/device_handler/scsi_dh.c | 29 ++++++++++---- drivers/scsi/device_handler/scsi_dh_alua.c | 59 ++++++++++------------------- drivers/scsi/device_handler/scsi_dh_emc.c | 58 +++++++++------------------- drivers/scsi/device_handler/scsi_dh_hp_sw.c | 54 ++++++++------------------ drivers/scsi/device_handler/scsi_dh_rdac.c | 52 +++++++------------------ include/scsi/scsi_device.h | 2 +- 6 files changed, 87 insertions(+), 167 deletions(-)
drivers/scsi/device_handler/scsi_dh.c +21 -8
@@ -98,7 +98,7 @@ device_handler_match(struct scsi_device_handler *scsi_dh,static int scsi_dh_handler_attach (struct scsi_device *sdev,struct scsi_device_handler *scsi_dh) { -int err =0 ; +struct scsi_dh_data *d;if (sdev->scsi_dh_data) {if (sdev->scsi_dh_data->scsi_dh != scsi_dh)
@@ -111,15 +111,22 @@ static int scsi_dh_handler_attach(struct scsi_device *sdev,if (!try_module_get (scsi_dh->module))return -EINVAL ; - err = scsi_dh->attach (sdev); -if (err) { + d = scsi_dh->attach (sdev); +if (IS_ERR (d)) { +sdev_printk (KERN_ERR , sdev,"%s: Attach failed (%ld)\n" , + scsi_dh->name,PTR_ERR (d));module_put (scsi_dh->module); -return err; +return PTR_ERR (d); } -kref_init (&sdev->scsi_dh_data->kref); - sdev->scsi_dh_data->sdev = sdev; -return err; + d->scsi_dh = scsi_dh; +kref_init (&d->kref); + d->sdev = sdev; + +spin_lock_irq (sdev->request_queue->queue_lock); + sdev->scsi_dh_data = d; +spin_unlock_irq (sdev->request_queue->queue_lock); +return 0 ; }static void __detach_handler (struct kref *kref)
@@ -127,8 +134,14 @@ static void __detach_handler (struct kref *kref)struct scsi_dh_data *scsi_dh_data = container_of(kref, struct scsi_dh_data, kref);struct scsi_device_handler *scsi_dh = scsi_dh_data->scsi_dh; +struct scsi_device *sdev = scsi_dh_data->sdev; + +spin_lock_irq (sdev->request_queue->queue_lock); + sdev->scsi_dh_data =NULL ; +spin_unlock_irq (sdev->request_queue->queue_lock); - scsi_dh->detach (scsi_dh_data->sdev); + scsi_dh->detach (sdev); +sdev_printk (KERN_NOTICE , sdev,"%s: Detached\n" , scsi_dh->name);module_put (scsi_dh->module); }
drivers/scsi/device_handler/scsi_dh_alua.c +19 -40
96 lines not on this page · raw message
drivers/scsi/device_handler/scsi_dh_emc.c +17 -41
92 lines not on this page · raw message
drivers/scsi/device_handler/scsi_dh_hp_sw.c +15 -39
85 lines not on this page · raw message
drivers/scsi/device_handler/scsi_dh_rdac.c +14 -38
97 lines not on this page · raw message
include/scsi/scsi_device.h +1 -1
@@ -210,7 +210,7 @@ struct scsi_device_handler {struct module *module;const char *name;int (*check_sense)(struct scsi_device *,struct scsi_sense_hdr *); -int (*attach)(struct scsi_device *); +struct scsi_dh_data *(*attach)(struct scsi_device *);void (*detach)(struct scsi_device *);int (*activate)(struct scsi_device *,activate_complete ,void *);int (*prep_fn)(struct scsi_device *,struct request *);
Signature · 1 line
1.9.1
Re: [PATCH 6/6] scsi: handle more device handler setup/teardown in common code
Quoted 3 lines · Christoph Hellwig
Move all code to set up and tear down
sdev->scsi_dh_datato common code.Signed-off-by Christoph Hellwig <[email protected]>
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [PATCH 6/6] scsi: handle more device handler setup/teardown in common code
In reply to Christoph HellwigQuoted 26 lines · Christoph Hellwig
drivers/scsi/device_handler/scsi_dh_rdac.c +3
-9-static int rdac_bus_attach (struct scsi_device *sdev) +static struct scsi_dh_data *rdac_bus_attach (struct scsi_device *sdev) {struct rdac_dh_data *h; -unsigned long flags;int err;char array_name[ARRAY_LABEL_LEN ];char array_id[UNIQUE_ID_LEN ]; h =kzalloc (sizeof (*h) ,GFP_KERNEL ); -if (!h) { -sdev_printk (KERN_ERR , sdev,"%s: Attach failed\n" , -RDAC_NAME ); -return -ENOMEM ; - } - - h->dh_data.scsi_dh = &rdac_dh; +if (!h) +return ERR_PTR (-ENOMEM ); h->lun =UNINITIALIZED_LUN ; h->state =RDAC_STATE_ACTIVE ;@@ -876,15 +856,10 @@ static int rdac_bus_attach(struct scsi_device *sdev)if (err !=SCSI_DH_OK ) goto clean_ctlr;
drivers/scsi/device_handler/scsi_dh_rdac.c static int rdac_bus_attach(struct scsi_device *sdev) · line 863
Quoted 10 lines
drivers/scsi/device_handler/scsi_dh_rdac.c +0
-5-spin_lock_irqsave (sdev->request_queue->queue_lock, flags); - sdev->scsi_dh_data = &h->dh_data; -spin_unlock_irqrestore (sdev->request_queue->queue_lock, flags); -sdev_printk (KERN_NOTICE , sdev,"%s: LUN %d (%s) (%s)\n" ,RDAC_NAME , h->lun, mode[(int )h->mode], lun_state[(int )h->lun_state]); -return 0 ;
Was this supposed to return a "struct scsi_dh_data *" instead of zero here?
Re: [PATCH 6/6] scsi: handle more device handler setup/teardown in common code
Quoted 1 line · Mike Christie
Was this supposed to return a "struct
scsi_dh_data*" instead of zero here?
Yes, thanks for catching it.