Skip to content

Commit

Permalink
fabrics: print an error for ENOENT too
Browse files Browse the repository at this point in the history
Many nvme commands such as discover, connect, connect-all, etc.
simply return to the prompt without printing any useful error
message when the respective nvme driver modules are not loaded in
the kernel. This is because nothing gets printed when
nvme_scan_topology() returns an ENOENT due to missing nvme system
files stemming from not loading the appropriate nvme modules.
Fix the same. Please note, we want to suppress this ENOENT error
for disconnect-all, hence this change doesn't apply to
disconnect-all here. And while we are it, ensure a zero is returned
if the errno is a ENOENT in this case.

Signed-off-by: Martin George <[email protected]>
  • Loading branch information
martin-gpy committed Jul 26, 2024
1 parent e99ee46 commit 24c4066
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
30 changes: 14 additions & 16 deletions fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,8 @@ int nvmf_discover(const char *desc, int argc, char **argv, bool connect)
nvme_root_skip_namespaces(r);
ret = nvme_scan_topology(r, NULL, NULL);
if (ret < 0) {
if (errno != ENOENT)
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
return ret;
}

Expand Down Expand Up @@ -958,9 +957,8 @@ int nvmf_connect(const char *desc, int argc, char **argv)
nvme_root_skip_namespaces(r);
ret = nvme_scan_topology(r, NULL, NULL);
if (ret < 0) {
if (errno != ENOENT)
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
return ret;
}

Expand Down Expand Up @@ -1107,9 +1105,8 @@ int nvmf_disconnect(const char *desc, int argc, char **argv)
nvme_root_skip_namespaces(r);
ret = nvme_scan_topology(r, NULL, NULL);
if (ret < 0) {
if (errno != ENOENT)
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
nvme_free_tree(r);
return ret;
}
Expand Down Expand Up @@ -1183,7 +1180,10 @@ int nvmf_disconnect_all(const char *desc, int argc, char **argv)
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
nvme_free_tree(r);
return ret;
if (errno != ENOENT)
return ret;
else
return 0;
}

nvme_for_each_host(r, h) {
Expand Down Expand Up @@ -1255,9 +1255,8 @@ int nvmf_config(const char *desc, int argc, char **argv)
nvme_root_skip_namespaces(r);
ret = nvme_scan_topology(r, NULL, NULL);
if (ret < 0) {
if (errno != ENOENT)
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
nvme_free_tree(r);
return ret;
}
Expand Down Expand Up @@ -1409,9 +1408,8 @@ int nvmf_dim(const char *desc, int argc, char **argv)
nvme_root_skip_namespaces(r);
ret = nvme_scan_topology(r, NULL, NULL);
if (ret < 0) {
if (errno != ENOENT)
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
fprintf(stderr, "Failed to scan topology: %s\n",
nvme_strerror(errno));
nvme_free_tree(r);
return ret;
}
Expand Down
9 changes: 3 additions & 6 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -3331,8 +3331,7 @@ static int list_subsys(int argc, char **argv, struct command *cmd,

err = nvme_scan_topology(r, filter, (void *)devname);
if (err) {
if (errno != ENOENT)
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
return -errno;
}

Expand Down Expand Up @@ -3370,8 +3369,7 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
}
err = nvme_scan_topology(r, NULL, NULL);
if (err < 0) {
if (errno != ENOENT)
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
return err;
}

Expand Down Expand Up @@ -9588,8 +9586,7 @@ static int show_topology_cmd(int argc, char **argv, struct command *command, str

err = nvme_scan_topology(r, NULL, NULL);
if (err < 0) {
if (errno != ENOENT)
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
nvme_free_tree(r);
return err;
}
Expand Down

0 comments on commit 24c4066

Please sign in to comment.