Skip to content

Commit 39753b8

Browse files
Copilotigaw
andauthored
libnvme: embed libnvme_fabrics_config in libnvmf_context instead of pointer
Agent-Logs-Url: https://github.com/igaw/nvme-cli/sessions/85863804-294f-4e01-a099-c0a6103abb7a Co-authored-by: igaw <1050803+igaw@users.noreply.github.com>
1 parent da2f1b1 commit 39753b8

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

libnvme/src/nvme/fabrics.c

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ __public int libnvmf_context_set_discovery_defaults(struct libnvmf_context *fctx
255255
__public int libnvmf_context_set_fabrics_config(struct libnvmf_context *fctx,
256256
struct libnvme_fabrics_config *cfg)
257257
{
258-
fctx->cfg = cfg;
258+
fctx->cfg = *cfg;
259259

260260
return 0;
261261
}
@@ -2030,14 +2030,13 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx,
20302030
bool discover = false;
20312031
bool disconnect;
20322032
libnvme_ctrl_t child = { 0 };
2033-
int tmo = fctx->cfg->keep_alive_tmo;
2033+
int tmo = fctx->cfg.keep_alive_tmo;
20342034
struct libnvmf_context nfctx = *fctx;
20352035

20362036
nfctx.subsysnqn = e->subnqn;
20372037
nfctx.transport = libnvmf_trtype_str(e->trtype);
20382038
nfctx.traddr = e->traddr;
20392039
nfctx.trsvcid = e->trsvcid;
2040-
nfctx.cfg = fctx->cfg;
20412040

20422041
/* Already connected ? */
20432042
cl = lookup_ctrl(h, &nfctx);
@@ -2076,16 +2075,16 @@ static int _nvmf_discovery(struct libnvme_global_ctx *ctx,
20762075
disconnect = false;
20772076
}
20782077

2079-
set_discovery_kato(&nfctx, fctx->cfg);
2078+
set_discovery_kato(&nfctx, &nfctx.cfg);
20802079
} else {
20812080
/* NVME_NQN_NVME */
20822081
disconnect = false;
20832082
}
20842083

