* [PATCH] nvme-fabrics: open code __nvmf_host_find()
@ 2023-06-02 6:47 Chaitanya Kulkarni
2023-06-02 15:04 ` Christoph Hellwig
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Chaitanya Kulkarni @ 2023-06-02 6:47 UTC (permalink / raw)
To: linux-nvme; +Cc: kbusch, hch, sagi, Chaitanya Kulkarni
There is no point in maintaining a separate funciton __nvmf_host_find()
that has only one caller nvmf_host_add() especially when caller and
callee both are small enough to merge.
Due to this we are actually repeating the error handling code in both
callee and caller for no reason that can be avoided, but instead we have
to read both function to establish the correctness along with additional
lockdep warning check due to involved locking.
Just open code __nvmf_host_find() in nvme_host_alloc() with appropriate
comment that removes repeated error checks in the callee/caller and
lockdep check that is needed for the nvmf_hosts_mutex involvement,
diffstats :-
drivers/nvme/host/fabrics.c | 75 +++++++++++++------------------------
1 file changed, 27 insertions(+), 48 deletions(-)
Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
Hi,
This is generated on the top of posted fix :
[PATCH] nvme-fabrics: error out to unlock the mutex
-ck
drivers/nvme/host/fabrics.c | 75 +++++++++++++------------------------
1 file changed, 27 insertions(+), 48 deletions(-)
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index c4345d1d98aa..8175d49f2909 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -21,48 +21,6 @@ static DEFINE_MUTEX(nvmf_hosts_mutex);
static struct nvmf_host *nvmf_default_host;
-/**
- * __nvmf_host_find() - Find a matching to a previously created host
- * @hostnqn: Host NQN to match
- * @id: Host ID to match
- *
- * We have defined a host as how it is perceived by the target.
- * Therefore, we don't allow different Host NQNs with the same Host ID.
- * Similarly, we do not allow the usage of the same Host NQN with different
- * Host IDs. This will maintain unambiguous host identification.
- *
- * Return: Returns host pointer on success, NULL in case of no match or
- * ERR_PTR(-EINVAL) in case of error match.
- */
-static struct nvmf_host *__nvmf_host_find(const char *hostnqn, uuid_t *id)
-{
- struct nvmf_host *host;
-
- lockdep_assert_held(&nvmf_hosts_mutex);
-
- list_for_each_entry(host, &nvmf_hosts, list) {
- bool same_hostnqn = !strcmp(host->nqn, hostnqn);
- bool same_hostid = uuid_equal(&host->id, id);
-
- if (same_hostnqn && same_hostid)
- return host;
-
- if (same_hostnqn) {
- pr_err("found same hostnqn %s but different hostid %pUb\n",
- hostnqn, id);
- return ERR_PTR(-EINVAL);
- }
- if (same_hostid) {
- pr_err("found same hostid %pUb but different hostnqn %s\n",
- id, hostnqn);
- return ERR_PTR(-EINVAL);
-
- }
- }
-
- return NULL;
-}
-
static struct nvmf_host *nvmf_host_alloc(const char *hostnqn, uuid_t *id)
{
struct nvmf_host *host;
@@ -83,12 +41,33 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
struct nvmf_host *host;
mutex_lock(&nvmf_hosts_mutex);
- host = __nvmf_host_find(hostnqn, id);
- if (IS_ERR(host)) {
- goto out_unlock;
- } else if (host) {
- kref_get(&host->ref);
- goto out_unlock;
+
+ /*
+ * We have defined a host as how it is perceived by the target.
+ * Therefore, we don't allow different Host NQNs with the same Host ID.
+ * Similarly, we do not allow the usage of the same Host NQN with
+ * different Host IDs. This'll maintain unambiguous host identification.
+ */
+ list_for_each_entry(host, &nvmf_hosts, list) {
+ bool same_hostnqn = !strcmp(host->nqn, hostnqn);
+ bool same_hostid = uuid_equal(&host->id, id);
+
+ if (same_hostnqn && same_hostid) {
+ kref_get(&host->ref);
+ goto out_unlock;
+ }
+ if (same_hostnqn) {
+ pr_err("found same hostnqn %s but different hostid %pUb\n",
+ hostnqn, id);
+ host = ERR_PTR(-EINVAL);
+ goto out_unlock;
+ }
+ if (same_hostid) {
+ pr_err("found same hostid %pUb but different hostnqn %s\n",
+ id, hostnqn);
+ host = ERR_PTR(-EINVAL);
+ goto out_unlock;
+ }
}
host = nvmf_host_alloc(hostnqn, id);
--
2.40.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-fabrics: open code __nvmf_host_find()
2023-06-02 6:47 [PATCH] nvme-fabrics: open code __nvmf_host_find() Chaitanya Kulkarni
@ 2023-06-02 15:04 ` Christoph Hellwig
2023-06-04 0:35 ` Max Gurtovoy
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2023-06-02 15:04 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-nvme, kbusch, hch, sagi
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-fabrics: open code __nvmf_host_find()
2023-06-02 6:47 [PATCH] nvme-fabrics: open code __nvmf_host_find() Chaitanya Kulkarni
2023-06-02 15:04 ` Christoph Hellwig
@ 2023-06-04 0:35 ` Max Gurtovoy
2023-06-05 9:13 ` Chaitanya Kulkarni
2023-06-05 21:52 ` Sagi Grimberg
2023-06-09 15:46 ` Keith Busch
3 siblings, 1 reply; 7+ messages in thread
From: Max Gurtovoy @ 2023-06-04 0:35 UTC (permalink / raw)
To: Chaitanya Kulkarni, linux-nvme; +Cc: kbusch, hch, sagi
Hi,
On 02/06/2023 9:47, Chaitanya Kulkarni wrote:
> There is no point in maintaining a separate funciton __nvmf_host_find()
typo *function
> that has only one caller nvmf_host_add() especially when caller and
> callee both are small enough to merge.
>
> Due to this we are actually repeating the error handling code in both
> callee and caller for no reason that can be avoided, but instead we have
> to read both function to establish the correctness along with additional
> lockdep warning check due to involved locking.
>
> Just open code __nvmf_host_find() in nvme_host_alloc() with appropriate
> comment that removes repeated error checks in the callee/caller and
> lockdep check that is needed for the nvmf_hosts_mutex involvement,
> diffstats :-
The above 2 sentences are redundant IMO.
There is no error handling in the callee so it can't be repeated. We
just return error in the callee.
The first sentence is good enough to justify this patch.
Lets have instead:
"Merge its code with the only caller nvmf_host_add() since both are
small enough.
The lockdep check in __nvmf_host_find() after the merge becomes
redundant so we can remove it too."
>
> drivers/nvme/host/fabrics.c | 75 +++++++++++++------------------------
> 1 file changed, 27 insertions(+), 48 deletions(-)
>
> Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
> ---
> Hi,
>
> This is generated on the top of posted fix :
> [PATCH] nvme-fabrics: error out to unlock the mutex
>
> -ck
>
> drivers/nvme/host/fabrics.c | 75 +++++++++++++------------------------
> 1 file changed, 27 insertions(+), 48 deletions(-)
>
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index c4345d1d98aa..8175d49f2909 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
> @@ -21,48 +21,6 @@ static DEFINE_MUTEX(nvmf_hosts_mutex);
>
> static struct nvmf_host *nvmf_default_host;
>
> -/**
> - * __nvmf_host_find() - Find a matching to a previously created host
> - * @hostnqn: Host NQN to match
> - * @id: Host ID to match
> - *
> - * We have defined a host as how it is perceived by the target.
> - * Therefore, we don't allow different Host NQNs with the same Host ID.
> - * Similarly, we do not allow the usage of the same Host NQN with different
> - * Host IDs. This will maintain unambiguous host identification.
> - *
> - * Return: Returns host pointer on success, NULL in case of no match or
> - * ERR_PTR(-EINVAL) in case of error match.
> - */
> -static struct nvmf_host *__nvmf_host_find(const char *hostnqn, uuid_t *id)
> -{
> - struct nvmf_host *host;
> -
> - lockdep_assert_held(&nvmf_hosts_mutex);
> -
> - list_for_each_entry(host, &nvmf_hosts, list) {
> - bool same_hostnqn = !strcmp(host->nqn, hostnqn);
> - bool same_hostid = uuid_equal(&host->id, id);
> -
> - if (same_hostnqn && same_hostid)
> - return host;
> -
> - if (same_hostnqn) {
> - pr_err("found same hostnqn %s but different hostid %pUb\n",
> - hostnqn, id);
> - return ERR_PTR(-EINVAL);
> - }
> - if (same_hostid) {
> - pr_err("found same hostid %pUb but different hostnqn %s\n",
> - id, hostnqn);
> - return ERR_PTR(-EINVAL);
> -
> - }
> - }
> -
> - return NULL;
> -}
> -
> static struct nvmf_host *nvmf_host_alloc(const char *hostnqn, uuid_t *id)
> {
> struct nvmf_host *host;
> @@ -83,12 +41,33 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
> struct nvmf_host *host;
>
> mutex_lock(&nvmf_hosts_mutex);
> - host = __nvmf_host_find(hostnqn, id);
> - if (IS_ERR(host)) {
> - goto out_unlock;
> - } else if (host) {
> - kref_get(&host->ref);
> - goto out_unlock;
> +
> + /*
> + * We have defined a host as how it is perceived by the target.
> + * Therefore, we don't allow different Host NQNs with the same Host ID.
> + * Similarly, we do not allow the usage of the same Host NQN with
> + * different Host IDs. This'll maintain unambiguous host identification.
> + */
> + list_for_each_entry(host, &nvmf_hosts, list) {
> + bool same_hostnqn = !strcmp(host->nqn, hostnqn);
> + bool same_hostid = uuid_equal(&host->id, id);
> +
> + if (same_hostnqn && same_hostid) {
> + kref_get(&host->ref);
> + goto out_unlock;
> + }
> + if (same_hostnqn) {
> + pr_err("found same hostnqn %s but different hostid %pUb\n",
> + hostnqn, id);
> + host = ERR_PTR(-EINVAL);
> + goto out_unlock;
> + }
> + if (same_hostid) {
> + pr_err("found same hostid %pUb but different hostnqn %s\n",
> + id, hostnqn);
> + host = ERR_PTR(-EINVAL);
> + goto out_unlock;
> + }
> }
>
> host = nvmf_host_alloc(hostnqn, id);
With the updated commit message,
The code looks good to me,
Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-fabrics: open code __nvmf_host_find()
2023-06-04 0:35 ` Max Gurtovoy
@ 2023-06-05 9:13 ` Chaitanya Kulkarni
2023-06-05 10:51 ` Max Gurtovoy
0 siblings, 1 reply; 7+ messages in thread
From: Chaitanya Kulkarni @ 2023-06-05 9:13 UTC (permalink / raw)
To: Max Gurtovoy, Chaitanya Kulkarni, linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, hch@lst.de, sagi@grimberg.me
On 6/3/23 17:35, Max Gurtovoy wrote:
> Hi,
>
> On 02/06/2023 9:47, Chaitanya Kulkarni wrote:
>> There is no point in maintaining a separate funciton __nvmf_host_find()
>
> typo *function
>
>> that has only one caller nvmf_host_add() especially when caller and
>> callee both are small enough to merge.
>>
>> Due to this we are actually repeating the error handling code in both
>> callee and caller for no reason that can be avoided, but instead we have
>> to read both function to establish the correctness along with additional
>> lockdep warning check due to involved locking.
>>
>> Just open code __nvmf_host_find() in nvme_host_alloc() with appropriate
>> comment that removes repeated error checks in the callee/caller and
>> lockdep check that is needed for the nvmf_hosts_mutex involvement,
>> diffstats :-
>
> The above 2 sentences are redundant IMO.
> There is no error handling in the callee so it can't be repeated. We
> just return error in the callee.
and that is error handling, without error conditions we would
only returning either valid host (that is non NULL) or NULL in
absence of host in the list. That -EINVAL return is the reason
we need separate check with IS_ERR in the caller ...
- if (IS_ERR(host)) {
- goto out_unlock;
- } else if (host) {
- kref_get(&host->ref);
- goto out_unlock;
> The first sentence is good enough to justify this patch.
>
> Lets have instead:
>
> "Merge its code with the only caller nvmf_host_add() since both are
> small enough.
> The lockdep check in __nvmf_host_find() after the merge becomes
> redundant so we can remove it too."
>
>
I don't understand what you are saying, provide a complete commit
log that can be applied verbatim to this patch.
-ck
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-fabrics: open code __nvmf_host_find()
2023-06-05 9:13 ` Chaitanya Kulkarni
@ 2023-06-05 10:51 ` Max Gurtovoy
0 siblings, 0 replies; 7+ messages in thread
From: Max Gurtovoy @ 2023-06-05 10:51 UTC (permalink / raw)
To: Chaitanya Kulkarni, linux-nvme@lists.infradead.org
Cc: kbusch@kernel.org, hch@lst.de, sagi@grimberg.me
On 05/06/2023 12:13, Chaitanya Kulkarni wrote:
> On 6/3/23 17:35, Max Gurtovoy wrote:
>> Hi,
>>
>> On 02/06/2023 9:47, Chaitanya Kulkarni wrote:
>>> There is no point in maintaining a separate funciton __nvmf_host_find()
>>
>> typo *function
>>
>>> that has only one caller nvmf_host_add() especially when caller and
>>> callee both are small enough to merge.
>>>
>>> Due to this we are actually repeating the error handling code in both
>>> callee and caller for no reason that can be avoided, but instead we have
>>> to read both function to establish the correctness along with additional
>>> lockdep warning check due to involved locking.
>>>
>>> Just open code __nvmf_host_find() in nvme_host_alloc() with appropriate
>>> comment that removes repeated error checks in the callee/caller and
>>> lockdep check that is needed for the nvmf_hosts_mutex involvement,
>>> diffstats :-
>>
>> The above 2 sentences are redundant IMO.
>> There is no error handling in the callee so it can't be repeated. We
>> just return error in the callee.
>
> and that is error handling, without error conditions we would
> only returning either valid host (that is non NULL) or NULL in
> absence of host in the list. That -EINVAL return is the reason
> we need separate check with IS_ERR in the caller ...
>
> - if (IS_ERR(host)) {
> - goto out_unlock;
> - } else if (host) {
> - kref_get(&host->ref);
> - goto out_unlock;
this check happens in the caller. No duplication.
>
>> The first sentence is good enough to justify this patch.
>>
>> Lets have instead:
>>
>> "Merge its code with the only caller nvmf_host_add() since both are
>> small enough.
>> The lockdep check in __nvmf_host_find() after the merge becomes
>> redundant so we can remove it too."
>>
>>
>
> I don't understand what you are saying, provide a complete commit
> log that can be applied verbatim to this patch.
just say something like:
"
Open code __nvmf_host_find() since there is only one caller for it and
both are small enough to merge.
As a result, the lockdep check in __nvmf_host_find() after the merge
becomes redundant so we can remove it too.
"
>
> -ck
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-fabrics: open code __nvmf_host_find()
2023-06-02 6:47 [PATCH] nvme-fabrics: open code __nvmf_host_find() Chaitanya Kulkarni
2023-06-02 15:04 ` Christoph Hellwig
2023-06-04 0:35 ` Max Gurtovoy
@ 2023-06-05 21:52 ` Sagi Grimberg
2023-06-09 15:46 ` Keith Busch
3 siblings, 0 replies; 7+ messages in thread
From: Sagi Grimberg @ 2023-06-05 21:52 UTC (permalink / raw)
To: Chaitanya Kulkarni, linux-nvme; +Cc: kbusch, hch
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] nvme-fabrics: open code __nvmf_host_find()
2023-06-02 6:47 [PATCH] nvme-fabrics: open code __nvmf_host_find() Chaitanya Kulkarni
` (2 preceding siblings ...)
2023-06-05 21:52 ` Sagi Grimberg
@ 2023-06-09 15:46 ` Keith Busch
3 siblings, 0 replies; 7+ messages in thread
From: Keith Busch @ 2023-06-09 15:46 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-nvme, hch, sagi
Thanks, appliked for nvme-6.5.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-06-09 15:46 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-02 6:47 [PATCH] nvme-fabrics: open code __nvmf_host_find() Chaitanya Kulkarni
2023-06-02 15:04 ` Christoph Hellwig
2023-06-04 0:35 ` Max Gurtovoy
2023-06-05 9:13 ` Chaitanya Kulkarni
2023-06-05 10:51 ` Max Gurtovoy
2023-06-05 21:52 ` Sagi Grimberg
2023-06-09 15:46 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox