Skip to content

Commit c6611bb

Browse files
committed
tree: Factor lookup code for controller
nvme_lookup_ctrl() will create a controller if it is not found. In the case where we really just want the lookup if a controller is in the tree we are missing a pure lookup function. Hence factor out the lookup into a internal function. Signed-off-by: Daniel Wagner <[email protected]>
1 parent ab027a2 commit c6611bb

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/nvme/private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ int json_update_config(nvme_root_t r, const char *config_file);
132132

133133
int json_dump_tree(nvme_root_t r);
134134

135+
nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
136+
const char *traddr, const char *host_traddr,
137+
const char *host_iface, const char *trsvcid,
138+
nvme_ctrl_t p);
139+
135140
#if (LOG_FUNCNAME == 1)
136141
#define __nvme_log_func __func__
137142
#else

src/nvme/tree.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,17 +1020,14 @@ struct nvme_ctrl *nvme_create_ctrl(nvme_root_t r,
10201020
return c;
10211021
}
10221022

1023-
nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
1024-
const char *traddr, const char *host_traddr,
1025-
const char *host_iface, const char *trsvcid,
1026-
nvme_ctrl_t p)
1023+
nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
1024+
const char *traddr, const char *host_traddr,
1025+
const char *host_iface, const char *trsvcid,
1026+
nvme_ctrl_t p)
1027+
10271028
{
1028-
nvme_root_t r;
10291029
struct nvme_ctrl *c;
10301030

1031-
if (!s || !transport)
1032-
return NULL;
1033-
r = s->h ? s->h->r : NULL;
10341031
c = p ? nvme_subsystem_next_ctrl(s, p) : nvme_subsystem_first_ctrl(s);
10351032
for (; c != NULL; c = nvme_subsystem_next_ctrl(s, c)) {
10361033
if (strcmp(c->transport, transport))
@@ -1049,6 +1046,27 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
10491046
continue;
10501047
return c;
10511048
}
1049+
1050+
return NULL;
1051+
}
1052+
1053+
nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
1054+
const char *traddr, const char *host_traddr,
1055+
const char *host_iface, const char *trsvcid,
1056+
nvme_ctrl_t p)
1057+
{
1058+
nvme_root_t r;
1059+
struct nvme_ctrl *c;
1060+
1061+
if (!s || !transport)
1062+
return NULL;
1063+
1064+
c = __nvme_lookup_ctrl(s, transport, traddr, host_traddr,
1065+
host_iface, trsvcid, p);
1066+
if (c)
1067+
return c;
1068+
1069+
r = s->h ? s->h->r : NULL;
10521070
c = nvme_create_ctrl(r, s->subsysnqn, transport, traddr,
10531071
host_traddr, host_iface, trsvcid);
10541072
if (c) {

0 commit comments

Comments
 (0)