Skip to content

Commit 9552455

Browse files
committed
fabrics: move host_traddr and host_iface to ctrl
The host_traddr and host_iface are property of the controller not of the fabric configuration. Because the discovery API was stable, it ended up in the fabric configuration. The discovery API is reworked thus we can move it to where it actually belongs. See also 9a4dd38 ("Move 'host_traddr' and 'host_iface' into fabrics configuration"). Signed-off-by: Daniel Wagner <[email protected]>
1 parent 9859262 commit 9552455

7 files changed

Lines changed: 98 additions & 91 deletions

File tree

fabrics.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ static const char *nvmf_context = "execution context identification string";
100100
OPT_STRING("nqn", 'n', "STR", &subsysnqn, nvmf_nqn), \
101101
OPT_STRING("traddr", 'a', "STR", &traddr, nvmf_traddr), \
102102
OPT_STRING("trsvcid", 's', "STR", &trsvcid, nvmf_trsvcid), \
103-
OPT_STRING("host-traddr", 'w', "STR", &c.host_traddr, nvmf_htraddr), \
104-
OPT_STRING("host-iface", 'f', "STR", &c.host_iface, nvmf_hiface), \
103+
OPT_STRING("host-traddr", 'w', "STR", &host_traddr, nvmf_htraddr), \
104+
OPT_STRING("host-iface", 'f', "STR", &host_iface, nvmf_hiface), \
105105
OPT_STRING("hostnqn", 'q', "STR", &hostnqn, nvmf_hostnqn), \
106106
OPT_STRING("hostid", 'I', "STR", &hostid, nvmf_hostid), \
107107
OPT_STRING("dhchap-secret", 'S', "STR", &hostkey, nvmf_hostkey), \
@@ -369,6 +369,7 @@ static void nvmf_connected(struct nvmf_discovery_ctx *dctx,
369369

370370
static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
371371
bool persistent,
372+
const char *host_traddr, const char *host_iface,
372373
struct nvme_fabrics_config *defcfg,
373374
void *user_data, struct nvmf_discovery_ctx **dctxp)
374375
{
@@ -407,6 +408,14 @@ static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
407408
if (err)
408409
goto err;
409410

411+
err = nvmf_discovery_ctx_host_traddr_set(dctx, host_traddr);
412+
if (err)
413+
goto err;
414+
415+
err = nvmf_discovery_ctx_host_iface_set(dctx, host_iface);
416+
if (err)
417+
goto err;
418+
410419
err = nvmf_discovery_ctx_default_fabrics_config_set(dctx, defcfg);
411420
if (err)
412421
goto err;
@@ -427,6 +436,7 @@ static int discover_from_conf_file(struct nvme_global_ctx *ctx, nvme_host_t h,
427436
char *hostnqn = NULL, *hostid = NULL, *hostkey = NULL;
428437
char *subsysnqn = NULL, *keyring = NULL, *tls_key = NULL;
429438
_cleanup_free_ struct nvmf_discovery_ctx *dctx = NULL;
439+
char *host_iface = NULL, *host_traddr = NULL;
430440
char *tls_key_identity = NULL;
431441
char *ptr, **argv, *p, line[4096];
432442
int argc, ret = 0;
@@ -491,16 +501,17 @@ static int discover_from_conf_file(struct nvme_global_ctx *ctx, nvme_host_t h,
491501
.subsysnqn = subsysnqn,
492502
.transport = transport,
493503
.traddr = traddr,
494-
.host_traddr = cfg.host_traddr,
495-
.host_iface = cfg.host_iface,
504+
.host_traddr = host_traddr,
505+
.host_iface = host_iface,
496506
.trsvcid = trsvcid,
497507
};
498508

499509
struct cb_discovery_log_data dld = {
500510
.flags = flags,
501511
.raw = raw,
502512
};
503-
ret = create_discovery_log_ctx(ctx, true, &cfg, &dld, &dctx);
513+
ret = create_discovery_log_ctx(ctx, true, host_traddr,
514+
host_iface, &cfg, &dld, &dctx);
504515
if (ret)
505516
return ret;
506517

@@ -581,6 +592,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
581592
char *subsysnqn = NVME_DISC_SUBSYS_NAME;
582593
char *hostnqn = NULL, *hostid = NULL, *hostkey = NULL;
583594
char *transport = NULL, *traddr = NULL, *trsvcid = NULL;
595+
char *host_iface = NULL, *host_traddr = NULL;
584596
char *keyring = NULL, *tls_key = NULL;
585597
char *tls_key_identity = NULL;
586598
char *config_file = PATH_NVMF_CONFIG;
@@ -680,7 +692,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
680692
.raw = raw,
681693
};
682694

683-
ret = create_discovery_log_ctx(ctx, persistent, &cfg, &dld, &dctx);
695+
ret = create_discovery_log_ctx(ctx, persistent, host_traddr,
696+
host_iface, &cfg, &dld, &dctx);
684697
if (ret)
685698
return ret;
686699

@@ -709,8 +722,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
709722
.subsysnqn = subsysnqn,
710723
.transport = transport,
711724
.traddr = traddr,
712-
.host_traddr = cfg.host_traddr,
713-
.host_iface = cfg.host_iface,
725+
.host_traddr = host_traddr,
726+
.host_iface = host_iface,
714727
.trsvcid = trsvcid,
715728
};
716729

