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; 14+ 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] 14+ messages in thread
[parent not found: <1336514167-15393-1-git-send-email-snitzer@redhat.com>]

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

Thread overview: 14+ 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
     [not found] <1336514167-15393-1-git-send-email-snitzer@redhat.com>
     [not found] ` <1336514167-15393-3-git-send-email-snitzer@redhat.com>
     [not found]   ` <77471C95FAFD844C8CA02DD4F4C5FE2B05D284@SACEXCMBX02-PRD.hq.netapp.com>
2012-05-09 20:41     ` [PATCH v3 " Mike Snitzer
     [not found]     ` <20120509204101.GB26785@redhat.com>
2012-05-09 22:54       ` Chandra Seetharaman

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