aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Snitzer <snitzer@redhat.com>2012-06-26 14:32:03 -0400
committerJames Bottomley <JBottomley@Parallels.com>2012-07-20 03:58:42 -0400
commit7e8a74b177f17d100916b6ad415450f7c9508691 (patch)
tree3a2ed38f030ef3e79d3c332c594dbad89d7642bf
parent6aca4112f67b67d0a2f60326a1331a4125564ca7 (diff)
[SCSI] scsi_dh: add scsi_dh_attached_handler_name
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> Reviewed-by: Chandra Seetharaman <sekharan@us.ibm.com> Acked-by: Hannes Reinecke <hare@suse.de> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r--drivers/scsi/device_handler/scsi_dh.c38
-rw-r--r--include/scsi/scsi_dh.h6
2 files changed, 42 insertions, 2 deletions
diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index 48e46f5b77cc..33e422e75835 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -468,7 +468,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_handler_exist);
468 468
469/* 469/*
470 * scsi_dh_attach - Attach device handler 470 * scsi_dh_attach - Attach device handler
471 * @sdev - sdev the handler should be attached to 471 * @q - Request queue that is associated with the scsi_device
472 * the handler should be attached to
472 * @name - name of the handler to attach 473 * @name - name of the handler to attach
473 */ 474 */
474int scsi_dh_attach(struct request_queue *q, const char *name) 475int scsi_dh_attach(struct request_queue *q, const char *name)
@@ -498,7 +499,8 @@ EXPORT_SYMBOL_GPL(scsi_dh_attach);
498 499
499/* 500/*
500 * scsi_dh_detach - Detach device handler 501 * scsi_dh_detach - Detach device handler
501 * @sdev - sdev the handler should be detached from 502 * @q - Request queue that is associated with the scsi_device
503 * the handler should be detached from
502 * 504 *
503 * This function will detach the device handler only 505 * This function will detach the device handler only
504 * if the sdev is not part of the internal list, ie 506 * if the sdev is not part of the internal list, ie
@@ -527,6 +529,38 @@ void scsi_dh_detach(struct request_queue *q)
527} 529}
528EXPORT_SYMBOL_GPL(scsi_dh_detach); 530EXPORT_SYMBOL_GPL(scsi_dh_detach);
529 531
532/*
533 * scsi_dh_attached_handler_name - Get attached device handler's name
534 * @q - Request queue that is associated with the scsi_device
535 * that may have a device handler attached
536 * @gfp - the GFP mask used in the kmalloc() call when allocating memory
537 *
538 * Returns name of attached handler, NULL if no handler is attached.
539 * Caller must take care to free the returned string.
540 */
541const char *scsi_dh_attached_handler_name(struct request_queue *q, gfp_t gfp)
542{
543 unsigned long flags;
544 struct scsi_device *sdev;
545 const char *handler_name = NULL;
546
547 spin_lock_irqsave(q->queue_lock, flags);
548 sdev = q->queuedata;
549 if (!sdev || !get_device(&sdev->sdev_gendev))
550 sdev = NULL;
551 spin_unlock_irqrestore(q->queue_lock, flags);
552
553 if (!sdev)
554 return NULL;
555
556 if (sdev->scsi_dh_data)
557 handler_name = kstrdup(sdev->scsi_dh_data->scsi_dh->name, gfp);
558
559 put_device(&sdev->sdev_gendev);
560 return handler_name;
561}
562EXPORT_SYMBOL_GPL(scsi_dh_attached_handler_name);
563
530static struct notifier_block scsi_dh_nb = { 564static struct notifier_block scsi_dh_nb = {
531 .notifier_call = scsi_dh_notifier 565 .notifier_call = scsi_dh_notifier
532}; 566};
diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
index e3f2db212ddc..620c723ee8ed 100644
--- a/include/scsi/scsi_dh.h
+++ b/include/scsi/scsi_dh.h
@@ -60,6 +60,7 @@ extern int scsi_dh_activate(struct request_queue *, activate_complete, void *);
60extern int scsi_dh_handler_exist(const char *); 60extern int scsi_dh_handler_exist(const char *);
61extern int scsi_dh_attach(struct request_queue *, const char *); 61extern int scsi_dh_attach(struct request_queue *, const char *);
62extern void scsi_dh_detach(struct request_queue *); 62extern void scsi_dh_detach(struct request_queue *);
63extern const char *scsi_dh_attached_handler_name(struct request_queue *, gfp_t);
63extern int scsi_dh_set_params(struct request_queue *, const char *); 64extern int scsi_dh_set_params(struct request_queue *, const char *);
64#else 65#else
65static inline int scsi_dh_activate(struct request_queue *req, 66static inline int scsi_dh_activate(struct request_queue *req,
@@ -80,6 +81,11 @@ static inline void scsi_dh_detach(struct request_queue *q)
80{ 81{
81 return; 82 return;
82} 83}
84static inline const char *scsi_dh_attached_handler_name(struct request_queue *q,
85 gfp_t gfp)
86{
87 return NULL;
88}
83static inline int scsi_dh_set_params(struct request_queue *req, const char *params) 89static inline int scsi_dh_set_params(struct request_queue *req, const char *params)
84{ 90{
85 return -SCSI_DH_NOSYS; 91 return -SCSI_DH_NOSYS;