Skip to content

Commit f41bf84

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 e5d233b commit f41bf84

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
@@ -765,56 +765,6 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
765765
return ret;
766766
}
767767

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

945895
if (config_file)
946-
return nvme_connect_config(ctx, hostnqn, hostid, &cfg);
896+
return nvmf_connect_config_json(ctx, hostnqn, hostid, &cfg);
947897

948898
struct tr_config trcfg = {
949899
.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
@@ -2385,3 +2385,52 @@ int nvmf_discovery_config_json(struct nvme_global_ctx *ctx,
23852385

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

libnvme/src/nvme/fabrics.h

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

0 commit comments

Comments
 (0)