Skip to content

Commit d5ab086

Browse files
committed
libnvme: use 'struct nvmf_context' as argument for __nvme_lookup_ctrl()
To simplify the interface. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent fdcb92c commit d5ab086

3 files changed

Lines changed: 48 additions & 31 deletions

File tree

libnvme/src/nvme/fabrics.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -968,13 +968,15 @@ static const char *lookup_context(struct nvme_global_ctx *ctx, nvme_ctrl_t c)
968968

969969
nvme_for_each_host(ctx, h) {
970970
nvme_for_each_subsystem(h, s) {
971-
if (__nvme_lookup_ctrl(s, nvme_ctrl_get_transport(c),
972-
nvme_ctrl_get_traddr(c),
973-
NULL,
974-
NULL,
975-
nvme_ctrl_get_trsvcid(c),
976-
NULL,
977-
NULL))
971+
struct nvmf_context fctx = {
972+
.transport = nvme_ctrl_get_transport(c),
973+
.traddr = nvme_ctrl_get_traddr(c),
974+
.host_traddr = NULL,
975+
.host_iface = NULL,
976+
.trsvcid = nvme_ctrl_get_trsvcid(c),
977+
.subsysnqn = NULL,
978+
};
979+
if (__nvme_lookup_ctrl(s, &fctx, NULL))
978980
return nvme_subsystem_get_application(s);
979981
}
980982
}
@@ -997,14 +999,16 @@ __public int nvmf_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
997999
s = nvme_lookup_subsystem(h, NULL, nvme_ctrl_get_subsysnqn(c));
9981000
if (s) {
9991001
nvme_ctrl_t fc;
1000-
1001-
fc = __nvme_lookup_ctrl(s, nvme_ctrl_get_transport(c),
1002-
nvme_ctrl_get_traddr(c),
1003-
nvme_ctrl_get_host_traddr(c),
1004-
nvme_ctrl_get_host_iface(c),
1005-
nvme_ctrl_get_trsvcid(c),
1006-
NULL,
1007-
NULL);
1002+
struct nvmf_context fctx = {
1003+
.transport = nvme_ctrl_get_transport(c),
1004+
.traddr = nvme_ctrl_get_traddr(c),
1005+
.host_traddr = nvme_ctrl_get_host_traddr(c),
1006+
.host_iface = nvme_ctrl_get_trsvcid(c),
1007+
.trsvcid = nvme_ctrl_get_trsvcid(c),
1008+
.subsysnqn = NULL,
1009+
};
1010+
1011+
fc = __nvme_lookup_ctrl(s, &fctx, NULL);
10081012
if (fc) {
10091013
const char *key;
10101014

@@ -2439,7 +2443,6 @@ __public int nvmf_config_modify(struct nvme_global_ctx *ctx,
24392443
nvme_msg(ctx, LOG_ERR, "Failed to lookup controller\n");
24402444
return -ENODEV;
24412445
}
2442-
24432446
if (fctx->ctrlkey)
24442447
nvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey);
24452448

libnvme/src/nvme/private.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,9 @@ int __nvme_transport_handle_open_mi(struct nvme_transport_handle *hdl, const cha
381381
int __nvme_transport_handle_init_mi(struct nvme_transport_handle *hdl);
382382
void __nvme_transport_handle_close_mi(struct nvme_transport_handle *hdl);
383383

384-
nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
385-
const char *traddr, const char *host_traddr,
386-
const char *host_iface, const char *trsvcid,
387-
const char *subsysnqn, nvme_ctrl_t p);
384+
nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s,
385+
struct nvmf_context *fctx,
386+
nvme_ctrl_t p);
388387

389388
void *__nvme_alloc(size_t len);
390389

libnvme/src/nvme/tree.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,19 +1437,18 @@ static ctrl_match_t _candidate_init(struct nvme_global_ctx *ctx,
14371437
return _match_ctrl;
14381438
}
14391439

1440-
nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
1441-
const char *traddr, const char *host_traddr,
1442-
const char *host_iface, const char *trsvcid,
1443-
const char *subsysnqn, nvme_ctrl_t p)
1440+
nvme_ctrl_t __nvme_lookup_ctrl(nvme_subsystem_t s, struct nvmf_context *fctx,
1441+
nvme_ctrl_t p)
14441442
{
14451443
struct candidate_args candidate = {};
14461444
struct nvme_ctrl *c, *matching_c = NULL;
14471445
ctrl_match_t ctrl_match;
14481446

14491447
/* Init candidate and get the matching function to use */
1450-
ctrl_match = _candidate_init(s->h->ctx, &candidate, transport, traddr,
1451-
trsvcid, subsysnqn, host_traddr,
1452-
host_iface);
1448+
ctrl_match = _candidate_init(s->h->ctx, &candidate,
1449+
fctx->transport, fctx->traddr,
1450+
fctx->trsvcid, fctx->subsysnqn,
1451+
fctx->host_traddr, fctx->host_iface);
14531452

14541453
c = p ? nvme_subsystem_next_ctrl(s, p) : nvme_subsystem_first_ctrl(s);
14551454
for (; c != NULL; c = nvme_subsystem_next_ctrl(s, c)) {
@@ -1483,8 +1482,16 @@ nvme_ctrl_t nvme_ctrl_find(nvme_subsystem_t s, const char *transport,
14831482
const char *subsysnqn, const char *host_traddr,
14841483
const char *host_iface)
14851484
{
1486-
return __nvme_lookup_ctrl(s, transport, traddr, host_traddr, host_iface,
1487-
trsvcid, subsysnqn, NULL/*p*/);
1485+
struct nvmf_context fctx = {
1486+
.transport = transport,
1487+
.traddr = traddr,
1488+
.host_traddr = host_traddr,
1489+
.host_iface = host_iface,
1490+
.trsvcid = trsvcid,
1491+
.subsysnqn = subsysnqn,
1492+
};
1493+
1494+
return __nvme_lookup_ctrl(s, &fctx, NULL/*p*/);
14881495
}
14891496

14901497
nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
@@ -1499,8 +1506,16 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
14991506
if (!s || !transport)
15001507
return NULL;
15011508

1502-
c = __nvme_lookup_ctrl(s, transport, traddr, host_traddr,
1503-
host_iface, trsvcid, NULL, p);
1509+
struct nvmf_context fctx = {
1510+
.transport = transport,
1511+
.traddr = traddr,
1512+
.host_traddr = host_traddr,
1513+
.host_iface = host_iface,
1514+
.trsvcid = trsvcid,
1515+
.subsysnqn = NULL,
1516+
};
1517+
1518+
c = __nvme_lookup_ctrl(s, &fctx, p);
15041519
if (c)
15051520
return c;
15061521

0 commit comments

Comments
 (0)