Skip to content

Commit 927aac9

Browse files
committed
fabrics: connect all hosts in config.json
Iterate over all hosts defined in the config.json configuration file, instead just the default controller. Signed-off-by: Daniel Wagner <dwagner@suse.de>
1 parent b3b9963 commit 927aac9

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

fabrics.c

+33-9
Original file line numberDiff line numberDiff line change
@@ -588,20 +588,44 @@ static int _discover_from_json_config_file(nvme_root_t r, nvme_host_t h, nvme_su
588588
return ret;
589589
}
590590

591-
static int discover_from_json_config_file(nvme_root_t r, nvme_host_t h,
592-
const char *desc, bool connect,
591+
static int discover_from_json_config_file(nvme_root_t r, const char *hostnqn,
592+
const char *hostid, const char *desc,
593+
bool connect,
593594
const struct nvme_fabrics_config *defcfg,
594595
nvme_print_flags_t flags,
595596
bool force)
596597
{
598+
const char *hnqn, *hid;
599+
nvme_host_t h;
597600
nvme_subsystem_t s;
598601
nvme_ctrl_t c;
599-
int ret = 0;
602+
int ret = 0, err;
600603

601-
nvme_for_each_subsystem(h, s) {
602-
nvme_subsystem_for_each_ctrl(s, c) {
603-
ret = _discover_from_json_config_file(r, h, s, c, desc,
604-
connect, defcfg, flags, force);
604+
nvme_for_each_host(r, h) {
605+
nvme_for_each_subsystem(h, s) {
606+
hnqn = nvme_host_get_hostnqn(h);
607+
if (hostnqn && hnqn && strcmp(hostnqn, hnqn))
608+
continue;
609+
hid = nvme_host_get_hostid(h);
610+
if (hostid && hid && strcmp(hostid, hid))
611+
continue;
612+
613+
nvme_subsystem_for_each_ctrl(s, c) {
614+
err = _discover_from_json_config_file(
615+
r, h, s, c, desc, connect, defcfg,
616+
flags, force);
617+
618+
if (err) {
619+
fprintf(stderr,
620+
"failed to connect to hostnqn=%s,nqn=%s,%s\n",
621+
nvme_host_get_hostnqn(h),
622+
nvme_subsystem_get_name(s),
623+
nvme_ctrl_get_address(c));
624+
625+
if (!ret)
626+
ret = err;
627+
}
628+
}
605629
}
606630
}
607631

@@ -749,8 +773,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
749773
goto out_free;
750774

751775
if (json_config)
752-
ret = discover_from_json_config_file(r, h, desc,
753-
connect, &cfg,
776+
ret = discover_from_json_config_file(r, hostnqn, hostid,
777+
desc, connect, &cfg,
754778
flags, force);
755779
if (ret || access(PATH_NVMF_DISC, F_OK))
756780
goto out_free;

0 commit comments

Comments
 (0)