All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@redhat.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: linux-scsi@vger.kernel.org, agk@redhat.com, hare@suse.de,
	babu.moger@netapp.com, sekharan@us.ibm.com
Subject: Re: [PATCH v3 2/5] scsi_dh: add scsi_dh_attached_handler_name
Date: Thu, 10 May 2012 10:10:58 -0400	[thread overview]
Message-ID: <20120510141057.GA1983@redhat.com> (raw)
In-Reply-To: <20120510065548.GA5728@infradead.org>

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;
 }




  reply	other threads:[~2012-05-10 14:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2012-05-08 21:56 [PATCH v2 0/5] dm mpath: add 'default_hw_handler' and 'no_partitions' features Mike Snitzer
2012-05-08 21:56 ` [PATCH v2 2/5] scsi_dh: add scsi_dh_attached_handler_name Mike Snitzer
2012-05-09 17:40   ` Moger, Babu
2012-05-09 20:41     ` [PATCH v3 " Mike Snitzer
2012-05-09 20:41     ` Mike Snitzer
2012-05-09 22:54       ` Chandra Seetharaman
2012-05-09 22:54       ` Chandra Seetharaman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120510141057.GA1983@redhat.com \
    --to=snitzer@redhat.com \
    --cc=agk@redhat.com \
    --cc=babu.moger@netapp.com \
    --cc=hare@suse.de \
    --cc=hch@infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=sekharan@us.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.