linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
@ 2012-05-10  1:12 Mike Snitzer
  2012-05-10  6:55 ` Christoph Hellwig
  2012-05-10 21:31 ` [PATCH v4 " Mike Snitzer
  0 siblings, 2 replies; 12+ messages in thread
From: Mike Snitzer @ 2012-05-10  1:12 UTC (permalink / raw)
  To: linux-scsi; +Cc: agk, hare, babu.moger, sekharan, 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 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.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Reviewed-by: Chandra Seetharaman <sekharan@us.ibm.com>
---
 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

Index: linux-2.6/drivers/scsi/device_handler/scsi_dh.c
===================================================================
--- linux-2.6.orig/drivers/scsi/device_handler/scsi_dh.c
+++ linux-2.6/drivers/scsi/device_handler/scsi_dh.c
@@ -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
 };
Index: linux-2.6/include/scsi/scsi_dh.h
===================================================================
--- linux-2.6.orig/include/scsi/scsi_dh.h
+++ linux-2.6/include/scsi/scsi_dh.h
@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct reque
 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 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;

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10  1:12 [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name Mike Snitzer
@ 2012-05-10  6:55 ` Christoph Hellwig
  2012-05-10 14:10   ` Mike Snitzer
  2012-05-10 21:31 ` [PATCH v4 " Mike Snitzer
  1 sibling, 1 reply; 12+ messages in thread
From: Christoph Hellwig @ 2012-05-10  6:55 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: linux-scsi, agk, hare, babu.moger, sekharan

On Wed, May 09, 2012 at 09:12:46PM -0400, Mike Snitzer wrote:
> 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.

Wha'ts the use case for this?  The name is stale as soon as the function
returns.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10  6:55 ` Christoph Hellwig
@ 2012-05-10 14:10   ` Mike Snitzer
  2012-05-10 18:14     ` Moger, Babu
  2012-05-10 20:26     ` Moger, Babu
  0 siblings, 2 replies; 12+ messages in thread
From: Mike Snitzer @ 2012-05-10 14:10 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linux-scsi, agk, hare, babu.moger, sekharan

On Thu, May 10 2012 at  2:55am -0400,
Christoph Hellwig <hch@infradead.org> wrote:

> On Wed, May 09, 2012 at 09:12:46PM -0400, Mike Snitzer wrote:
> > 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.
> 
> 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.

> 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.

diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 1039e7f..6f11956 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -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;
 		}
 	}
 
diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index 83071e4..33e422e 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -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;
diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
index 94f502b..620c723 100644
--- a/include/scsi/scsi_dh.h
+++ b/include/scsi/scsi_dh.h
@@ -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;
 }




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* RE: [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10 14:10   ` Mike Snitzer
@ 2012-05-10 18:14     ` Moger, Babu
  2012-05-10 20:26     ` Moger, Babu
  1 sibling, 0 replies; 12+ messages in thread
From: Moger, Babu @ 2012-05-10 18:14 UTC (permalink / raw)
  To: Mike Snitzer, Christoph Hellwig
  Cc: linux-scsi@vger.kernel.org, agk@redhat.com, hare@suse.de,
	sekharan@us.ibm.com,
	device-mapper development (dm-devel@redhat.com)

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


> -----Original Message-----
> From: Mike Snitzer [mailto:snitzer@redhat.com]
> Sent: Thursday, May 10, 2012 9:11 AM
> To: Christoph Hellwig
> Cc: linux-scsi@vger.kernel.org; agk@redhat.com; hare@suse.de; Moger,
> Babu; sekharan@us.ibm.com
> Subject: Re: [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
> 
> On Thu, May 10 2012 at  2:55am -0400,
> Christoph Hellwig <hch@infradead.org> wrote:
> 
> > On Wed, May 09, 2012 at 09:12:46PM -0400, Mike Snitzer wrote:
> > > 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.
> >
> > 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.
> 
> > 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.
> 
> diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
> index 1039e7f..6f11956 100644
> --- a/drivers/md/dm-mpath.c
> +++ b/drivers/md/dm-mpath.c
> @@ -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;
>  		}
>  	}
> 
> diff --git a/drivers/scsi/device_handler/scsi_dh.c
> b/drivers/scsi/device_handler/scsi_dh.c
> index 83071e4..33e422e 100644
> --- a/drivers/scsi/device_handler/scsi_dh.c
> +++ b/drivers/scsi/device_handler/scsi_dh.c
> @@ -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;
> diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
> index 94f502b..620c723 100644
> --- a/include/scsi/scsi_dh.h
> +++ b/include/scsi/scsi_dh.h
> @@ -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;
>  }
> 
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10 14:10   ` Mike Snitzer
  2012-05-10 18:14     ` Moger, Babu
