Skip to content

Commit 9ba7489

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 a994a52 commit 9ba7489

7 files changed

Lines changed: 98 additions & 90 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), \
@@ -368,6 +368,7 @@ static void nvmf_connected(struct nvmf_discovery_ctx *dctx,
368368

369369
static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
370370
bool persistent,
371+
const char *host_traddr, const char *host_iface,
371372
struct nvme_fabrics_config *defcfg,
372373
void *user_data, struct nvmf_discovery_ctx **dctxp)
373374
{
@@ -406,6 +407,14 @@ static int create_discovery_log_ctx(struct nvme_global_ctx *ctx,
406407
if (err)
407408
goto err;
408409

410+
err = nvmf_discovery_ctx_host_traddr_set(dctx, host_traddr);
411+
if (err)
412+
goto err;
413+
414+
err = nvmf_discovery_ctx_host_iface_set(dctx, host_iface);
415+
if (err)
416+
goto err;
417+
409418
err = nvmf_discovery_ctx_default_fabrics_config_set(dctx, defcfg);
410419
if (err)
411420
goto err;
@@ -426,6 +435,7 @@ static int discover_from_conf_file(struct nvme_global_ctx *ctx, nvme_host_t h,
426435
char *hostnqn = NULL, *hostid = NULL, *hostkey = NULL;
427436
char *subsysnqn = NULL, *keyring = NULL, *tls_key = NULL;
428437
_cleanup_free_ struct nvmf_discovery_ctx *dctx = NULL;
438+
char *host_iface = NULL, *host_traddr = NULL;
429439
char *tls_key_identity = NULL;
430440
char *ptr, **argv, *p, line[4096];
431441
int argc, ret = 0;
@@ -490,16 +500,17 @@ static int discover_from_conf_file(struct nvme_global_ctx *ctx, nvme_host_t h,
490500
.subsysnqn = subsysnqn,
491501
.transport = transport,
492502
.traddr = traddr,
493-
.host_traddr = cfg.host_traddr,
494-
.host_iface = cfg.host_iface,
503+
.host_traddr = host_traddr,
504+
.host_iface = host_iface,
495505
.trsvcid = trsvcid,
496506
};
497507

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

@@ -580,6 +591,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
580591
char *subsysnqn = NVME_DISC_SUBSYS_NAME;
581592
char *hostnqn = NULL, *hostid = NULL, *hostkey = NULL;
582593
char *transport = NULL, *traddr = NULL, *trsvcid = NULL;
594+
char *host_iface = NULL, *host_traddr = NULL;
583595
char *keyring = NULL, *tls_key = NULL;
584596
char *tls_key_identity = NULL;
585597
char *config_file = PATH_NVMF_CONFIG;
@@ -679,7 +691,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
679691
.raw = raw,
680692
};
681693

682-
ret = create_discovery_log_ctx(ctx, persistent, &cfg, &dld, &dctx);
694+
ret = create_discovery_log_ctx(ctx, persistent, host_traddr,
695+
host_iface, &cfg, &dld, &dctx);
683696
if (ret)
684697
return ret;
685698

@@ -708,8 +721,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
708721
.subsysnqn = subsysnqn,
709722
.transport = transport,
710723
.traddr = traddr,
711-
.host_traddr = cfg.host_traddr,
712-
.host_iface = cfg.host_iface,
724+
.host_traddr = host_traddr,
725+
.host_iface = host_iface,
713726
.trsvcid = trsvcid,
714727
};
715728

@@ -718,7 +731,7 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
718731
if (!ret) {
719732
/* Check if device matches command-line options */
720733
if (!nvme_ctrl_config_match(c, transport, traddr, trsvcid, subsysnqn,
721-
cfg.host_traddr, cfg.host_iface)) {
734+
host_traddr, host_iface)) {
722735
fprintf(stderr,
723736
"ctrl device %s found, ignoring non matching command-line options\n",
724737
device);
@@ -749,10 +762,10 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
749762
* for the udev rules). This ensures that host-traddr/
750763
* host-iface are consistent with the discovery controller (c).
751764
*/
752-
if (!cfg.host_traddr)
753-
cfg.host_traddr = (char *)nvme_ctrl_get_host_traddr(c);
754-
if (!cfg.host_iface)
755-
cfg.host_iface = (char *)nvme_ctrl_get_host_iface(c);
765+
if (!host_traddr)
766+
host_traddr = (char *)nvme_ctrl_get_host_traddr(c);
767+
if (!host_iface)
768+
host_iface = (char *)nvme_ctrl_get_host_iface(c);
756769
}
757770
} else {
758771
/*
@@ -829,6 +842,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
829842
char *trsvcid = NULL, *hostnqn = NULL, *hostid = NULL;
830843
char *hostkey = NULL, *ctrlkey = NULL, *keyring = NULL;
831844
char *tls_key = NULL, *tls_key_identity = NULL;
845+
char *host_iface = NULL, *host_traddr = NULL;
832846
_cleanup_free_ char *hnqn = NULL;
833847
_cleanup_free_ char *hid = NULL;
834848
char *config_file = NULL;
@@ -928,8 +942,8 @@ int nvmf_connect(const char *desc, int argc, char **argv)
928942
.subsysnqn = subsysnqn,
929943
.transport = transport,
930944
.traddr = traddr,
931-
.host_traddr = cfg.host_traddr,
932-
.host_iface = cfg.host_iface,
945+
.host_traddr = host_traddr,
946+
.host_iface = host_iface,
933947
.trsvcid = trsvcid,
934948
};
935949

@@ -940,7 +954,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
940954
}
941955

942956
ret = nvme_create_ctrl(ctx, subsysnqn, transport, traddr,
943-
cfg.host_traddr, cfg.host_iface, trsvcid, &c);
957+
host_traddr, host_iface, trsvcid, &c);
944958
if (ret)
945959
return ret;
946960

@@ -1183,6 +1197,7 @@ int nvmf_config(const char *desc, int argc, char **argv)
11831197
char *subsysnqn = NULL;
11841198
char *transport = NULL, *traddr = NULL;
11851199
char *trsvcid = NULL, *hostnqn = NULL, *hostid = NULL;
1200+
char *host_traddr = NULL, *host_iface = NULL;
11861201
_cleanup_free_ char *hnqn = NULL;
11871202
_cleanup_free_ char *hid = NULL;
11881203
char *hostkey = NULL, *ctrlkey = NULL;
@@ -1269,7 +1284,7 @@ int nvmf_config(const char *desc, int argc, char **argv)
12691284
return -ENODEV;
12701285
}
12711286
c = nvme_lookup_ctrl(s, transport, traddr,
1272-
cfg.host_traddr, cfg.host_iface,
1287+
host_traddr, host_iface,
12731288
trsvcid, NULL);
12741289
if (!c) {
12751290
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 & 24 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(struct nvmf_discovery_ctx *dctx,
276292
struct nvme_fabrics_config *defcfg)
277293
{
@@ -320,15 +336,11 @@ void nvmf_default_config(struct nvme_fabrics_config *cfg)
320336

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

330-
MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_traddr, NULL);
331-
MERGE_CFG_OPTION_STR(ctrl_cfg, cfg, host_iface, NULL);
332344
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0);
333345
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0);
334346
MERGE_CFG_OPTION(ctrl_cfg, cfg, nr_poll_queues, 0);
@@ -357,8 +369,6 @@ void nvmf_update_config(nvme_ctrl_t c, const struct nvme_fabrics_config *cfg)
357369
{
358370
struct nvme_fabrics_config *ctrl_cfg = nvme_ctrl_get_config(c);
359371

360-
UPDATE_CFG_OPTION(ctrl_cfg, cfg, host_traddr, NULL);
361-
UPDATE_CFG_OPTION(ctrl_cfg, cfg, host_iface, NULL);
362372
UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_io_queues, 0);
363373
UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_write_queues, 0);
364374
UPDATE_CFG_OPTION(ctrl_cfg, cfg, nr_poll_queues, 0);
@@ -722,9 +732,9 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
722732
add_argument(ctx, argstr, traddr,
723733
nvme_ctrl_get_traddr(c)) ||
724734
add_argument(ctx, argstr, host_traddr,
725-
cfg->host_traddr) ||
735+
nvme_ctrl_get_host_traddr(c)) ||
726736
add_argument(ctx, argstr, host_iface,
727-
cfg->host_iface) ||
737+
nvme_ctrl_get_host_iface(c)) ||
728738
add_argument(ctx, argstr, trsvcid,
729739
nvme_ctrl_get_trsvcid(c)) ||
730740
(hostnqn && add_argument(ctx, argstr, hostnqn, hostnqn)) ||
@@ -1070,14 +1080,14 @@ int nvmf_connect_ctrl(nvme_ctrl_t c)
10701080
return 0;
10711081
}
10721082

1073-
int nvmf_connect_disc_entry(nvme_host_t h,
1074-
struct nvmf_disc_log_entry *e,
1075-
const struct nvme_fabrics_config *cfg,
1076-
bool *discover,
1077-
nvme_ctrl_t *cp)
1083+
static int nvmf_connect_disc_entry(nvme_host_t h,
1084+
struct nvmf_disc_log_entry *e,
1085+
const char *host_traddr, const char *host_iface,
1086+
const struct nvme_fabrics_config *cfg,
1087+
bool *discover, nvme_ctrl_t *cp)
10781088
{
1079-
const char *transport;
10801089
char *traddr = NULL, *trsvcid = NULL;
1090+
const char *transport;
10811091
nvme_ctrl_t c;
10821092
int ret;
10831093

@@ -1125,7 +1135,7 @@ int nvmf_connect_disc_entry(nvme_host_t h,
11251135
transport, traddr, trsvcid);
11261136

11271137
ret = nvme_create_ctrl(h->ctx, e->subnqn, transport, traddr,
1128-
cfg->host_traddr, cfg->host_iface, trsvcid, &c);
1138+
host_traddr, host_iface, trsvcid, &c);
11291139
if (ret) {
11301140
nvme_msg(h->ctx, LOG_DEBUG, "skipping discovery entry, "
11311141
"failed to allocate %s controller with traddr %s\n",
@@ -2078,8 +2088,8 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_discovery_ctx *dctx,
20782088
.subsysnqn = e->subnqn,
20792089
.transport = nvmf_trtype_str(e->trtype),
20802090
.traddr = e->traddr,
2081-
.host_traddr = dctx->defcfg->host_traddr,
2082-
.host_iface = dctx->defcfg->host_iface,
2091+
.host_traddr = dctx->host_traddr,
2092+
.host_iface = dctx->host_iface,
20832093
.trsvcid = e->trsvcid,
20842094
};
20852095

@@ -2123,8 +2133,9 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_discovery_ctx *dctx,
21232133
disconnect = false;
21242134
}
21252135

2126-
err = nvmf_connect_disc_entry(h, e, dctx->defcfg,
2127-
&discover, &child);
2136+
err = nvmf_connect_disc_entry(h, e, dctx->host_traddr,
2137+
dctx->host_iface, dctx->defcfg,
2138+
&discover, &child);
21282139

21292140
dctx->defcfg->keep_alive_tmo = tmo;
21302141

@@ -2626,8 +2637,8 @@ static int nbft_discovery(struct nvme_global_ctx *ctx,
26262637
.subsysnqn = e->subnqn,
26272638
.transport = nvmf_trtype_str(e->trtype),
26282639
.traddr = e->traddr,
2629-
.host_traddr = deftrcfg->host_traddr,
2630-
.host_iface = deftrcfg->host_iface,
2640+
.host_traddr = dctx->host_traddr,
2641+
.host_iface = dctx->host_iface,
26312642
.trsvcid = e->trsvcid,
26322643
};
26332644

@@ -2647,7 +2658,8 @@ static int nbft_discovery(struct nvme_global_ctx *ctx,
26472658
if (e->subtype == NVME_NQN_DISC) {
26482659
nvme_ctrl_t child;
26492660

2650-
ret = nvmf_connect_disc_entry(h, e, defcfg, NULL, &child);
2661+
ret = nvmf_connect_disc_entry(h, e, dctx->host_traddr,
2662+
dctx->host_iface, defcfg, NULL, &child);
26512663
if (ret)
26522664
continue;
26532665
nbft_discovery(ctx, dctx, dd, h, child, defcfg, &trcfg);
@@ -2760,7 +2772,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
27602772
}
27612773

27622774
host_traddr = NULL;
2763-
if (!cfg->host_traddr &&
2775+
if (!dctx->host_traddr &&
27642776
!strncmp((*ss)->transport, "tcp", 3))
27652777
host_traddr = hfi->tcp_info.ipaddr;
27662778

@@ -2839,7 +2851,7 @@ int nvmf_discovery_nbft(struct nvme_global_ctx *ctx,
28392851
continue;
28402852

28412853
host_traddr = NULL;
2842-
if (!cfg->host_traddr &&
2854+
if (!dctx->host_traddr &&
28432855
!strncmp(uri->protocol, "tcp", 3))
28442856
host_traddr = hfi->tcp_info.ipaddr;
28452857
if (uri->port > 0) {

libnvme/src/nvme/fabrics.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,15 @@ 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(struct nvmf_discovery_ctx *dctx,
5256
struct nvme_fabrics_config *defcfg);
5357

5458
/**
5559
* struct nvme_fabrics_config - Defines all linux nvme fabrics initiator options
56-
* @host_traddr: Host transport address
57-
* @host_iface: Host interface name
5860
* @queue_size: Number of IO queue entries
5961
* @nr_io_queues: Number of controller IO queues to establish
6062
* @reconnect_delay: Time between two consecutive reconnect attempts.
@@ -75,8 +77,6 @@ int nvmf_discovery_ctx_default_fabrics_config_set(struct nvmf_discovery_ctx *dct
7577
* @concat: Enable secure concatenation (TCP)
7678
*/
7779
struct nvme_fabrics_config {
78-
char *host_traddr;
79-
char *host_iface;
8080
int queue_size;
8181
int nr_io_queues;
8282
int reconnect_delay;
@@ -366,22 +366,6 @@ char *nvmf_hostnqn_from_file();
366366
*/
367367
char *nvmf_hostid_from_file();
368368

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

0 commit comments

Comments
 (0)