Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/nvme/fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ static struct nvmf_discovery_log *nvme_discovery_log(
nvme_root_t r = root_from_ctrl(args->c);
struct nvmf_discovery_log *log;
int retries = 0;
int err;
const char *name = nvme_ctrl_get_name(args->c);
uint64_t genctr, numrec;
int fd = nvme_ctrl_get_fd(args->c);
Expand Down Expand Up @@ -1161,10 +1162,11 @@ static struct nvmf_discovery_log *nvme_discovery_log(
name, retries, args->max_retries);
log_args.log = log;
log_args.len = DISCOVERY_HEADER_LEN;
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) {
err = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args);
if (err) {
nvme_msg(r, LOG_INFO,
"%s: discover try %d/%d failed, error %d\n",
name, retries, args->max_retries, errno);
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
name, retries, args->max_retries, errno, err);
goto out_free_log;
}

Expand Down Expand Up @@ -1194,10 +1196,11 @@ static struct nvmf_discovery_log *nvme_discovery_log(
log_args.lpo = sizeof(*log);
log_args.log = log->entries;
log_args.len = entries_size;
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) {
err = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args);
if (err) {
nvme_msg(r, LOG_INFO,
"%s: discover try %d/%d failed, error %d\n",
name, retries, args->max_retries, errno);
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
name, retries, args->max_retries, errno, err);
goto out_free_log;
}

Expand All @@ -1210,10 +1213,11 @@ static struct nvmf_discovery_log *nvme_discovery_log(
log_args.lpo = 0;
log_args.log = log;
log_args.len = DISCOVERY_HEADER_LEN;
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) {
err = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args);
if (err) {
nvme_msg(r, LOG_INFO,
"%s: discover try %d/%d failed, error %d\n",
name, retries, args->max_retries, errno);
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
name, retries, args->max_retries, errno, err);
goto out_free_log;
}
} while (genctr != le64_to_cpu(log->genctr) &&
Expand All @@ -1234,6 +1238,8 @@ static struct nvmf_discovery_log *nvme_discovery_log(

out_free_log:
free(log);
if (!errno)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC nvme_get_log_page wont set errno, when the return value is positive. So in theory errno could be set... Leave it as it is, just saying it is not 100% safe. Did I mention that errno is stupid?

Copy link
Contributor Author

@maurizio-lombardi maurizio-lombardi Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what do you mean here. Yes, in some cases nvme_get_log_page() doesn't set errno... and this is precisely the problem. The caller sees that nvme_discovery_log() returns a NULL pointer and assumes that errno is set.
This is why the "failed to get discovery log: Success" error message appears

errno = nvme_status_to_errno(err, true);
return NULL;
}

Expand Down