* [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
@ 2021-03-22 19:57 amit.engel
2021-03-26 13:32 ` Engel, Amit
` (2 more replies)
0 siblings, 3 replies; 15+ messages in thread
From: amit.engel @ 2021-03-22 19:57 UTC (permalink / raw)
To: linux-nvme, james.smart, Chaitanya.Kulkarni; +Cc: amit.engel, James Smart
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.
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Amit Engel <amit.engel@dell.com>
---
drivers/nvme/target/fc.c | 77 ++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 31 deletions(-)
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index d375745fc4ed..cfde3376b8ee 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1020,61 +1020,76 @@ 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;
+
+ lockdep_assert_held(&tgtport->lock);
+
+ 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
+ */
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
^ permalink raw reply related [flat|nested] 15+ messages in thread
* RE: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-22 19:57 [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport amit.engel
@ 2021-03-26 13:32 ` Engel, Amit
2021-03-26 19:02 ` Chaitanya Kulkarni
2021-04-10 6:45 ` Christoph Hellwig
2021-04-12 7:48 ` Christoph Hellwig
2 siblings, 1 reply; 15+ messages in thread
From: Engel, Amit @ 2021-03-26 13:32 UTC (permalink / raw)
To: linux-nvme, james.smart, Chaitanya.Kulkarni; +Cc: James Smart
Hi, are we OK with this patch? please let me know if there is anything that is missing/required
Thanks
Amit E
-----Original Message-----
From: Engel, Amit <Amit.Engel@Dell.com>
Sent: Monday, March 22, 2021 9:57 PM
To: linux-nvme@lists.infradead.org; james.smart@broadcom.com; Chaitanya.Kulkarni@wdc.com
Cc: Engel, Amit; James Smart
Subject: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
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.
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Amit Engel <amit.engel@dell.com>
---
drivers/nvme/target/fc.c | 77 ++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 31 deletions(-)
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c index d375745fc4ed..cfde3376b8ee 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1020,61 +1020,76 @@ 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;
+
+ lockdep_assert_held(&tgtport->lock);
+
+ 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
+ */
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
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-26 13:32 ` Engel, Amit
@ 2021-03-26 19:02 ` Chaitanya Kulkarni
2021-04-04 11:41 ` Engel, Amit
0 siblings, 1 reply; 15+ messages in thread
From: Chaitanya Kulkarni @ 2021-03-26 19:02 UTC (permalink / raw)
To: Engel, Amit, linux-nvme, james.smart; +Cc: James Smart
On 3/26/21 06:32, Engel, Amit wrote:
> Hi, are we OK with this patch? please let me know if there is anything that is missing/required
>
> Thanks
> Amit E
Looks good.
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* RE: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-26 19:02 ` Chaitanya Kulkarni
@ 2021-04-04 11:41 ` Engel, Amit
0 siblings, 0 replies; 15+ messages in thread
From: Engel, Amit @ 2021-04-04 11:41 UTC (permalink / raw)
To: Chaitanya Kulkarni, linux-nvme, james.smart; +Cc: James Smart
Ok, thank you
Amit
-----Original Message-----
From: Chaitanya Kulkarni <Chaitanya.Kulkarni@wdc.com>
Sent: Friday, March 26, 2021 10:03 PM
To: Engel, Amit; linux-nvme@lists.infradead.org; james.smart@broadcom.com
Cc: James Smart
Subject: Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
[EXTERNAL EMAIL]
On 3/26/21 06:32, Engel, Amit wrote:
> Hi, are we OK with this patch? please let me know if there is anything that is missing/required
>
> Thanks
> Amit E
Looks good.
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-22 19:57 [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport amit.engel
2021-03-26 13:32 ` Engel, Amit
@ 2021-04-10 6:45 ` Christoph Hellwig
2021-04-10 14:27 ` James Smart
2021-04-12 7:48 ` Christoph Hellwig
2 siblings, 1 reply; 15+ messages in thread
From: Christoph Hellwig @ 2021-04-10 6:45 UTC (permalink / raw)
To: amit.engel; +Cc: linux-nvme, james.smart, Chaitanya.Kulkarni, James Smart
On Mon, Mar 22, 2021 at 09:57:17PM +0200, 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.
>
> Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
> Signed-off-by: James Smart <jsmart2021@gmail.com>
Is this really a signoff from James or a review?
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-04-10 6:45 ` Christoph Hellwig
@ 2021-04-10 14:27 ` James Smart
0 siblings, 0 replies; 15+ messages in thread
From: James Smart @ 2021-04-10 14:27 UTC (permalink / raw)
To: Christoph Hellwig, amit.engel; +Cc: linux-nvme, james.smart, Chaitanya.Kulkarni
On 4/9/2021 11:45 PM, Christoph Hellwig wrote:
> On Mon, Mar 22, 2021 at 09:57:17PM +0200, 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.
>>
>> Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
>> Signed-off-by: James Smart <jsmart2021@gmail.com>
>
> Is this really a signoff from James or a review?
>
I reworked some of it - so it's a joint Signed-off-by w/ Amit.
-- james
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-22 19:57 [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport amit.engel
2021-03-26 13:32 ` Engel, Amit
2021-04-10 6:45 ` Christoph Hellwig
@ 2021-04-12 7:48 ` Christoph Hellwig
2 siblings, 0 replies; 15+ messages in thread
From: Christoph Hellwig @ 2021-04-12 7:48 UTC (permalink / raw)
To: amit.engel; +Cc: linux-nvme, james.smart, Chaitanya.Kulkarni, James Smart
Thanks, applied to nvme-5.13.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-22 19:37 ` James Smart
@ 2021-03-22 19:40 ` Chaitanya Kulkarni
0 siblings, 0 replies; 15+ messages in thread
From: Chaitanya Kulkarni @ 2021-03-22 19:40 UTC (permalink / raw)
To: James Smart, amit.engel, linux-nvme, james.smart
On 3/22/21 12:37, James Smart wrote:
>> Same comment about return () here.
>>
>>
> nothing wrong here....
>
> -- james
>
>
Wrong comment plesae ignore.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-22 19:15 ` Chaitanya Kulkarni
@ 2021-03-22 19:37 ` James Smart
2021-03-22 19:40 ` Chaitanya Kulkarni
0 siblings, 1 reply; 15+ messages in thread
From: James Smart @ 2021-03-22 19:37 UTC (permalink / raw)
To: Chaitanya Kulkarni, amit.engel, linux-nvme, james.smart
On 3/22/2021 12:15 PM, Chaitanya Kulkarni wrote:
> On 3/22/21 12:08, amit.engel@dell.com wrote:
>> - return (match) ? match : ERR_PTR(-ENOMEM);
>> + return ERR_PTR(-ENOMEM);
>> }
>
> Same comment about return () here.
>
>
nothing wrong here....
-- james
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
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
2 siblings, 1 reply; 15+ messages in thread
From: Chaitanya Kulkarni @ 2021-03-22 19:15 UTC (permalink / raw)
To: amit.engel, linux-nvme, james.smart; +Cc: James Smart
On 3/22/21 12:08, amit.engel@dell.com wrote:
> - return (match) ? match : ERR_PTR(-ENOMEM);
> + return ERR_PTR(-ENOMEM);
> }
Same comment about return () here.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
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
2 siblings, 0 replies; 15+ messages in thread
From: Chaitanya Kulkarni @ 2021-03-22 19:13 UTC (permalink / raw)
To: amit.engel, linux-nvme, james.smart; +Cc: James Smart
On 3/22/21 12:08, amit.engel@dell.com wrote:
> + }
> +
> + return (NULL);
> +}
nit:- no need for () around NULL.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
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
2 siblings, 0 replies; 15+ messages in thread
From: Chaitanya Kulkarni @ 2021-03-22 19:11 UTC (permalink / raw)
To: amit.engel, linux-nvme, james.smart; +Cc: James Smart
On 3/22/21 12:08, amit.engel@dell.com wrote:
> + struct nvmet_fc_hostport *host;
> +
> + /* tgtport->lock is held by caller */
> +
Please consider adding lockdep instead of comment.
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
@ 2021-03-22 18:59 amit.engel
2021-03-22 19:11 ` Chaitanya Kulkarni
` (2 more replies)
0 siblings, 3 replies; 15+ messages in thread
From: amit.engel @ 2021-03-22 18:59 UTC (permalink / raw)
To: linux-nvme, james.smart; +Cc: amit.engel, James Smart
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.
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Amit Engel <amit.engel@dell.com>
---
drivers/nvme/target/fc.c | 77 ++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 31 deletions(-)
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index d375745fc4ed..d62e1f973177 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1020,61 +1020,76 @@ 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
+ */
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
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
2021-03-16 6:43 amit.engel
@ 2021-03-17 21:28 ` Himanshu Madhani
0 siblings, 0 replies; 15+ messages in thread
From: Himanshu Madhani @ 2021-03-17 21:28 UTC (permalink / raw)
To: amit.engel; +Cc: linux-nvme, jsmart2021
> 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
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport
@ 2021-03-16 6:43 amit.engel
2021-03-17 21:28 ` Himanshu Madhani
0 siblings, 1 reply; 15+ messages in thread
From: amit.engel @ 2021-03-16 6:43 UTC (permalink / raw)
To: linux-nvme, jsmart2021; +Cc: amit.engel
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
+ */
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
^ permalink raw reply related [flat|nested] 15+ messages in thread
end of thread, other threads:[~2021-04-12 7:49 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 19:57 [PATCH] nvmet-fc: simplify nvmet_fc_alloc_hostport 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
-- strict thread matches above, loose matches on Subject: below --
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-16 6:43 amit.engel
2021-03-17 21:28 ` Himanshu Madhani
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).