From: Chris Leech <cleech@redhat.com>
To: Mike Christie <michael.christie@oracle.com>
Cc: skashyap@marvell.com, lduncan@suse.com, njavali@marvell.com,
mrangankar@marvell.com, GR-QLogic-Storage-Upstream@marvell.com,
martin.petersen@oracle.com, linux-scsi@vger.kernel.org,
jejb@linux.ibm.com
Subject: Re: [PATCH 03/10] scsi: iscsi: Release endpoint ID when its freed.
Date: Fri, 8 Apr 2022 18:40:23 -0700 [thread overview]
Message-ID: <YlDkB4+O77xyxUj6@localhost> (raw)
In-Reply-To: <20220408001314.5014-4-michael.christie@oracle.com>
On Thu, Apr 07, 2022 at 07:13:07PM -0500, Mike Christie wrote:
> We can't release the endpoint ID until all references to the endpoint have
> been dropped or it could be allocated while in use. This has us use an idr
> instead of looping over all conns to find a free ID and then free the ID
> when all references have been dropped instead of when the device is only
> deleted.
>
> Signed-off-by: Mike Christie <michael.christie@oracle.com>
> ---
> drivers/scsi/scsi_transport_iscsi.c | 71 ++++++++++++++---------------
> include/scsi/scsi_transport_iscsi.h | 2 +-
> 2 files changed, 36 insertions(+), 37 deletions(-)
Reviewed-by: Chris Leech <cleech@redhat.com>
> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
> index bf39fb5569b6..1fc7c6bfbd67 100644
> --- a/drivers/scsi/scsi_transport_iscsi.c
> +++ b/drivers/scsi/scsi_transport_iscsi.c
> @@ -86,6 +86,9 @@ struct iscsi_internal {
> struct transport_container session_cont;
> };
>
> +static DEFINE_IDR(iscsi_ep_idr);
> +static DEFINE_MUTEX(iscsi_ep_idr_mutex);
> +
> static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
>
> static struct workqueue_struct *iscsi_conn_cleanup_workq;
> @@ -168,6 +171,11 @@ struct device_attribute dev_attr_##_prefix##_##_name = \
> static void iscsi_endpoint_release(struct device *dev)
> {
> struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
> +
> + mutex_lock(&iscsi_ep_idr_mutex);
> + idr_remove(&iscsi_ep_idr, ep->id);
> + mutex_unlock(&iscsi_ep_idr_mutex);
> +
> kfree(ep);
> }
>
> @@ -180,7 +188,7 @@ static ssize_t
> show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
> {
> struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
> - return sysfs_emit(buf, "%llu\n", (unsigned long long) ep->id);
> + return sysfs_emit(buf, "%d\n", ep->id);
> }
> static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
>
> @@ -193,48 +201,32 @@ static struct attribute_group iscsi_endpoint_group = {
> .attrs = iscsi_endpoint_attrs,
> };
>
> -#define ISCSI_MAX_EPID -1
> -
> -static int iscsi_match_epid(struct device *dev, const void *data)
> -{
> - struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
> - const uint64_t *epid = data;
> -
> - return *epid == ep->id;
> -}
> -
> struct iscsi_endpoint *
> iscsi_create_endpoint(int dd_size)
> {
> - struct device *dev;
> struct iscsi_endpoint *ep;
> - uint64_t id;
> - int err;
> -
> - for (id = 1; id < ISCSI_MAX_EPID; id++) {
> - dev = class_find_device(&iscsi_endpoint_class, NULL, &id,
> - iscsi_match_epid);
> - if (!dev)
> - break;
> - else
> - put_device(dev);
> - }
> - if (id == ISCSI_MAX_EPID) {
> - printk(KERN_ERR "Too many connections. Max supported %u\n",
> - ISCSI_MAX_EPID - 1);
> - return NULL;
> - }
> + int err, id;
>
> ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
> if (!ep)
> return NULL;
>
> + mutex_lock(&iscsi_ep_idr_mutex);
> + id = idr_alloc(&iscsi_ep_idr, ep, 0, -1, GFP_NOIO);
> + if (id < 0) {
> + mutex_unlock(&iscsi_ep_idr_mutex);
> + printk(KERN_ERR "Could not allocate endpoint ID. Error %d.\n",
> + id);
> + goto free_ep;
> + }
> + mutex_unlock(&iscsi_ep_idr_mutex);
> +
> ep->id = id;
> ep->dev.class = &iscsi_endpoint_class;
> - dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id);
> + dev_set_name(&ep->dev, "ep-%d", id);
> err = device_register(&ep->dev);
> if (err)
> - goto free_ep;
> + goto free_id;
>
> err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
> if (err)
> @@ -248,6 +240,10 @@ iscsi_create_endpoint(int dd_size)
> device_unregister(&ep->dev);
> return NULL;
>
> +free_id:
> + mutex_lock(&iscsi_ep_idr_mutex);
> + idr_remove(&iscsi_ep_idr, id);
> + mutex_unlock(&iscsi_ep_idr_mutex);
> free_ep:
> kfree(ep);
> return NULL;
> @@ -275,14 +271,17 @@ EXPORT_SYMBOL_GPL(iscsi_put_endpoint);
> */
> struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
> {
> - struct device *dev;
> + struct iscsi_endpoint *ep;
>
> - dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
> - iscsi_match_epid);
> - if (!dev)
> - return NULL;
> + mutex_lock(&iscsi_ep_idr_mutex);
> + ep = idr_find(&iscsi_ep_idr, handle);
> + if (!ep)
> + goto unlock;
>
> - return iscsi_dev_to_endpoint(dev);
> + get_device(&ep->dev);
> +unlock:
> + mutex_unlock(&iscsi_ep_idr_mutex);
> + return ep;
> }
> EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
>
> diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
> index 38e4a67f5922..fdd486047404 100644
> --- a/include/scsi/scsi_transport_iscsi.h
> +++ b/include/scsi/scsi_transport_iscsi.h
> @@ -295,7 +295,7 @@ extern void iscsi_host_for_each_session(struct Scsi_Host *shost,
> struct iscsi_endpoint {
> void *dd_data; /* LLD private data */
> struct device dev;
> - uint64_t id;
> + int id;
> struct iscsi_cls_conn *conn;
> };
>
> --
> 2.25.1
>
next prev parent reply other threads:[~2022-04-09 1:40 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 0:13 [PATCH 00/10] iscsi fixes Mike Christie
2022-04-08 0:13 ` [PATCH 01/10] scsi: iscsi: Move iscsi_ep_disconnect Mike Christie
2022-04-09 1:36 ` Chris Leech
2022-04-08 0:13 ` [PATCH 02/10] scsi: iscsi: Fix offload conn cleanup when iscsid restarts Mike Christie
2022-04-08 17:21 ` Lee Duncan
2022-04-09 1:36 ` Chris Leech
2022-04-08 0:13 ` [PATCH 03/10] scsi: iscsi: Release endpoint ID when its freed Mike Christie
2022-04-08 17:39 ` Lee Duncan
2022-04-09 1:40 ` Chris Leech [this message]
2022-04-11 7:22 ` wubo (T)
2022-04-08 0:13 ` [PATCH 04/10] scsi: iscsi: Fix endpoint reuse regression Mike Christie
2022-04-08 17:40 ` Lee Duncan
2022-04-09 1:41 ` Chris Leech
2022-04-08 0:13 ` [PATCH 05/10] scsi: iscsi: Fix conn cleanup and stop race during iscsid restart Mike Christie
2022-04-08 17:48 ` Lee Duncan
2022-04-09 1:46 ` Chris Leech
2022-04-08 0:13 ` [PATCH 06/10] scsi: iscsi: Fix unbound endpoint error handling Mike Christie
2022-04-08 17:55 ` Lee Duncan
2022-04-09 1:54 ` Chris Leech
2022-04-08 0:13 ` [PATCH 07/10] scsi: iscsi: Merge suspend fields Mike Christie
2022-04-09 1:56 ` Chris Leech
2022-04-08 0:13 ` [PATCH 08/10] scsi: iscsi: Fix nop handling during conn recovery Mike Christie
2022-04-09 1:59 ` Chris Leech
2022-04-08 0:13 ` [PATCH 09/10] scsi: qedi: Fix failed disconnect handling Mike Christie
2022-04-08 16:49 ` [EXT] " Manish Rangankar
2022-04-08 17:58 ` Lee Duncan
2022-04-09 2:00 ` Chris Leech
2022-04-08 0:13 ` [PATCH 10/10] scsi: iscsi: Add Mike Christie as co-maintainer Mike Christie
2022-04-08 17:59 ` Lee Duncan
2022-04-09 1:57 ` Chris Leech
2022-04-08 16:47 ` [EXT] [PATCH 00/10] iscsi fixes Manish Rangankar
2022-04-12 2:36 ` Martin K. Petersen
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=YlDkB4+O77xyxUj6@localhost \
--to=cleech@redhat.com \
--cc=GR-QLogic-Storage-Upstream@marvell.com \
--cc=jejb@linux.ibm.com \
--cc=lduncan@suse.com \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=mrangankar@marvell.com \
--cc=njavali@marvell.com \
--cc=skashyap@marvell.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox