Skip to content

Commit e3140b0

Browse files
committed
tree: get global context directly
struct nvme_ns and struct nvme_ctrl both have now a global context pointer, no need for pointer chasing anymore. Signed-off-by: Daniel Wagner <[email protected]>
1 parent b39e119 commit e3140b0

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

libnvme/src/nvme/fabrics.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ static int nvmf_connect_disc_entry(nvme_host_t h,
12511251
static int nvme_discovery_log(const struct nvme_get_discovery_args *args,
12521252
struct nvmf_discovery_log **logp)
12531253
{
1254-
struct nvme_global_ctx *ctx = ctx_from_ctrl(args->c);
1254+
struct nvme_global_ctx *ctx = args->c->ctx;
12551255
struct nvmf_discovery_log *log;
12561256
int retries = 0;
12571257
int err;

libnvme/src/nvme/private.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,6 @@ __nvme_msg(struct nvme_global_ctx *ctx, int level, const char *func, const char
439439
#define nvme_msg(ctx, level, format, ...) \
440440
__nvme_msg(ctx, level, __nvme_log_func, format, ##__VA_ARGS__)
441441

442-
#define ctx_from_ctrl(c) ((c)->s && (c)->s->h ? (c)->s->h->ctx : NULL)
443-
#define ctx_from_ns(n) ((n)->s && (n)->s->h ? (n)->s->h->ctx : \
444-
(n)->c && (n)->c->s && (n)->c->s->h ? (n)->c->s->h->ctx : \
445-
NULL)
446-
447442
/* mi internal headers */
448443

449444
/* internal transport API */

libnvme/src/nvme/tree.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,12 +1043,11 @@ static int nvme_ctrl_scan_path(struct nvme_global_ctx *ctx, struct nvme_ctrl *c,
10431043
struct nvme_transport_handle *nvme_ctrl_get_transport_handle(nvme_ctrl_t c)
10441044
{
10451045
if (!c->hdl) {
1046-
struct nvme_global_ctx *ctx = ctx_from_ctrl(c);
10471046
int err;
10481047

1049-
err = nvme_open(ctx, c->name, &c->hdl);
1048+
err = nvme_open(c->ctx, c->name, &c->hdl);
10501049
if (err)
1051-
nvme_msg(ctx, LOG_ERR,
1050+
nvme_msg(c->ctx, LOG_ERR,
10521051
"Failed to open ctrl %s, errno %d\n",
10531052
c->name, err);
10541053
}
@@ -1104,7 +1103,7 @@ char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len)
11041103
p += strlen("src_addr=");
11051104
l = strcspn(p, ",%"); /* % to eliminate IPv6 scope (if present) */
11061105
if (l >= src_addr_len) {
1107-
nvme_msg(ctx_from_ctrl(c), LOG_ERR,
1106+
nvme_msg(c->ctx, LOG_ERR,
11081107
"Buffer for src_addr is too small (%zu must be > %zu)\n",
11091108
src_addr_len, l);
11101109
return NULL;
@@ -1514,7 +1513,7 @@ static bool _tcp_ctrl_match_host_traddr_no_src_addr(struct nvme_ctrl *c, struct
15141513
* 100% positive match. Regardless, let's be optimistic
15151514
* and assume that we have a match.
15161515
*/
1517-
nvme_msg(ctx_from_ctrl(c), LOG_DEBUG,
1516+
nvme_msg(c->ctx, LOG_DEBUG,
15181517
"Not enough data, but assume %s matches candidate's host_traddr: %s\n",
15191518
nvme_ctrl_get_name(c), candidate->host_traddr);
15201519

@@ -1554,7 +1553,7 @@ static bool _tcp_ctrl_match_host_iface_no_src_addr(struct nvme_ctrl *c, struct c
15541553
* 100% positive match. Regardless, let's be optimistic
15551554
* and assume that we have a match.
15561555
*/
1557-
nvme_msg(ctx_from_ctrl(c), LOG_DEBUG,
1556+
nvme_msg(c->ctx, LOG_DEBUG,
15581557
"Not enough data, but assume %s matches candidate's host_iface: %s\n",
15591558
nvme_ctrl_get_name(c), candidate->host_iface);
15601559

@@ -2358,12 +2357,11 @@ static int nvme_bytes_to_lba(nvme_ns_t n, off_t offset, size_t count,
23582357
struct nvme_transport_handle *nvme_ns_get_transport_handle(nvme_ns_t n)
23592358
{
23602359
if (!n->hdl) {
2361-
struct nvme_global_ctx *ctx = ctx_from_ns(n);
23622360
int err;
23632361

2364-
err = nvme_open(ctx, n->name, &n->hdl);
2362+
err = nvme_open(n->ctx, n->name, &n->hdl);
23652363
if (err)
2366-
nvme_msg(ctx, LOG_ERR,
2364+
nvme_msg(n->ctx, LOG_ERR,
23672365
"Failed to open ns %s, error %d\n",
23682366
n->name, err);
23692367
}

0 commit comments

Comments
 (0)