On 05/08/2012 11:56 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>
> ---
> drivers/scsi/device_handler/scsi_dh.c | 31 +++++++++++++++++++++++++++++--
> include/scsi/scsi_dh.h | 5 +++++
> 2 files changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
> index 48e46f5..7497c78 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);
>
> /*
> * 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,31 @@ void scsi_dh_detach(struct request_queue *q)
> }
> 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 scsi_dh, NULL if no handler is attached.
> + */
> +const char *scsi_dh_attached_handler_name(struct request_queue *q)
> +{
> + unsigned long flags;
> + struct scsi_device *sdev;
> +
> + 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 || !sdev->scsi_dh_data)
> + return NULL;
> +
> + return sdev->scsi_dh_data->scsi_dh->name;
> +}
> +EXPORT_SYMBOL_GPL(scsi_dh_attached_handler_name);
> +
> static struct notifier_block scsi_dh_nb = {
> .notifier_call = scsi_dh_notifier
> };
> diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
> index e3f2db2..94f502b 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 *);
> 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 request_queue *q)
> {
> 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;
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)
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
05-09-2012, 05:40 PM
"Moger, Babu"
scsi_dh: add scsi_dh_attached_handler_name
Mike, I have a question for you below.
> -----Original Message-----
> From: Mike Snitzer [mailto:snitzer@redhat.com]
> Sent: Tuesday, May 08, 2012 4:56 PM
> To: dm-devel@redhat.com
> Cc: agk@redhat.com; hare@suse.de; Moger, Babu; sekharan@us.ibm.com;
> Mike Snitzer
> Subject: [PATCH v2 2/5] 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>
> ---
> drivers/scsi/device_handler/scsi_dh.c | 31
> +++++++++++++++++++++++++++++--
> include/scsi/scsi_dh.h | 5 +++++
> 2 files changed, 34 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/device_handler/scsi_dh.c
> b/drivers/scsi/device_handler/scsi_dh.c
> index 48e46f5..7497c78 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);
>
> /*
> * 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,31 @@ void scsi_dh_detach(struct request_queue *q)
> }
> 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 scsi_dh, NULL if no handler is attached.
> + */
> +const char *scsi_dh_attached_handler_name(struct request_queue *q)
> +{
> + unsigned long flags;
> + struct scsi_device *sdev;
> +
> + 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 || !sdev->scsi_dh_data)
> + return NULL;
> +
> + return sdev->scsi_dh_data->scsi_dh->name;
> +}
I only see get_device call. I don't see matching put_device call. Was that on purspose?
Mike, you may have to cross post to linux-scsi for James to pick it up.
On Wed, 2012-05-09 at 16:41 -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>
> ---
> 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;
>
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
05-10-2012, 06:14 PM
"Moger, Babu"
scsi_dh: add scsi_dh_attached_handler_name
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.
> -----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.carse_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;
> }
>
>
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
05-17-2012, 09:12 PM
Chandra Seetharaman
scsi_dh: add scsi_dh_attached_handler_name
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)
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;
>
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
05-21-2012, 06:45 PM
Mike Snitzer
scsi_dh: add scsi_dh_attached_handler_name
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;
> >
>
>
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
06-26-2012, 06:32 PM
Mike Snitzer
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.
/*
* 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 *q)
}
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
};
diff --git a/include/scsi/scsi_dh.h b/include/scsi/scsi_dh.h
index e3f2db2..620c723 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 *);
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 request_queue *q)
{
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;
--
1.7.4.4
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel