Skip to content

Commit 959ffef

Browse files
Chaitanya Kulkarnikeithbusch
authored andcommitted
nvme-fabrics: open code __nvmf_host_find()
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 <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Max Gurtovoy <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent 900095b commit 959ffef

File tree

1 file changed

+27
-48
lines changed

1 file changed

+27
-48
lines changed

drivers/nvme/host/fabrics.c

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,6 @@ static DEFINE_MUTEX(nvmf_hosts_mutex);
2121

2222
static struct nvmf_host *nvmf_default_host;
2323

24-
/**
25-
* __nvmf_host_find() - Find a matching to a previously created host
26-
* @hostnqn: Host NQN to match
27-
* @id: Host ID to match
28-
*
29-
* We have defined a host as how it is perceived by the target.
30-
* Therefore, we don't allow different Host NQNs with the same Host ID.
31-
* Similarly, we do not allow the usage of the same Host NQN with different
32-
* Host IDs. This will maintain unambiguous host identification.
33-
*
34-
* Return: Returns host pointer on success, NULL in case of no match or
35-
* ERR_PTR(-EINVAL) in case of error match.
36-
*/
37-
static struct nvmf_host *__nvmf_host_find(const char *hostnqn, uuid_t *id)
38-
{
39-
struct nvmf_host *host;
40-
41-
lockdep_assert_held(&nvmf_hosts_mutex);
42-
43-
list_for_each_entry(host, &nvmf_hosts, list) {
44-
bool same_hostnqn = !strcmp(host->nqn, hostnqn);
45-
bool same_hostid = uuid_equal(&host->id, id);
46-
47-
if (same_hostnqn && same_hostid)
48-
return host;
49-
50-
if (same_hostnqn) {
51-
pr_err("found same hostnqn %s but different hostid %pUb\n",
52-
hostnqn, id);
53-
return ERR_PTR(-EINVAL);
54-
}
55-
if (same_hostid) {
56-
pr_err("found same hostid %pUb but different hostnqn %s\n",
57-
id, hostnqn);
58-
return ERR_PTR(-EINVAL);
59-
60-
}
61-
}
62-
63-
return NULL;
64-
}
65-
6624
static struct nvmf_host *nvmf_host_alloc(const char *hostnqn, uuid_t *id)
6725
{
6826
struct nvmf_host *host;
@@ -83,12 +41,33 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
8341
struct nvmf_host *host;
8442

8543
mutex_lock(&nvmf_hosts_mutex);
86-
host = __nvmf_host_find(hostnqn, id);
87-
if (IS_ERR(host)) {
88-
goto out_unlock;
89-
} else if (host) {
90-
kref_get(&host->ref);
91-
goto out_unlock;
44+
45+
/*
46+
* We have defined a host as how it is perceived by the target.
47+
* Therefore, we don't allow different Host NQNs with the same Host ID.
48+
* Similarly, we do not allow the usage of the same Host NQN with
49+
* different Host IDs. This'll maintain unambiguous host identification.
50+
*/
51+
list_for_each_entry(host, &nvmf_hosts, list) {
52+
bool same_hostnqn = !strcmp(host->nqn, hostnqn);
53+
bool same_hostid = uuid_equal(&host->id, id);
54+
55+
if (same_hostnqn && same_hostid) {
56+
kref_get(&host->ref);
57+
goto out_unlock;
58+
}
59+
if (same_hostnqn) {
60+
pr_err("found same hostnqn %s but different hostid %pUb\n",
61+
hostnqn, id);
62+
host = ERR_PTR(-EINVAL);
63+
goto out_unlock;
64+
}
65+
if (same_hostid) {
66+
pr_err("found same hostid %pUb but different hostnqn %s\n",
67+
id, hostnqn);
68+
host = ERR_PTR(-EINVAL);
69+
goto out_unlock;
70+
}
9271
}
9372

9473
host = nvmf_host_alloc(hostnqn, id);

0 commit comments

Comments
 (0)