2085-
err = nvmf_connect_disc_entry(h, e, &nfctx, nfctx.cfg,
2084+
err = nvmf_connect_disc_entry(h, e, &nfctx, &nfctx.cfg,
20862085
&discover, &child);
20872086

2088-
nfctx.cfg->keep_alive_tmo = tmo;
2087+
nfctx.cfg.keep_alive_tmo = tmo;
20892088

20902089
if (!child) {
20912090
if (discover)
@@ -2300,7 +2299,7 @@ int _discovery_config_json(struct libnvme_global_ctx *ctx,
23002299
if (libnvme_ctrl_get_persistent(c))
23012300
nfctx.persistent = true;
23022301

2303-
memcpy(&cfg, fctx->cfg, sizeof(cfg));
2302+
cfg = fctx->cfg;
23042303

23052304
if (!force) {
23062305
cn = lookup_ctrl(h, &nfctx);
@@ -2464,7 +2463,7 @@ __public int libnvmf_discovery_config_file(struct libnvme_global_ctx *ctx,
24642463
}
24652464
}
24662465

2467-
err = nvmf_create_discovery_ctrl(ctx, &nfctx, h, fctx->cfg,
2466+
err = nvmf_create_discovery_ctrl(ctx, &nfctx, h, &fctx->cfg,
24682467
&c);
24692468
if (err)
24702469
continue;
@@ -2524,9 +2523,9 @@ __public int libnvmf_config_modify(struct libnvme_global_ctx *ctx,
25242523
libnvme_ctrl_set_dhchap_ctrl_key(c, fctx->ctrlkey);
25252524

25262525
nvme_parse_tls_args(fctx->keyring, fctx->tls_key,
2527-
fctx->tls_key_identity, fctx->cfg, c);
2526+
fctx->tls_key_identity, &fctx->cfg, c);
25282527

2529-
libnvmf_update_config(c, fctx->cfg);
2528+
libnvmf_update_config(c, &fctx->cfg);
25302529

25312530
return 0;
25322531
}
@@ -2859,7 +2858,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx,
28592858
nfctx.host_iface = NULL;
28602859

28612860
rr = nbft_connect(ctx, &nfctx, h, NULL,
2862-
*ss, fctx->cfg);
2861+
*ss, &fctx->cfg);
28632862

28642863
/*
28652864
* With TCP/DHCP, it can happen that the OS
@@ -2872,7 +2871,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx,
28722871
nfctx.host_traddr = NULL;
28732872

28742873
rr = nbft_connect(ctx, &nfctx, h, NULL,
2875-
*ss, fctx->cfg);
2874+
*ss, &fctx->cfg);
28762875

28772876
if (rr == 0)
28782877
libnvme_msg(ctx, LOG_INFO,
@@ -2954,13 +2953,13 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx,
29542953

29552954
if (!c) {
29562955
ret = nvmf_create_discovery_ctrl(ctx, &nfctx,
2957-
h, fctx->cfg, &c);
2956+
h, &fctx->cfg, &c);
29582957
if (ret == -ENVME_CONNECT_ADDRNOTAVAIL &&
29592958
!strcmp(nfctx.transport, "tcp") &&
29602959
strlen(hfi->tcp_info.dhcp_server_ipaddr) > 0) {
29612960
nfctx.traddr = NULL;
29622961
ret = nvmf_create_discovery_ctrl(ctx,
2963-
&nfctx, h, fctx->cfg, &c);
2962+
&nfctx, h, &fctx->cfg, &c);
29642963
}
29652964
} else
29662965
ret = 0;
@@ -2972,7 +2971,7 @@ __public int libnvmf_discovery_nbft(struct libnvme_global_ctx *ctx,
29722971
goto out_free;
29732972
}
29742973

2975-
rr = nbft_discovery(ctx, &nfctx, *dd, h, c, fctx->cfg);
2974+
rr = nbft_discovery(ctx, &nfctx, *dd, h, c, &fctx->cfg);
29762975
if (!persistent)
29772976
libnvme_disconnect_ctrl(c);
29782977
libnvme_free_ctrl(c);
@@ -3064,7 +3063,7 @@ __public int libnvmf_discovery(struct libnvme_global_ctx *ctx, struct libnvmf_co
30643063
}
30653064
if (!c) {
30663065
/* No device or non-matching device, create a new controller */
3067-
ret = nvmf_create_discovery_ctrl(ctx, fctx, h, fctx->cfg, &c);
3066+
ret = nvmf_create_discovery_ctrl(ctx, fctx, h, &fctx->cfg, &c);
30683067
if (ret) {
30693068
if (ret != -ENVME_CONNECT_IGNORED)
30703069
libnvme_msg(ctx, LOG_ERR,
@@ -3097,7 +3096,7 @@ __public int libnvmf_connect(struct libnvme_global_ctx *ctx, struct libnvmf_cont
30973096
return err;
30983097

30993098
c = lookup_ctrl(h, fctx);
3100-
if (c && libnvme_ctrl_get_name(c) && !fctx->cfg->duplicate_connect) {
3099+
if (c && libnvme_ctrl_get_name(c) && !fctx->cfg.duplicate_connect) {
31013100
fctx->already_connected(fctx, h, libnvme_ctrl_get_subsysnqn(c),
31023101
libnvme_ctrl_get_transport(c), libnvme_ctrl_get_traddr(c),
31033102
libnvme_ctrl_get_trsvcid(c), fctx->user_data);
@@ -3115,7 +3114,7 @@ __public int libnvmf_connect(struct libnvme_global_ctx *ctx, struct libnvmf_cont
31153114
}
31163115

31173116
nvme_parse_tls_args(fctx->keyring, fctx->tls_key,
3118-
fctx->tls_key_identity, fctx->cfg, c);
3117+
fctx->tls_key_identity, &fctx->cfg, c);
31193118

31203119
/*
31213120
* We are connecting to a discovery controller, so let's treat
@@ -3124,10 +3123,10 @@ __public int libnvmf_connect(struct libnvme_global_ctx *ctx, struct libnvmf_cont
31243123
if (!strcmp(fctx->subsysnqn, NVME_DISC_SUBSYS_NAME)) {
31253124
fctx->persistent = true;
31263125

3127-
set_discovery_kato(fctx, fctx->cfg);
3126+
set_discovery_kato(fctx, &fctx->cfg);
31283127
}
31293128

3130-
err = libnvme_add_ctrl(fctx, h, c, fctx->cfg);
3129+
err = libnvme_add_ctrl(fctx, h, c, &fctx->cfg);
31313130
if (err) {
31323131
libnvme_msg(ctx, LOG_ERR, "could not add new controller: %s\n",
31333132
libnvme_strerror(-err));

libnvme/src/nvme/private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ struct libnvmf_context {
338338
/* common fabrics configuraiton */
339339
const char *device;
340340
bool persistent;
341-
struct libnvme_fabrics_config *cfg;
341+
struct libnvme_fabrics_config cfg;
342342

343343
/* connection configuration */
344344
const char *subsysnqn;

0 commit comments

Comments
 (0)