@ 2012-05-10 20:26     ` Moger, Babu
  1 sibling, 0 replies; 12+ messages in thread
From: Moger, Babu @ 2012-05-10 20:26 UTC (permalink / raw)
  To: Mike Snitzer, Christoph Hellwig
  Cc: linux-scsi@vger.kernel.org, agk@redhat.com, hare@suse.de,
	sekharan@us.ibm.com

Mike, Yes, I have retested using this patch. Everything looks good. 

> -----Original Message-----
> From: Mike Snitzer [mailto:snitzer@redhat.com]
> Sent: Thursday, May 10, 2012 9:11 AM
> To: Christoph Hellwig
> Cc: linux-scsi@vger.kernel.org; agk@redhat.com; hare@suse.de; Moger,
> Babu; sekharan@us.ibm.com
> Subject: Re: [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
> 
> On Thu, May 10 2012 at  2:55am -0400,
> Christoph Hellwig <hch@infradead.org> wrote:
> 
> > On Wed, May 09, 2012 at 09:12:46PM -0400, Mike Snitzer wrote:
> > > 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.
> >
> > 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.
> 
> > 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.
> 
> diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
> index 1039e7f..6f11956 100644
> --- a/drivers/md/dm-mpath.c
> +++ b/drivers/md/dm-mpath.c
> @@ -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;
>  		}
>  	}
> 
> diff --git a/drivers/scsi/device_handler/scsi_dh.c
> b/drivers/scsi/device_handler/scsi_dh.c
> index 83071e4..33e422e 100644
> --- a/drivers/scsi/device_handler/scsi_dh.c
> +++ b/drivers/scsi/device_handler/scsi_dh.c
> @@ -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;
> diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
> index 94f502b..620c723 100644
> --- a/include/scsi/scsi_dh.h
> +++ b/include/scsi/scsi_dh.h
> @@ -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;
>  }
> 
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v4 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10  1:12 [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name Mike Snitzer
  2012-05-10  6:55 ` Christoph Hellwig
@ 2012-05-10 21:31 ` Mike Snitzer
  2012-05-17 21:12   ` Chandra Seetharaman
                     ` (2 more replies)
  1 sibling, 3 replies; 12+ messages in thread
From: Mike Snitzer @ 2012-05-10 21:31 UTC (permalink / raw)
  To: linux-scsi; +Cc: agk, hare, babu.moger, sekharan, dm-devel

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.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Tested-by: Babu Moger <babu.moger@netapp.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Chandra Seetharaman <sekharan@us.ibm.com>
---
 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

Index: linux-2.6/drivers/scsi/device_handler/scsi_dh.c
===================================================================
--- linux-2.6.orig/drivers/scsi/device_handler/scsi_dh.c
+++ linux-2.6/drivers/scsi/device_handler/scsi_dh.c
@@ -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
===================================================================
--- linux-2.6.orig/include/scsi/scsi_dh.h
+++ linux-2.6/include/scsi/scsi_dh.h
@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct reque
 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 *, 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;

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10 21:31 ` [PATCH v4 " Mike Snitzer
@ 2012-05-17 21:12   ` Chandra Seetharaman
  2012-05-17 21:23     ` Mike Snitzer
  2012-05-17 22:58   ` Chandra Seetharaman
  2012-06-08 15:03   ` Hannes Reinecke
  2 siblings, 1 reply; 12+ messages in thread
From: Chandra Seetharaman @ 2012-05-17 21:12 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: linux-scsi, agk, hare, babu.moger, dm-devel

On Thu, 2012-05-10 at 17:31 -0400, Mike Snitzer wrote:
> 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.
> 
> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
> Tested-by: Babu Moger <babu.moger@netapp.com>
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: Chandra Seetharaman <sekharan@us.ibm.com>
> ---
>  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
> 
> Index: linux-2.6/drivers/scsi/device_handler/scsi_dh.c
> ===================================================================
> --- linux-2.6.orig/drivers/scsi/device_handler/scsi_dh.c
> +++ linux-2.6/drivers/scsi/device_handler/scsi_dh.c
> @@ -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)

put_device() missing here.

