From: Himanshu Madhani <himanshu.madhani@oracle.com>
To: "amit.engel@dell.com" <amit.engel@dell.com>
Cc: "linux-nvme@lists.infradead.org" <linux-nvme@lists.infradead.org>,
"jsmart2021@gmail.com" <jsmart2021@gmail.com>
Subject: Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
Date: Wed, 17 Mar 2021 21:28:30 +0000 [thread overview]
Message-ID: <EC219DA2-0CCB-42EE-95B6-CEBE9D332551@oracle.com> (raw)
In-Reply-To: <20210316064345.25713-1-amit.engel@dell.com>
> On Mar 16, 2021, at 1:43 AM, amit.engel@dell.com wrote:
>
> From: Amit Engel <amit.engel@dell.com>
>
> Once a host is already created,
> avoid allocate additional hostports that will be thrown away.
> add an helper function to handle host search.
>
> Signed-off-by: Amit Engel <amit.engel@dell.com>
> Signed-off-by: James Smart <jsmart2021@gmail.com>
> ---
> drivers/nvme/target/fc.c | 76 ++++++++++++++++++++++++----------------
> 1 file changed, 45 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
> index d375745fc4ed..4762f298e579 100644
> --- a/drivers/nvme/target/fc.c
> +++ b/drivers/nvme/target/fc.c
> @@ -1020,61 +1020,75 @@ nvmet_fc_free_hostport(struct nvmet_fc_hostport *hostport)
> nvmet_fc_hostport_put(hostport);
> }
>
> +static struct nvmet_fc_hostport *
> +nvmet_fc_match_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
> +{
> + struct nvmet_fc_hostport *host;
> +
> + /* tgtport->lock is held by caller */
> +
> + list_for_each_entry(host, &tgtport->host_list, host_list) {
> + if (host->hosthandle == hosthandle && !host->invalid) {
> + if (nvmet_fc_hostport_get(host))
> + return (host);
> + }
> + }
> +
> + return (NULL);
> +}
> +
> static struct nvmet_fc_hostport *
> nvmet_fc_alloc_hostport(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
> {
> - struct nvmet_fc_hostport *newhost, *host, *match = NULL;
> + struct nvmet_fc_hostport *newhost, *match = NULL;
> unsigned long flags;
>
> /* if LLDD not implemented, leave as NULL */
> if (!hosthandle)
> return NULL;
>
> - /* take reference for what will be the newly allocated hostport */
> + /* take reference for what will be the newly allocated hostport if
> + * we end up using a new allocation
> + */
Small nit.. Please fix the comment formatting for multi-line
> if (!nvmet_fc_tgtport_get(tgtport))
> return ERR_PTR(-EINVAL);
>
> + spin_lock_irqsave(&tgtport->lock, flags);
> + match = nvmet_fc_match_hostport(tgtport, hosthandle);
> + spin_unlock_irqrestore(&tgtport->lock, flags);
> +
> + if (match) {
> + /* no new allocation - release reference */
> + nvmet_fc_tgtport_put(tgtport);
> + return match;
> + }
> +
> newhost = kzalloc(sizeof(*newhost), GFP_KERNEL);
> if (!newhost) {
> - spin_lock_irqsave(&tgtport->lock, flags);
> - list_for_each_entry(host, &tgtport->host_list, host_list) {
> - if (host->hosthandle == hosthandle && !host->invalid) {
> - if (nvmet_fc_hostport_get(host)) {
> - match = host;
> - break;
> - }
> - }
> - }
> - spin_unlock_irqrestore(&tgtport->lock, flags);
> - /* no allocation - release reference */
> + /* no new allocation - release reference */
> nvmet_fc_tgtport_put(tgtport);
> - return (match) ? match : ERR_PTR(-ENOMEM);
> + return ERR_PTR(-ENOMEM);
> }
>
> - newhost->tgtport = tgtport;
> - newhost->hosthandle = hosthandle;
> - INIT_LIST_HEAD(&newhost->host_list);
> - kref_init(&newhost->ref);
> -
> spin_lock_irqsave(&tgtport->lock, flags);
> - list_for_each_entry(host, &tgtport->host_list, host_list) {
> - if (host->hosthandle == hosthandle && !host->invalid) {
> - if (nvmet_fc_hostport_get(host)) {
> - match = host;
> - break;
> - }
> - }
> - }
> + match = nvmet_fc_match_hostport(tgtport, hosthandle);
> if (match) {
> + /* new allocation not needed */
> kfree(newhost);
> - newhost = NULL;
> - /* releasing allocation - release reference */
> + newhost = match;
> + /* no new allocation - release reference */
> nvmet_fc_tgtport_put(tgtport);
> - } else
> + } else {
> + newhost->tgtport = tgtport;
> + newhost->hosthandle = hosthandle;
> + INIT_LIST_HEAD(&newhost->host_list);
> + kref_init(&newhost->ref);
> +
> list_add_tail(&newhost->host_list, &tgtport->host_list);
> + }
> spin_unlock_irqrestore(&tgtport->lock, flags);
>
> - return (match) ? match : newhost;
> + return newhost;
> }
>
> static void
> --
> 2.18.2
>
>
> _______________________________________________
> Linux-nvme mailing list
> Linux-nvme@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-nvme
code looks good.
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
--
Himanshu Madhani Oracle Linux Engineering
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next prev parent reply other threads:[~2021-03-17 21:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-16 6:43 [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport amit.engel
2021-03-17 21:28 ` Himanshu Madhani [this message]
2021-03-22 18:59 amit.engel
2021-03-22 19:11 ` Chaitanya Kulkarni
2021-03-22 19:13 ` Chaitanya Kulkarni
2021-03-22 19:15 ` Chaitanya Kulkarni
2021-03-22 19:37 ` James Smart
2021-03-22 19:40 ` Chaitanya Kulkarni
2021-03-22 19:57 amit.engel
2021-03-26 13:32 ` Engel, Amit
2021-03-26 19:02 ` Chaitanya Kulkarni
2021-04-04 11:41 ` Engel, Amit
2021-04-10 6:45 ` Christoph Hellwig
2021-04-10 14:27 ` James Smart
2021-04-12 7:48 ` Christoph Hellwig
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=EC219DA2-0CCB-42EE-95B6-CEBE9D332551@oracle.com \
--to=himanshu.madhani@oracle.com \
--cc=amit.engel@dell.com \
--cc=jsmart2021@gmail.com \
--cc=linux-nvme@lists.infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).