return 0;
}
+/* returns negative errno values */
int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
{
char *subsysnqn = NVME_DISC_SUBSYS_NAME;
if (ret < 0) {
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
- return ret;
+ return -errno;
}
ret = nvme_host_get_ids(r, hostnqn, hostid, &hnqn, &hid);
h = nvme_lookup_host(r, hnqn, hid);
if (!h) {
- ret = ENOMEM;
+ ret = -ENOMEM;
goto out_free;
}
if (!device && !transport && !traddr) {
if (!nonbft)
- discover_from_nbft(r, hostnqn, hostid,
- hnqn, hid, desc, connect,
- &cfg, nbft_path, flags, verbose);
-
+ ret = discover_from_nbft(r, hostnqn, hostid,
+ hnqn, hid, desc, connect,
+ &cfg, nbft_path, flags, verbose);
if (nbft)
goto out_free;
fprintf(stderr,
"failed to add controller, error %s\n",
nvme_strerror(errno));
- ret = errno;
+ ret = -errno;
goto out_free;
}
}
return 0;
}
+/* returns negative errno values */
int discover_from_nbft(nvme_root_t r, char *hostnqn_arg, char *hostid_arg,
char *hostnqn_sys, char *hostid_sys,
const char *desc, bool connect,
{
char *hostnqn = NULL, *hostid = NULL, *host_traddr = NULL;
nvme_host_t h;
- int ret, i;
+ int ret, rr, i;
struct list_head nbft_list;
struct nbft_file_entry *entry = NULL;
struct nbft_info_subsystem_ns **ss;
struct nbft_info_discovery **dd;
if (!connect)
- /* to do: print discovery-type info from NBFT tables */
+ /* TODO: print discovery-type info from NBFT tables */
return 0;
list_head_init(&nbft_list);
if (ret) {
if (ret != -ENOENT)
nvme_show_perror("Failed to access ACPI tables directory");
+ else
+ ret = 0; /* nothing to connect */
goto out_free;
}
}
h = nvme_lookup_host(r, hostnqn, hostid);
- if (!h)
+ if (!h) {
+ ret = -ENOENT;
goto out_free;
+ }
/* Subsystem Namespace Descriptor List */
for (ss = entry->nbft->subsystem_ns_list; ss && *ss; ss++)
.trsvcid = (*ss)->trsvcid,
};
- ret = do_connect(r, h, NULL, *ss, &trcfg,
- cfg, flags, verbose);
+ rr = do_connect(r, h, NULL, *ss, &trcfg,
+ cfg, flags, verbose);
/*
* With TCP/DHCP, it can happen that the OS
* obtains a different local IP address than the
* firmware had. Retry without host_traddr.
*/
- if (ret == -ENVME_CONNECT_ADDRNOTAVAIL &&
+ if (rr == -ENVME_CONNECT_ADDRNOTAVAIL &&
!strcmp(trcfg.transport, "tcp") &&
strlen(hfi->tcp_info.dhcp_server_ipaddr) > 0) {
trcfg.host_traddr = NULL;
- ret = do_connect(r, h, NULL, *ss, &trcfg,
- cfg, flags, verbose);
+ rr = do_connect(r, h, NULL, *ss, &trcfg,
+ cfg, flags, verbose);
- if (ret == 0 && verbose >= 1)
+ if (rr == 0 && verbose >= 1)
fprintf(stderr,
"SSNS %d: connect with host_traddr=\"%s\" failed, success after omitting host_traddr\n",
(*ss)->index,
host_traddr);
}
- if (ret)
+ if (rr) {
fprintf(stderr, "SSNS %d: no controller found\n",
(*ss)->index);
+ /* report an error */
+ ret = rr;
+ }
- if (ret == -ENOMEM)
+ if (rr == -ENOMEM)
goto out_free;
}
host_traddr = hfi->tcp_info.ipaddr;
if (uri->port > 0) {
if (asprintf(&trsvcid, "%d", uri->port) < 0) {
- errno = ENOMEM;
+ ret = -ENOMEM;
goto out_free;
}
} else
"Discovery Descriptor %d: failed to add discovery controller: %s\n",
(*dd)->index,
nvme_strerror(errno));
- if (errno == ENOMEM)
+ if (errno == ENOMEM) {
+ ret = -ENOMEM;
goto out_free;
+ }
continue;
}
- ret = do_discover(*dd, r, h, c, cfg, &trcfg,
- flags, verbose);
+ rr = do_discover(*dd, r, h, c, cfg, &trcfg,
+ flags, verbose);
if (!persistent)
nvme_disconnect_ctrl(c);
nvme_free_ctrl(c);
- if (ret == -ENOMEM)
+ if (rr == -ENOMEM) {
+ ret = rr;
goto out_free;
+ }
}
}
out_free:
free_nbfts(&nbft_list);
- return errno;
+ return ret;
}