> +		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
> ===================================================================
> --- linux-2.6.orig/include/scsi/scsi_dh.h
> +++ linux-2.6/include/scsi/scsi_dh.h
> @@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct reque
>  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 *, 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;
> 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-17 21:12   ` Chandra Seetharaman
@ 2012-05-17 21:23     ` Mike Snitzer
  2012-05-17 22:57       ` Chandra Seetharaman
  0 siblings, 1 reply; 12+ messages in thread
From: Mike Snitzer @ 2012-05-17 21:23 UTC (permalink / raw)
  To: Chandra Seetharaman; +Cc: linux-scsi, agk, hare, babu.moger, dm-devel

On Thu, May 17 2012 at  5:12pm -0400,
Chandra Seetharaman <sekharan@us.ibm.com> wrote:

> > +/*
> > + * 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)
> 
> 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)

> > +		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
> > ===================================================================
> > --- linux-2.6.orig/include/scsi/scsi_dh.h
> > +++ linux-2.6/include/scsi/scsi_dh.h
> > @@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct reque
> >  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 *, 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;
> > 
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-17 21:23     ` Mike Snitzer
@ 2012-05-17 22:57       ` Chandra Seetharaman
  0 siblings, 0 replies; 12+ messages in thread
From: Chandra Seetharaman @ 2012-05-17 22:57 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: linux-scsi, agk, hare, babu.moger, dm-devel

On Thu, 2012-05-17 at 17:23 -0400, Mike Snitzer wrote:
> On Thu, May 17 2012 at  5:12pm -0400,
> Chandra Seetharaman <sekharan@us.ibm.com> wrote:
> 
> > > +/*
> > > + * 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)
> > 
> > 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)

yup.. overlooked. will send a reviewed-by to the original email
> 
> > > +		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
> > > ===================================================================
> > > --- linux-2.6.orig/include/scsi/scsi_dh.h
> > > +++ linux-2.6/include/scsi/scsi_dh.h
> > > @@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct reque
> > >  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 *, 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;
> > > 
> > 
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10 21:31 ` [PATCH v4 " Mike Snitzer
  2012-05-17 21:12   ` Chandra Seetharaman
@ 2012-05-17 22:58   ` Chandra Seetharaman
  2012-05-21 18:45     ` Mike Snitzer
  2012-06-08 15:03   ` Hannes Reinecke
  2 siblings, 1 reply; 12+ messages in thread
From: Chandra Seetharaman @ 2012-05-17 22:58 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: linux-scsi, agk, hare, babu.moger, dm-devel

Reviewed-by: Chandra Seetharaman <sekharan@us.ibm.com>

On Thu, 2012-05-10 at 17:31 -0400, Mike Snitzer wrote:
> 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.
> 
> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
> Tested-by: Babu Moger <babu.moger@netapp.com>
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: Chandra Seetharaman <sekharan@us.ibm.com>
> ---
>  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
> 
> Index: linux-2.6/drivers/scsi/device_handler/scsi_dh.c
> ===================================================================
> --- linux-2.6.orig/drivers/scsi/device_handler/scsi_dh.c
> +++ linux-2.6/drivers/scsi/device_handler/scsi_dh.c
> @@ -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
> ===================================================================
> --- linux-2.6.orig/include/scsi/scsi_dh.h
> +++ linux-2.6/include/scsi/scsi_dh.h
> @@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct reque
>  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 *, 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;
> 



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-17 22:58   ` Chandra Seetharaman
@ 2012-05-21 18:45     ` Mike Snitzer
  0 siblings, 0 replies; 12+ messages in thread
From: Mike Snitzer @ 2012-05-21 18:45 UTC (permalink / raw)
  To: James.Bottomley
  Cc: linux-scsi, agk, hare, babu.moger, dm-devel, Chandra Seetharaman

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

On Thu, May 17 2012 at  6:58pm -0400,
Chandra Seetharaman <sekharan@us.ibm.com> wrote:

> Reviewed-by: Chandra Seetharaman <sekharan@us.ibm.com>
> 
> On Thu, 2012-05-10 at 17:31 -0400, Mike Snitzer wrote:
> > 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.
> > 
> > Signed-off-by: Mike Snitzer <snitzer@redhat.com>
> > Tested-by: Babu Moger <babu.moger@netapp.com>
> > Cc: Hannes Reinecke <hare@suse.de>
> > Cc: Chandra Seetharaman <sekharan@us.ibm.com>
> > ---
> >  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
> > 
> > Index: linux-2.6/drivers/scsi/device_handler/scsi_dh.c
> > ===================================================================
> > --- linux-2.6.orig/drivers/scsi/device_handler/scsi_dh.c
> > +++ linux-2.6/drivers/scsi/device_handler/scsi_dh.c
> > @@ -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
> > ===================================================================
> > --- linux-2.6.orig/include/scsi/scsi_dh.h
> > +++ linux-2.6/include/scsi/scsi_dh.h
> > @@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct reque
> >  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 *, 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;
> > 
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v4 2/5] scsi_dh: add scsi_dh_attached_handler_name
  2012-05-10 21:31 ` [PATCH v4 " Mike Snitzer
  2012-05-17 21:12   ` Chandra Seetharaman
  2012-05-17 22:58   ` Chandra Seetharaman
@ 2012-06-08 15:03   ` Hannes Reinecke
  2 siblings, 0 replies; 12+ messages in thread
From: Hannes Reinecke @ 2012-06-08 15:03 UTC (permalink / raw)
  To: Mike Snitzer; +Cc: linux-scsi, agk, babu.moger, sekharan, dm-devel

On 05/10/2012 11:31 PM, Mike Snitzer wrote:
> 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.
> 
> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
> Tested-by: Babu Moger <babu.moger@netapp.com>
> Cc: Hannes Reinecke <hare@suse.de>

Acked-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-06-08 15:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-10  1:12 [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name Mike Snitzer
2012-05-10  6:55 ` Christoph Hellwig
2012-05-10 14:10   ` Mike Snitzer
2012-05-10 18:14     ` Moger, Babu
2012-05-10 20:26     ` Moger, Babu
2012-05-10 21:31 ` [PATCH v4 " Mike Snitzer
2012-05-17 21:12   ` Chandra Seetharaman
2012-05-17 21:23     ` Mike Snitzer
2012-05-17 22:57       ` Chandra Seetharaman
2012-05-17 22:58   ` Chandra Seetharaman
2012-05-21 18:45     ` Mike Snitzer
2012-06-08 15:03   ` Hannes Reinecke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).