scsi_dh: add scsi_dh_attached_handler_name
Subsystems (2)
PATCH v3 2/5 scsi_dh: add scsi_dh_attached_handler_name
Originally posted to dm-devel but Chandra reminded me to post to linux-scsi for James to pick it up.
-------8<-------
Introduce scsi_dh_attached_handler_name() to retrieve the name of the scsi_dh that is attached to the scsi_device associated with the provided request queue. Returns NULL if a scsi_dh is not attached.
Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
--- drivers/scsi/device_handler/scsi_dh.c | 36 ++++++++++++++++++++++++++++++++-- include/scsi/scsi_dh.h | 5 ++++ 2 files changed, 39 insertions(+), 2 deletions(-)
v3: fixed missing put_device that Babu pointed out
drivers/scsi/device_handler/scsi_dh.c +34 -2
@@ -468,7 +468,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_handler_exist)/* * scsi_dh_attach - Attach device handler -* @sdev - sdev the handler should be attached to +* @q - Request queue that is associated with the scsi_device +* the handler should be attached to * @name - name of the handler to attach */ int scsi_dh_attach (struct request_queue *q,const char *name)
@@ -498,7 +499,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);/* * scsi_dh_detach - Detach device handler -* @sdev - sdev the handler should be detached from +* @q - Request queue that is associated with the scsi_device +* the handler should be detached from * * This function will detach the device handler only * if the sdev is not part of the internal list, ie
@@ -527,6 +529,36 @@ void scsi_dh_detach(struct request_queue }EXPORT_SYMBOL_GPL (scsi_dh_detach); +/* +* scsi_dh_attached_handler_name - Get attached device handler's name +* @q - Request queue that is associated with the scsi_device +* that may have a device handler attached +* +* Returns name of attached handler, NULL if no handler is attached. +*/ +const char *scsi_dh_attached_handler_name (struct request_queue *q) +{ +unsigned long flags; +struct scsi_device *sdev; +const char *handler_name =NULL ; + +spin_lock_irqsave (q->queue_lock, flags); + sdev = q->queuedata; +if (!sdev || !get_device (&sdev->sdev_gendev)) + sdev =NULL ; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (!sdev) +return NULL ; + +if (sdev->scsi_dh_data) + handler_name = sdev->scsi_dh_data->scsi_dh->name; + +put_device (&sdev->sdev_gendev); +return handler_name; +} +EXPORT_SYMBOL_GPL (scsi_dh_attached_handler_name); +static struct notifier_block scsi_dh_nb = { .notifier_call = scsi_dh_notifier };
include/scsi/scsi_dh.h +5 -0
@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct requeextern 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 *); +extern const char *scsi_dh_attached_handler_name (struct request_queue *q);extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,
@@ -80,6 +81,10 @@ static inline void scsi_dh_detach(struct {return ; } +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q) +{ +return NULL ; +}static inline int scsi_dh_set_params (struct request_queue *req,const char *params) {return -SCSI_DH_NOSYS ;
Quoted 11 lines · Mike Snitzer
Originally posted to dm-devel but Chandra reminded me to post to linux-scsi for James to pick it up.
-------8<-------
Introduce
scsi_dh_attached_handler_name()to retrieve the name of thescsi_dhthat is attached to thescsi_deviceassociated with the provided request queue. Returns NULL if ascsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
Wha'ts the use case for this? The name is stale as soon as the function returns.
Quoted 6 lines · Christoph Hellwig
Quoted 5 lines · Mike Snitzer
Originally posted to dm-devel but Chandra reminded me to post to linux-scsi for James to pick it up.
-------8<-------
Quoted 8 lines
Quoted 6 lines
Introduce
scsi_dh_attached_handler_name()to retrieve the name of thescsi_dhthat is attached to thescsi_deviceassociated with the provided request queue. Returns NULL if ascsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
Wha'ts the use case for this?
See this patch:
http://www.redhat.com/archives/dm-devel/2012-May/msg00046.html
(I attributed this change to Hannes because it was based on his earlier patch... I should probably change that given that in the end I re-wrote/merged his patch with my earlier patch...)
Anyway, DM mpath doesn't want to know about the "scsi_dh" structure, but we need the name of the attached handler (to adjust the multipath device's 'hw_handler_name' and to get an additional ref on the attached scsi_dh via dm-mapth.c:parse_path's scsi_dh_attach).
BTW, only reason I split the scsi_dh change from the above dm-mpath patch is because I'm patching SCSI and DM and need to send the changes through different trees.
Quoted 1 line
The name is stale as soon as the function returns.
Yeah, I have since wondered about that myself. In practice the attached handler should remain attached so the name really won't be stale.
But in theory there could be a race with scsi_dh_detach. So I think the following should address your concern?
If so I'll refresh and repost the appropriate patches.
Thanks.
drivers/md/dm-mpath.c +3 -2
@@ -592,10 +592,11 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps q =bdev_get_queue (p->path.dev->bdev);if (m->use_default_hw_handler) { -const char *attached_handler_name =scsi_dh_attached_handler_name (q); +const char *attached_handler_name = +scsi_dh_attached_handler_name (q,GFP_KERNEL );if (attached_handler_name) {kfree (m->hw_handler_name); - m->hw_handler_name =kstrdup (attached_handler_name,GFP_KERNEL ); + m->hw_handler_name = attached_handler_name; } }
drivers/scsi/device_handler/scsi_dh.c +4 -2
@@ -533,10 +533,12 @@ EXPORT_SYMBOL_GPL(scsi_dh_detach);* scsi_dh_attached_handler_name - Get attached device handler's name * @q - Request queue that is associated with the scsi_device * that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory * * Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. */ -const char *scsi_dh_attached_handler_name (struct request_queue *q) +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) {unsigned long flags;struct scsi_device *sdev;
@@ -552,7 +554,7 @@ const char *scsi_dh_attached_handler_name(struct request_queue *q)return NULL ;if (sdev->scsi_dh_data) - handler_name = sdev->scsi_dh_data->scsi_dh->name; + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp);put_device (&sdev->sdev_gendev);return handler_name;
include/scsi/scsi_dh.h +3 -2
@@ -60,7 +60,7 @@ extern int scsi_dh_activate(struct request_queue *, activate_complete, void *);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 *); -extern const char *scsi_dh_attached_handler_name (struct request_queue *q); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,
@@ -81,7 +81,8 @@ static inline void scsi_dh_detach(struct request_queue *q) {return ; } -static inline const char *scsi_dh_attached_handler_name (struct request_queue *q) +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp) {return NULL ; }
I have tested these patches(1 to 5) with scsi_dh_rdac and scsi_dh_alua. These modules are loaded as part of initrd image. For some devices scsi_dh_rdac is the default and for some scsi_dh_alua is default. Everything worked as expected.
Output of dmsetup table
3600a0b8000501df0000008134b432748: 0 41943040 multipath 2 queue_if_no_path default_hw_handler 1 rdac 2 1 round-robin 0 1 1 66:0 6 round-robin 0 1 1 8:64 1 360080e50001b098200008f054f63c73c: 0 20971520 multipath 2 queue_if_no_path default_hw_handler 1 alua 2 1 round-robin 0 1 1 67:80 14 round-robin 0 1 1 67:160 9
Quoted 138 lines
-----Original Message-----
From: Mike Snitzer [mailto:[email protected]]
Sent: Thursday, May 10, 2012 9:11 AM
To: Christoph Hellwig
Cc: [email protected]; [email protected]; [email protected]; Moger, Babu; [email protected]
Subject: Re: [PATCH v3 2/5]scsi_dh: addscsi_dh_attached_handler_nameQuoted 11 lines · Christoph Hellwig
Quoted 10 lines · Mike Snitzer
Originally posted to dm-devel but Chandra reminded me to post to linux-scsi for James to pick it up.
-------8<-------
Introduce
scsi_dh_attached_handler_name()to retrieve the name of thescsi_dhthat is attached to thescsi_deviceassociated with the provided request queue. Returns NULL if ascsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to
document
Quoted 3 lines
Quoted 1 line
@q rather than @sdev.
Wha'ts the use case for this?
See this patch:
http://www.redhat.com/archives/dm-devel/2012-May/msg00046.html(I attributed this change to Hannes because it was based on his earlier patch... I should probably change that given that in the end I re-wrote/merged his patch with my earlier patch...)
Anyway, DM mpath doesn't want to know about the "
scsi_dh" structure, but we need the name of the attached handler (to adjust the multipath device's 'hw_handler_name' and to get an additional ref on the attachedscsi_dhvia dm-mapth.c:parse_path'sscsi_dh_attach).BTW, only reason I split the
scsi_dhchange from the above dm-mpath patch is because I'm patching SCSI and DM and need to send the changes through different trees.Quoted 1 line
The name is stale as soon as the function returns.
Yeah, I have since wondered about that myself. In practice the attached handler should remain attached so the name really won't be stale.
But in theory there could be a race with
scsi_dh_detach. So I think the following should address your concern?If so I'll refresh and repost the appropriate patches.
Thanks.
drivers/md/dm-mpath.c +3
-2@@ -592,10 +592,11 @@ static struct pgpath *parse_path(struct dm_arg_set *as, struct path_selector *ps q = bdev_get_queue(p->path.dev->bdev);if (m->use_default_hw_handler) { -const char *attached_handler_name =scsi_dh_attached_handler_name (q); +const char *attached_handler_name = +scsi_dh_attached_handler_name (q,GFP_KERNEL );if (attached_handler_name) {kfree (m->hw_handler_name); - m->hw_handler_name =kstrdup (attached_handler_name,GFP_KERNEL ); + m->hw_handler_name = attached_handler_name;drivers/md/dm-mpath.c +0
-0} }drivers/scsi/device_handler/scsi_dh.c +3
-1@@ -533,10 +533,12 @@ EXPORT_SYMBOL_GPL(scsi_dh_detach);* scsi_dh_attached_handler_name - Get attached device handler's name * @q - Request queue that is associated with the scsi_device * that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory * * Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. */ -const char *scsi_dh_attached_handler_name (struct request_queue *q) +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) {unsigned long flags;drivers/scsi/device_handler/scsi_dh.c +1
-1struct scsi_device *sdev;@@ -552,7 +554,7 @@ const char *scsi_dh_attached_handler_name(struct request_queue *q)return NULL ;if (sdev->scsi_dh_data) - handler_name = sdev->scsi_dh_data->scsi_dh->name; + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh- >name, gfp);drivers/scsi/device_handler/scsi_dh.c +0
-0put_device (&sdev->sdev_gendev);return handler_name;include/scsi/scsi_dh.h +1
-1@@ -60,7 +60,7 @@ extern int scsi_dh_activate(struct request_queue *, activate_complete, void *);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 *); -extern const char *scsi_dh_attached_handler_name (struct request_queue *q); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int
scsi_dh_set_params(struct request_queue *, const char *); #else
static inline int scsi_dh_activate(structrequest_queue*req,include/scsi/scsi_dh.h +2
-1@@ -81,7 +81,8 @@ static inline void scsi_dh_detach(struct request_queue *q) {return ; } -static inline const char *scsi_dh_attached_handler_name (struct request_queue *q) +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp){
return NULL;
}
Mike, Yes, I have retested using this patch. Everything looks good.
Quoted 144 lines
-----Original Message-----
From: Mike Snitzer [mailto:[email protected]]
Sent: Thursday, May 10, 2012 9:11 AM
To: Christoph Hellwig
Cc: [email protected]; [email protected]; [email protected]; Moger, Babu; [email protected]
Subject: Re: [PATCH v3 2/5]scsi_dh: addscsi_dh_attached_handler_nameQuoted 7 lines · Christoph Hellwig
Quoted 6 lines · Mike Snitzer
Originally posted to dm-devel but Chandra reminded me to post to linux-scsi for James to pick it up.
-------8<-------
Introduce
scsi_dh_attached_handler_name()to retrieve the name ofthe
Quoted 1 line
Quoted 1 line
scsi_dhthat is attached to thescsi_deviceassociated with theprovided
Quoted 3 lines
Quoted 3 lines
request queue. Returns NULL if a
scsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to
document
Quoted 3 lines
Quoted 1 line
@q rather than @sdev.
Wha'ts the use case for this?
See this patch:
http://www.redhat.com/archives/dm-devel/2012-May/msg00046.html(I attributed this change to Hannes because it was based on his earlier patch... I should probably change that given that in the end I re-wrote/merged his patch with my earlier patch...)
Anyway, DM mpath doesn't want to know about the "
scsi_dh" structure, but
we need the name of the attached handler (to adjust the multipath device's 'hw_handler_name' and to get an additional ref on the attachedscsi_dhvia dm-mapth.c:parse_path'sscsi_dh_attach).BTW, only reason I split the
scsi_dhchange from the above dm-mpath patch is because I'm patching SCSI and DM and need to send the changes through different trees.Quoted 1 line
The name is stale as soon as the function returns.
Yeah, I have since wondered about that myself. In practice the attached
handler should remain attached so the name really won't be stale.But in theory there could be a race with
scsi_dh_detach. So I think the
following should address your concern?If so I'll refresh and repost the appropriate patches.
Thanks.
drivers/md/dm-mpath.c +0
-0@@ -592,10 +592,11 @@ static struct pgpath *parse_path(struct
dm_arg_set*as, structpath_selector*psdrivers/md/dm-mpath.c +0
-1q =bdev_get_queue (p->path.dev->bdev);if (m->use_default_hw_handler) { - const char *attached_handler_name =
scsi_dh_attached_handler_name(q);drivers/md/dm-mpath.c +2
-1+const char *attached_handler_name = +scsi_dh_attached_handler_name (q,GFP_KERNEL );if (attached_handler_name) {kfree (m->hw_handler_name); - m->hw_handler_name = kstrdup(attached_handler_name,
GFP_KERNEL);drivers/md/dm-mpath.c +1
-0+ m->hw_handler_name = attached_handler_name; } }drivers/scsi/device_handler/scsi_dh.c +1
-0@@ -533,10 +533,12 @@ EXPORT_SYMBOL_GPL(scsi_dh_detach);* scsi_dh_attached_handler_name - Get attached device handler's name * @q - Request queue that is associated with the scsi_device * that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory
*
* Returns name of attached handler, NULL if no handler is attached.
+ * Caller must take care to free the returned string.
*/drivers/scsi/device_handler/scsi_dh.c +1
-1-const char *scsi_dh_attached_handler_name (struct request_queue *q) +const char *scsi_dh_attached_handler_name(struct request_queue *q,
gfp_tgfp)
{drivers/scsi/device_handler/scsi_dh.c +1
-1unsigned long flags;struct scsi_device *sdev;@@ -552,7 +554,7 @@ const char *scsi_dh_attached_handler_name(struct request_queue *q)return NULL ;if (sdev->scsi_dh_data) - handler_name = sdev->scsi_dh_data->scsi_dh->name; + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp);drivers/scsi/device_handler/scsi_dh.c +0
-0put_device (&sdev->sdev_gendev);return handler_name;include/scsi/scsi_dh.h +1
-1@@ -60,7 +60,7 @@ extern int scsi_dh_activate(struct request_queue *, activate_complete, void *);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 *); -extern const char *scsi_dh_attached_handler_name (struct request_queue *q); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int
scsi_dh_set_params(struct request_queue *, const char *); #else
static inline int scsi_dh_activate(structrequest_queue*req,include/scsi/scsi_dh.h +2
-1@@ -81,7 +81,8 @@ static inline void scsi_dh_detach(struct request_queue *q) {return ; } -static inline const char *scsi_dh_attached_handler_name (struct request_queue *q) +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp){
return NULL;
}
PATCH v4 2/5 scsi_dh: add scsi_dh_attached_handler_name
In reply to Mike SnitzerIntroduce scsi_dh_attached_handler_name() to retrieve the name of the scsi_dh that is attached to the scsi_device associated with the provided request queue. Returns NULL if a scsi_dh is not attached.
Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
--- drivers/scsi/device_handler/scsi_dh.c | 38 ++++++++++++++++++++++++++++++++-- include/scsi/scsi_dh.h | 6 +++++ 2 files changed, 42 insertions(+), 2 deletions(-)
v4: fixed potential for returned string to be invalid (hch)
v3: fixed missing put_device that Babu pointed out
drivers/scsi/device_handler/scsi_dh.c +36 -2
@@ -468,7 +468,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_handler_exist)/* * scsi_dh_attach - Attach device handler -* @sdev - sdev the handler should be attached to +* @q - Request queue that is associated with the scsi_device +* the handler should be attached to * @name - name of the handler to attach */ int scsi_dh_attach (struct request_queue *q,const char *name)
@@ -498,7 +499,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);/* * scsi_dh_detach - Detach device handler -* @sdev - sdev the handler should be detached from +* @q - Request queue that is associated with the scsi_device +* the handler should be detached from * * This function will detach the device handler only * if the sdev is not part of the internal list, ie
@@ -527,6 +529,38 @@ void scsi_dh_detach(struct request_queue }EXPORT_SYMBOL_GPL (scsi_dh_detach); +/* +* scsi_dh_attached_handler_name - Get attached device handler's name +* @q - Request queue that is associated with the scsi_device +* that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory +* +* Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. +*/ +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) +{ +unsigned long flags; +struct scsi_device *sdev; +const char *handler_name =NULL ; + +spin_lock_irqsave (q->queue_lock, flags); + sdev = q->queuedata; +if (!sdev || !get_device (&sdev->sdev_gendev)) + sdev =NULL ; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (!sdev) +return NULL ; + +if (sdev->scsi_dh_data) + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp); + +put_device (&sdev->sdev_gendev); +return handler_name; +} +EXPORT_SYMBOL_GPL (scsi_dh_attached_handler_name); +static struct notifier_block scsi_dh_nb = { .notifier_call = scsi_dh_notifier };
include/scsi/scsi_dh.h +6 -0
@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct requeextern 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 *); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,
@@ -80,6 +81,11 @@ static inline void scsi_dh_detach(struct {return ; } +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp) +{ +return NULL ; +}static inline int scsi_dh_set_params (struct request_queue *req,const char *params) {return -SCSI_DH_NOSYS ;
Quoted 59 lines · Mike Snitzer
Introduce
scsi_dh_attached_handler_name()to retrieve the name of thescsi_dhthat is attached to thescsi_deviceassociated with the provided request queue. Returns NULL if ascsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
Signed-off-by Mike Snitzer <[email protected]>Tested-by Babu Moger <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Chandra Seetharaman <[email protected]>--- drivers/scsi/device_handler/scsi_dh.c | 38 ++++++++++++++++++++++++++++++++-- include/scsi/scsi_dh.h | 6 +++++ 2 files changed, 42 insertions(+), 2 deletions(-)v4: fixed potential for returned string to be invalid (hch)
v3: fixed missingput_devicethat Babu pointed outIndex:
linux-2.6/drivers/scsi/device_handler/scsi_dh.c
===================================================================drivers/scsi/device_handler/scsi_dh.c +16
-2@@ -468,7 +468,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_handler_exist)/* * scsi_dh_attach - Attach device handler -* @sdev - sdev the handler should be attached to +* @q - Request queue that is associated with the scsi_device +* the handler should be attached to * @name - name of the handler to attach */ int scsi_dh_attach (struct request_queue *q,const char *name)@@ -498,7 +499,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);/* * scsi_dh_detach - Detach device handler -* @sdev - sdev the handler should be detached from +* @q - Request queue that is associated with the scsi_device +* the handler should be detached from * * This function will detach the device handler only * if the sdev is not part of the internal list, ie @@ -527,6 +529,38 @@ void scsi_dh_detach(struct request_queue }EXPORT_SYMBOL_GPL (scsi_dh_detach); +/* +* scsi_dh_attached_handler_name - Get attached device handler's name +* @q - Request queue that is associated with the scsi_device +* that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory +* +* Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. +*/ +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) +{ +unsigned long flags;
drivers/scsi/device_handler/scsi_dh.c void scsi_dh_detach(struct request_queue · line 553
Quoted 10 lines
drivers/scsi/device_handler/scsi_dh.c +10
-0+struct scsi_device *sdev; +const char *handler_name =NULL ; + +spin_lock_irqsave (q->queue_lock, flags); + sdev = q->queuedata; +if (!sdev || !get_device (&sdev->sdev_gendev)) + sdev =NULL ; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (!sdev)
put_device() missing here.
Quoted 38 lines
drivers/scsi/device_handler/scsi_dh.c +10
-0+return NULL ; + +if (sdev->scsi_dh_data) + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp); + +put_device (&sdev->sdev_gendev); +return handler_name; +} +EXPORT_SYMBOL_GPL (scsi_dh_attached_handler_name); +static struct notifier_block scsi_dh_nb = { .notifier_call = scsi_dh_notifier };Index:
linux-2.6/include/scsi/scsi_dh.h
===================================================================include/scsi/scsi_dh.h +6
-0@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct requeextern 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 *); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,@@ -80,6 +81,11 @@ static inline void scsi_dh_detach(struct {return ; } +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp) +{ +return NULL ; +}static inline int scsi_dh_set_params (struct request_queue *req,const char *params) {return -SCSI_DH_NOSYS ;
Quoted 16 lines · Chandra Seetharaman
Quoted 16 lines
drivers/scsi/device_handler/scsi_dh.c +16
-0+/* +* scsi_dh_attached_handler_name - Get attached device handler's name +* @q - Request queue that is associated with the scsi_device +* that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory +* +* Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. +*/ +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) +{ +unsigned long flags; +struct scsi_device *sdev; +const char *handler_name =NULL ; + +spin_lock_irqsave (q->queue_lock, flags);
Quoted 8 lines
drivers/scsi/device_handler/scsi_dh.c void scsi_dh_detach(struct request_queue · line 553
Quoted 6 lines
drivers/scsi/device_handler/scsi_dh.c +6
-0+ sdev = q->queuedata; +if (!sdev || !get_device (&sdev->sdev_gendev)) + sdev =NULL ; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (!sdev)
put_device()missing here.
Not that I can see. If sdev is NULL then get_device never succeeded.
(same pattern is used in scsi_dh_detach)
Quoted 40 lines
Quoted 38 lines
drivers/scsi/device_handler/scsi_dh.c +10
-0+return NULL ; + +if (sdev->scsi_dh_data) + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp); + +put_device (&sdev->sdev_gendev); +return handler_name; +} +EXPORT_SYMBOL_GPL (scsi_dh_attached_handler_name); +static struct notifier_block scsi_dh_nb = { .notifier_call = scsi_dh_notifier };Index:
linux-2.6/include/scsi/scsi_dh.h
===================================================================include/scsi/scsi_dh.h +6
-0@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct requeextern 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 *); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,@@ -80,6 +81,11 @@ static inline void scsi_dh_detach(struct {return ; } +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp) +{ +return NULL ; +}static inline int scsi_dh_set_params (struct request_queue *req,const char *params) {return -SCSI_DH_NOSYS ;
Quoted 28 lines · Mike Snitzer
Quoted 16 lines · Chandra Seetharaman
Quoted 16 lines
drivers/scsi/device_handler/scsi_dh.c +16
-0+/* +* scsi_dh_attached_handler_name - Get attached device handler's name +* @q - Request queue that is associated with the scsi_device +* that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory +* +* Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. +*/ +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) +{ +unsigned long flags; +struct scsi_device *sdev; +const char *handler_name =NULL ; + +spin_lock_irqsave (q->queue_lock, flags);Quoted 8 lines
drivers/scsi/device_handler/scsi_dh.c void scsi_dh_detach(struct request_queue · line 553
Quoted 6 lines
drivers/scsi/device_handler/scsi_dh.c +6
-0+ sdev = q->queuedata; +if (!sdev || !get_device (&sdev->sdev_gendev)) + sdev =NULL ; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (!sdev)
put_device()missing here.
Quoted 3 lines
Not that I can see. If sdev is NULL then
get_devicenever succeeded.(same pattern is used in
scsi_dh_detach)
yup.. overlooked. will send a reviewed-by to the original email
Quoted 46 lines
Quoted 31 lines
Quoted 31 lines
drivers/scsi/device_handler/scsi_dh.c +10
-0+return NULL ; + +if (sdev->scsi_dh_data) + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp); + +put_device (&sdev->sdev_gendev); +return handler_name; +} +EXPORT_SYMBOL_GPL (scsi_dh_attached_handler_name); +static struct notifier_block scsi_dh_nb = { .notifier_call = scsi_dh_notifier };Index:
linux-2.6/include/scsi/scsi_dh.h
===================================================================include/scsi/scsi_dh.h +2
-0@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct requeextern 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 *); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,@@ -80,6 +81,11 @@ static inline void scsi_dh_detach(struct {return ; } +static inline const char *scsi_dh_attached_handler_name(struct request_queue *q,Quoted 10 lines
include/scsi/scsi_dh.h static inline void scsi_dh_detach(struct · line 91
Quoted 8 lines
include/scsi/scsi_dh.h +4
-0+ gfp_t gfp) +{ +return NULL ; +}static inline int scsi_dh_set_params (struct request_queue *req,const char *params) {return -SCSI_DH_NOSYS ;--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 107 lines · Mike Snitzer
Introduce
scsi_dh_attached_handler_name()to retrieve the name of thescsi_dhthat is attached to thescsi_deviceassociated with the provided request queue. Returns NULL if ascsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
Signed-off-by Mike Snitzer <[email protected]>Tested-by Babu Moger <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Chandra Seetharaman <[email protected]>--- drivers/scsi/device_handler/scsi_dh.c | 38 ++++++++++++++++++++++++++++++++-- include/scsi/scsi_dh.h | 6 +++++ 2 files changed, 42 insertions(+), 2 deletions(-)v4: fixed potential for returned string to be invalid (hch)
v3: fixed missingput_devicethat Babu pointed outIndex:
linux-2.6/drivers/scsi/device_handler/scsi_dh.c
===================================================================drivers/scsi/device_handler/scsi_dh.c +36
-2@@ -468,7 +468,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_handler_exist)/* * scsi_dh_attach - Attach device handler -* @sdev - sdev the handler should be attached to +* @q - Request queue that is associated with the scsi_device +* the handler should be attached to * @name - name of the handler to attach */ int scsi_dh_attach (struct request_queue *q,const char *name)@@ -498,7 +499,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);/* * scsi_dh_detach - Detach device handler -* @sdev - sdev the handler should be detached from +* @q - Request queue that is associated with the scsi_device +* the handler should be detached from * * This function will detach the device handler only * if the sdev is not part of the internal list, ie @@ -527,6 +529,38 @@ void scsi_dh_detach(struct request_queue }EXPORT_SYMBOL_GPL (scsi_dh_detach); +/* +* scsi_dh_attached_handler_name - Get attached device handler's name +* @q - Request queue that is associated with the scsi_device +* that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory +* +* Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. +*/ +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) +{ +unsigned long flags; +struct scsi_device *sdev; +const char *handler_name =NULL ; + +spin_lock_irqsave (q->queue_lock, flags); + sdev = q->queuedata; +if (!sdev || !get_device (&sdev->sdev_gendev)) + sdev =NULL ; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (!sdev) +return NULL ; + +if (sdev->scsi_dh_data) + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp); + +put_device (&sdev->sdev_gendev); +return handler_name; +} +EXPORT_SYMBOL_GPL (scsi_dh_attached_handler_name); +static struct notifier_block scsi_dh_nb = { .notifier_call = scsi_dh_notifier };Index:
linux-2.6/include/scsi/scsi_dh.h
===================================================================include/scsi/scsi_dh.h +6
-0@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct requeextern 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 *); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,@@ -80,6 +81,11 @@ static inline void scsi_dh_detach(struct {return ; } +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp) +{ +return NULL ; +}static inline int scsi_dh_set_params (struct request_queue *req,const char *params) {return -SCSI_DH_NOSYS ;
Hi James,
Could you please stage this scsi_dh patch for the 3.5 merge? The other DM mpath patches in the patchset will go through Alasdair's DM tree.
Thanks,
Mike
Quoted 112 lines · Chandra Seetharaman
Reviewed-by Chandra Seetharaman <[email protected]>Quoted 107 lines · Mike Snitzer
Introduce
scsi_dh_attached_handler_name()to retrieve the name of thescsi_dhthat is attached to thescsi_deviceassociated with the provided request queue. Returns NULL if ascsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
Signed-off-by Mike Snitzer <[email protected]>Tested-by Babu Moger <[email protected]>Cc Hannes Reinecke <[email protected]>Cc Chandra Seetharaman <[email protected]>--- drivers/scsi/device_handler/scsi_dh.c | 38 ++++++++++++++++++++++++++++++++-- include/scsi/scsi_dh.h | 6 +++++ 2 files changed, 42 insertions(+), 2 deletions(-)v4: fixed potential for returned string to be invalid (hch)
v3: fixed missingput_devicethat Babu pointed outIndex:
linux-2.6/drivers/scsi/device_handler/scsi_dh.c
===================================================================drivers/scsi/device_handler/scsi_dh.c +36
-2@@ -468,7 +468,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_handler_exist)/* * scsi_dh_attach - Attach device handler -* @sdev - sdev the handler should be attached to +* @q - Request queue that is associated with the scsi_device +* the handler should be attached to * @name - name of the handler to attach */ int scsi_dh_attach (struct request_queue *q,const char *name)@@ -498,7 +499,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);/* * scsi_dh_detach - Detach device handler -* @sdev - sdev the handler should be detached from +* @q - Request queue that is associated with the scsi_device +* the handler should be detached from * * This function will detach the device handler only * if the sdev is not part of the internal list, ie @@ -527,6 +529,38 @@ void scsi_dh_detach(struct request_queue }EXPORT_SYMBOL_GPL (scsi_dh_detach); +/* +* scsi_dh_attached_handler_name - Get attached device handler's name +* @q - Request queue that is associated with the scsi_device +* that may have a device handler attached +* @gfp - the GFP mask used in the kmalloc() call when allocating memory +* +* Returns name of attached handler, NULL if no handler is attached. +* Caller must take care to free the returned string. +*/ +const char *scsi_dh_attached_handler_name (struct request_queue *q,gfp_t gfp) +{ +unsigned long flags; +struct scsi_device *sdev; +const char *handler_name =NULL ; + +spin_lock_irqsave (q->queue_lock, flags); + sdev = q->queuedata; +if (!sdev || !get_device (&sdev->sdev_gendev)) + sdev =NULL ; +spin_unlock_irqrestore (q->queue_lock, flags); + +if (!sdev) +return NULL ; + +if (sdev->scsi_dh_data) + handler_name =kstrdup (sdev->scsi_dh_data->scsi_dh->name, gfp); + +put_device (&sdev->sdev_gendev); +return handler_name; +} +EXPORT_SYMBOL_GPL (scsi_dh_attached_handler_name); +static struct notifier_block scsi_dh_nb = { .notifier_call = scsi_dh_notifier };Index:
linux-2.6/include/scsi/scsi_dh.h
===================================================================include/scsi/scsi_dh.h +6
-0@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct requeextern 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 *); +extern const char *scsi_dh_attached_handler_name (struct request_queue *,gfp_t );extern int scsi_dh_set_params (struct request_queue *,const char *);#else static inline int scsi_dh_activate(struct request_queue *req,@@ -80,6 +81,11 @@ static inline void scsi_dh_detach(struct {return ; } +static inline const char *scsi_dh_attached_handler_name (struct request_queue *q, +gfp_t gfp) +{ +return NULL ; +}static inline int scsi_dh_set_params (struct request_queue *req,const char *params) {return -SCSI_DH_NOSYS ;
Quoted 10 lines · Mike Snitzer
Introduce
scsi_dh_attached_handler_name()to retrieve the name of thescsi_dhthat is attached to thescsi_deviceassociated with the provided request queue. Returns NULL if ascsi_dhis not attached.Also, fix scsi_dh_{attach,detach} function header comments to document @q rather than @sdev.
Signed-off-by Mike Snitzer <[email protected]>Tested-by Babu Moger <[email protected]>Cc Hannes Reinecke <[email protected]>
Cheers,
Hannes
Signature · 8 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) -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html