@@ -719,7 +732,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
719732
if (!ret) {
720733
/* Check if device matches command-line options */
721734
if (!nvme_ctrl_config_match(c, transport, traddr, trsvcid, subsysnqn,
722-
cfg.host_traddr, cfg.host_iface)) {
735+
host_traddr, host_iface)) {
723736
fprintf(stderr,
724737
"ctrl device %s found, ignoring non matching command-line options\n",
725738
device);
@@ -750,10 +763,10 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
750763
* for the udev rules). This ensures that host-traddr/
751764
* host-iface are consistent with the discovery controller (c).
752765
*/
753-
if (!cfg.host_traddr)
754-
cfg.host_traddr = (char *)nvme_ctrl_get_host_traddr(c);
755-
if (!cfg.host_iface)
756-
cfg.host_iface = (char *)nvme_ctrl_get_host_iface(c);
766+
if (!host_traddr)
767+
host_traddr = (char *)nvme_ctrl_get_host_traddr(c);
768+
if (!host_iface)
769+
host_iface = (char *)nvme_ctrl_get_host_iface(c);
757770
}
758771
} else {
759772
/*
@@ -830,6 +843,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
830843
char *trsvcid = NULL, *hostnqn = NULL, *hostid = NULL;
831844
char *hostkey = NULL, *ctrlkey = NULL, *keyring = NULL;
832845
char *tls_key = NULL, *tls_key_identity = NULL;
846+
char *host_iface = NULL, *host_traddr = NULL;
833847
_cleanup_free_ char *hnqn = NULL;
834848
_cleanup_free_ char *hid = NULL;
835849
char *config_file = NULL;
@@ -929,8 +943,8 @@ int nvmf_connect(const char *desc, int argc, char **argv)
929943
.subsysnqn = subsysnqn,
930944
.transport = transport,
931945
.traddr = traddr,
932-
.host_traddr = cfg.host_traddr,
933-
.host_iface = cfg.host_iface,
946+
.host_traddr = host_traddr,
947+
.host_iface = host_iface,
934948
.trsvcid = trsvcid,
935949
};
936950

@@ -941,7 +955,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
941955
}
942956

943957
ret = nvme_create_ctrl(ctx, subsysnqn, transport, traddr,
944-
cfg.host_traddr, cfg.host_iface, trsvcid, &c);
958+
host_traddr, host_iface, trsvcid, &c);
945959
if (ret)
946960
return ret;
947961

@@ -1184,6 +1198,7 @@ int nvmf_config(const char *desc, int argc, char **argv)
11841198
char *subsysnqn = NULL;
11851199
char *transport = NULL, *traddr = NULL;
11861200
char *trsvcid = NULL, *hostnqn = NULL, *hostid = NULL;
1201+
char *host_traddr = NULL, *host_iface = NULL;
11871202
_cleanup_free_ char *hnqn = NULL;
11881203
_cleanup_free_ char *hid = NULL;
11891204
char *hostkey = NULL, *ctrlkey = NULL;
@@ -1270,7 +1285,7 @@ int nvmf_config(const char *desc, int argc, char **argv)
12701285
return -ENODEV;
12711286
}
12721287
c = nvme_lookup_ctrl(s, transport, traddr,
1273-
cfg.host_traddr, cfg.host_iface,
1288+
host_traddr, host_iface,
12741289
trsvcid, NULL);
12751290
if (!c) {
12761291
fprintf(stderr, "Failed to lookup controller\n");

libnvme/libnvme/nvme.i

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@ PyObject *hostid_from_file();
110110
temp.tos = -1;
111111
temp.ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO;
112112
while (PyDict_Next($input, &pos, &key, &value)) {
113-
if (!PyUnicode_CompareWithASCIIString(key, "host_traddr")) {
114-
temp.host_traddr = PyBytes_AsString(value);
115-
continue;
116-
}
117-
if (!PyUnicode_CompareWithASCIIString(key, "host_iface")) {
118-
temp.host_iface = PyBytes_AsString(value);
119-
continue;
120-
}
121113
if (!PyUnicode_CompareWithASCIIString(key, "nr_io_queues")) {
122114
temp.nr_io_queues = PyLong_AsLong(value);
123115
continue;

libnvme/src/libnvme.map

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ LIBNVME_2_0 {
290290
nvmf_cms_str;
291291
nvmf_connect_config_json;
292292
nvmf_connect_ctrl;
293-
nvmf_connect_disc_entry;
294293
nvmf_default_config;
295294
nvmf_discovery;
296295
nvmf_discovery_config_json;
@@ -300,6 +299,8 @@ LIBNVME_2_0 {
300299
nvmf_discovery_ctx_decide_retry_set;
301300
nvmf_discovery_ctx_default_fabrics_config_set;
302301
nvmf_discovery_ctx_discovery_log_set;
302+
nvmf_discovery_ctx_host_iface_set;
303+
nvmf_discovery_ctx_host_traddr_set;
303304
nvmf_discovery_ctx_keep_alive_timeout;
304305
nvmf_discovery_ctx_max_retries;
305306
nvmf_discovery_ctx_persistent_set;

libnvme/src/nvme/fabrics.c

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,22 @@ int nvmf_discovery_ctx_persistent_set(struct nvmf_discovery_ctx *dctx,
272272
return 0;
273273
}
274274

275+
int nvmf_discovery_ctx_host_traddr_set(struct nvmf_discovery_ctx *dctx,
276+
const char *host_traddr)
277+
{
278+
dctx->host_traddr = host_traddr;
279+
280+
return 0;
281+
}
282+
283+
int nvmf_discovery_ctx_host_iface_set(struct nvmf_discovery_ctx *dctx,
284+
const char *host_iface)
285+
{
286+
dctx->host_iface = host_iface;
287+
288+
return 0;
289+
}
290+
275291
int nvmf_discovery_ctx_default_fabrics_config_set(
276292
struct nvmf_discovery_ctx *dctx,
277293
struct nvme_fabrics_config *defcfg)
@@ -321,15 +337,11 @@ void nvmf_default_config(struct nvme_fabrics_config *cfg)
321337

322338
#define MERGE_CFG_OPTION(c, n, o, d) \
323339
if ((c)->o == d) (c)->o = (n)->o
324-
#define MERGE_CFG_OPTION_STR(c, n, o, d) \
325-
if ((c)->o == d && (n)->o) (c)->o = strdup((n)->o)
326340
static struct nvme_fabrics_config *merge_config(nvme_ctrl_t c,
327341
const struct nvme_fabrics_config *cfg)
328342
{
329343
struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c);
330344

331-
MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_traddr, NULL);
332-
MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_iface, NULL);
333345
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0);
334346
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0);
335347
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_poll_queues, 0);
@@ -358,8 +370,6 @@ void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg)
358370
{
359371
struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c);
360372

361-
UPDATE_CFG_OPTION(ctrl_cfg, cfg, host_traddr, NULL);
362-
UPDATE_CFG_OPTION(ctrl_cfg, cfg, host_iface, NULL);
363373
UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0);
364374
UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0);
365375
UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_poll_queues, 0);
@@ -723,9 +733,9 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
723733
add_argument(ctx, argstr, traddr,
724734
nvme_ctrl_get_traddr(c)) ||
725735
add_argument(ctx, argstr, host_traddr,
726-
cfg->host_traddr) ||
736+
nvme_ctrl_get_host_traddr(c)) ||
727737
add_argument(ctx, argstr, host_iface,
728-
cfg->host_iface) ||
738+
nvme_ctrl_get_host_iface(c)) ||
729739
add_argument(ctx, argstr, trsvcid,
730740
nvme_ctrl_get_trsvcid(c)) ||
731741
(hostnqn && add_argument(ctx, argstr, hostnqn, hostnqn)) ||
@@ -1071,14 +1081,14 @@ int nvmf_connect_ctrl(nvme_ctrl_t c)
10711081
return 0;
10721082
}
10731083

1074-
int nvmf_connect_disc_entry(nvme_host_t h,
1075-
struct nvmf_disc_log_entry *e,
1076-
const struct nvme_fabrics_config *cfg,
1077-
bool *discover,
1078-
nvme_ctrl_t *cp)
1084+
static int nvmf_connect_disc_entry(nvme_host_t h,
1085+
struct nvmf_disc_log_entry *e,
1086+
const char *host_traddr, const char *host_iface,
1087+
const struct nvme_fabrics_config *cfg,
1088+
bool *discover, nvme_ctrl_t *cp)
10791089
{
1080-
const char *transport;
10811090
char *traddr = NULL, *trsvcid = NULL;
1091+
const char *transport;
10821092
nvme_ctrl_t c;
10831093
int ret;
10841094

@@ -1126,7 +1136,7 @@ int nvmf_connect_disc_entry(nvme_host_t h,
11261136
transport, traddr, trsvcid);
11271137

11281138
ret = nvme_create_ctrl(h->ctx, e->subnqn, transport, traddr,
1129-
cfg->host_traddr, cfg->host_iface, trsvcid, &c);
1139+
host_traddr, host_iface, trsvcid, &c);
11301140
if (ret) {
11311141
nvme_msg(h->ctx, LOG_DEBUG, "skipping discovery entry, "
11321142
"failed to allocate %s controller with traddr %s\n",
@@ -2079,8 +2089,8 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_discovery_ctx *dctx,
20792089
.subsysnqn = e->subnqn,
20802090
.transport = nvmf_trtype_str(e->trtype),
20812091
.traddr = e->traddr,
2082-
.host_traddr = dctx->defcfg->host_traddr,
2083-
.host_iface = dctx->defcfg->host_iface,
2092+
.host_traddr = dctx->host_traddr,
2093+
.host_iface = dctx->host_iface,
20842094
.trsvcid = e->trsvcid,
20852095
};
20862096

@@ -2127,8 +2137,9 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_discovery_ctx *dctx,
21272137
disconnect = false;
21282138
}
21292139

2130-
err = nvmf_connect_disc_entry(h, e, dctx->defcfg,
2131-
&discover, &child);
2140+
err = nvmf_connect_disc_entry(h, e, dctx->host_traddr,
2141+
dctx->host_iface, dctx->defcfg,
2142+
&discover, &child);
21322143

21332144
dctx->defcfg->keep_alive_tmo = tmo;
21342145

@@ -2633,8 +2644,8 @@ static int nbft_discovery(struct nvme_global_ctx *ctx,
26332644
.subsysnqn = e->subnqn,
26342645
.transport = nvmf_trtype_str(e->trtype),
26352646
.traddr = e->traddr,
2636-
.host_traddr = deftrcfg->host_traddr,
2637-
.host_iface = deftrcfg->host_iface,
2647+
.host_traddr = dctx->host_traddr,
2648+
.host_iface = dctx->host_iface,
26382649
.trsvcid = e->trsvcid,
26392650
};
26402651

@@ -2654,8 +2665,8 @@ static int nbft_discovery(struct nvme_global_ctx *ctx,
26542665
if (e->subtype == NVME_NQN_DISC) {
26552666
nvme_ctrl_t child;
26562667

2657-
ret = nvmf_connect_disc_entry(h, e, defcfg,
2658-
NULL, &child);
2668+
ret = nvmf_connect_disc_entry(h, e, dctx->host_traddr,
2669+
dctx->host_iface, defcfg, NULL, &child);
26592670
if (ret)
26602671
continue;
26612672
nbft_discovery(ctx, dctx, dd, h, child, defcfg, &trcfg);
@@ -2769,7 +2780,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
27692780
}
27702781

27712782
host_traddr = NULL;
2772-
if (!cfg->host_traddr &&
2783+
if (!dctx->host_traddr &&
27732784
!strncmp((*ss)->transport, "tcp", 3))
27742785
host_traddr = hfi->tcp_info.ipaddr;
27752786

@@ -2850,7 +2861,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
28502861
continue;
28512862

28522863
host_traddr = NULL;
2853-
if (!cfg->host_traddr &&
2864+
if (!dctx->host_traddr &&
28542865
!strncmp(uri->protocol, "tcp", 3))
28552866
host_traddr = hfi->tcp_info.ipaddr;
28562867
if (uri->port > 0) {

libnvme/src/nvme/fabrics.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ int nvmf_discovery_ctx_connected_set(struct nvmf_discovery_ctx *dctx,
4848
struct nvme_ctrl *c, void *user_data));
4949
int nvmf_discovery_ctx_persistent_set(struct nvmf_discovery_ctx *dctx,
5050
bool persistent);
51+
int nvmf_discovery_ctx_host_traddr_set(struct nvmf_discovery_ctx *dctx,
52+
const char *host_traddr);
53+
int nvmf_discovery_ctx_host_iface_set(struct nvmf_discovery_ctx *dctx,
54+
const char *host_iface);
5155
int nvmf_discovery_ctx_default_fabrics_config_set(
5256
struct nvmf_discovery_ctx *dctx,
5357
struct nvme_fabrics_config *defcfg);
5458

5559
/**
5660
* struct nvme_fabrics_config - Defines all linux nvme fabrics initiator options
57-
* @host_traddr: Host transport address
58-
* @host_iface: Host interface name
5961
* @queue_size: Number of IO queue entries
6062
* @nr_io_queues: Number of controller IO queues to establish
6163
* @reconnect_delay: Time between two consecutive reconnect attempts.
@@ -76,8 +78,6 @@ int nvmf_discovery_ctx_default_fabrics_config_set(
7678
* @concat: Enable secure concatenation (TCP)
7779
*/
7880
struct nvme_fabrics_config {
79-
char *host_traddr;
80-
char *host_iface;
8181
int queue_size;
8282
int nr_io_queues;
8383
int reconnect_delay;
@@ -367,22 +367,6 @@ char *nvmf_hostnqn_from_file();
367367
*/
368368
char *nvmf_hostid_from_file();
369369

370-
/**
371-
* nvmf_connect_disc_entry() - Connect controller based on the discovery log page entry
372-
* @h: Host to which the controller should be connected
373-
* @e: Discovery log page entry
374-
* @defcfg: Default configuration to be used for the new controller
375-
* @discover: Set to 'true' if the new controller is a discovery controller
376-
* @c: crtl object to return
377-
*
378-
* Return: 0 on success, or an error code on failure.
379-
*/
380-
int nvmf_connect_disc_entry(nvme_host_t h,
381-
struct nvmf_disc_log_entry *e,
382-
const struct nvme_fabrics_config *defcfg,
383-
bool *discover,
384-
nvme_ctrl_t *c);
385-
386370
/**
387371
* nvmf_is_registration_supported - check whether registration can be performed.
388372
* @c: Controller instance

0 commit comments

Comments
 (0)