Skip to content

Commit 633cc91

Browse files
committed
fabrics: move connect config json code to the library
Move the connect config json code to the library. Signed-off-by: Daniel Wagner <[email protected]>
1 parent c1a1a70 commit 633cc91

4 files changed

Lines changed: 54 additions & 51 deletions

File tree

fabrics.c

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -766,56 +766,6 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
766766
return ret;
767767
}
768768

769-
static int nvme_connect_config(struct nvme_global_ctx *ctx, const char *hostnqn,
770-
const char *hostid,
771-
const struct nvme_fabrics_config *cfg)
772-
{
773-
const char *hnqn, *hid;
774-
const char *transport;
775-
nvme_host_t h;
776-
nvme_subsystem_t s;
777-
nvme_ctrl_t c, _c;
778-
int ret = 0, err;
779-
780-
nvme_for_each_host(ctx, h) {
781-
nvme_for_each_subsystem(h, s) {
782-
hnqn = nvme_host_get_hostnqn(h);
783-
if (hostnqn && hnqn && strcmp(hostnqn, hnqn))
784-
continue;
785-
hid = nvme_host_get_hostid(h);
786-
if (hostid && hid && strcmp(hostid, hid))
787-
continue;
788-
789-
nvme_subsystem_for_each_ctrl_safe(s, c, _c) {
790-
transport = nvme_ctrl_get_transport(c);
791-
792-
/* ignore none fabric transports */
793-
if (strcmp(transport, "tcp") &&
794-
strcmp(transport, "rdma") &&
795-
strcmp(transport, "fc"))
796-
continue;
797-
798-
err = nvmf_connect_ctrl(c);
799-
if (err) {
800-
if (err == -ENVME_CONNECT_ALREADY)
801-
continue;
802-
803-
fprintf(stderr,
804-
"failed to connect to hostnqn=%s,nqn=%s,%s\n",
805-
nvme_host_get_hostnqn(h),
806-
nvme_subsystem_get_name(s),
807-
nvme_ctrl_get_address(c));
808-
809-
if (!ret)
810-
ret = err;
811-
}
812-
}
813-
}
814-
}
815-
816-
return ret;
817-
}
818-
819769
static void nvme_parse_tls_args(const char *keyring, const char *tls_key,
820770
const char *tls_key_identity,
821771
struct nvme_fabrics_config *cfg, nvme_ctrl_t c)
@@ -944,7 +894,7 @@ int nvmf_connect(const char *desc, int argc, char **argv)
944894
trsvcid = nvmf_get_default_trsvcid(transport, false);
945895

946896
if (config_file)
947-
return nvme_connect_config(ctx, hostnqn, hostid, &cfg);
897+
return nvmf_connect_config_json(ctx, hostnqn, hostid, &cfg);
948898

949899
struct tr_config trcfg = {
950900
.subsysnqn = subsysnqn,

libnvme/src/libnvme.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ LIBNVME_2_0 {
288288
nvmf_add_ctrl;
289289
nvmf_adrfam_str;
290290
nvmf_cms_str;
291+
nvmf_connect_config_json;
291292
nvmf_connect_ctrl;
292293
nvmf_connect_disc_entry;
293294
nvmf_default_config;

libnvme/src/nvme/fabrics.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,3 +2389,52 @@ int nvmf_discovery_config_json(struct nvme_global_ctx *ctx,
23892389

23902390
return ret;
23912391
}
2392+
2393+
int nvmf_connect_config_json(struct nvme_global_ctx *ctx, const char *hostnqn,
2394+
const char *hostid, const struct nvme_fabrics_config *cfg)
2395+
{
2396+
const char *hnqn, *hid;
2397+
const char *transport;
2398+
nvme_host_t h;
2399+
nvme_subsystem_t s;
2400+
nvme_ctrl_t c, _c;
2401+
int ret = 0, err;
2402+
2403+
nvme_for_each_host(ctx, h) {
2404+
nvme_for_each_subsystem(h, s) {
2405+
hnqn = nvme_host_get_hostnqn(h);
2406+
if (hostnqn && hnqn && strcmp(hostnqn, hnqn))
2407+
continue;
2408+
hid = nvme_host_get_hostid(h);
2409+
if (hostid && hid && strcmp(hostid, hid))
2410+
continue;
2411+
2412+
nvme_subsystem_for_each_ctrl_safe(s, c, _c) {
2413+
transport = nvme_ctrl_get_transport(c);
2414+
2415+
/* ignore none fabric transports */
2416+
if (strcmp(transport, "tcp") &&
2417+
strcmp(transport, "rdma") &&
2418+
strcmp(transport, "fc"))
2419+
continue;
2420+
2421+
err = nvmf_connect_ctrl(c);
2422+
if (err) {
2423+
if (err == -ENVME_CONNECT_ALREADY)
2424+
continue;
2425+
2426+
fprintf(stderr,
2427+
"failed to connect to hostnqn=%s,nqn=%s,%s\n",
2428+
nvme_host_get_hostnqn(h),
2429+
nvme_subsystem_get_name(s),
2430+
nvme_ctrl_get_address(c));
2431+
2432+
if (!ret)
2433+
ret = err;
2434+
}
2435+
}
2436+
}
2437+
}
2438+
2439+
return ret;
2440+
}

libnvme/src/nvme/fabrics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,7 @@ int nvmf_discovery(struct nvme_global_ctx *ctx, struct nvmf_discovery_ctx *dctx,
440440
int nvmf_discovery_config_json(struct nvme_global_ctx *ctx,
441441
struct nvmf_discovery_ctx *dctx, const char *hostnqn,
442442
const char *hostid, bool connect, bool force);
443+
444+
int nvmf_connect_config_json(struct nvme_global_ctx *ctx, const char *hostnqn,
445+
const char *hostid, const struct nvme_fabrics_config *cfg);
443446
#endif /* _LIBNVME_FABRICS_H */

0 commit comments

Comments
 (0)