Skip to content

Commit 1f7948a

Browse files
libnvme: propagate the error to the caller if nvme_get_log_page() fails
The nvme_get_log_page() function may return an NVMe status code on failure, leaving the errno number set to zero. The nvme_discovery_log() function wasn't propagating this error information to its caller; it would just return NULL without setting a meaningful errno value. the NULL pointer is interpreted as an error by nvme-cli, it then tries to print the string associated to the errno value, resulting in a funny output: failed to get discovery log: Success Fix this by capturing the status code returned by nvme_get_log_page(), converting it to an errno value using nvme_status_to_errno(), and setting errno before returning. Additionally, the error message has been improved to include the NVMe status code and the log level has been raised from LOG_INFO to LOG_ERR. Signed-off-by: Maurizio Lombardi <[email protected]>
1 parent a3995d2 commit 1f7948a

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

src/nvme/fabrics.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ static struct nvmf_discovery_log *nvme_discovery_log(
11341134
nvme_root_t r = root_from_ctrl(args->c);
11351135
struct nvmf_discovery_log *log;
11361136
int retries = 0;
1137+
uint32_t status = 0;
11371138
const char *name = nvme_ctrl_get_name(args->c);
11381139
uint64_t genctr, numrec;
11391140
int fd = nvme_ctrl_get_fd(args->c);
@@ -1161,10 +1162,10 @@ static struct nvmf_discovery_log *nvme_discovery_log(
11611162
name, retries, args->max_retries);
11621163
log_args.log = log;
11631164
log_args.len = DISCOVERY_HEADER_LEN;
1164-
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) {
1165-
nvme_msg(r, LOG_INFO,
1166-
"%s: discover try %d/%d failed, error %d\n",
1167-
name, retries, args->max_retries, errno);
1165+
if ((status = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args))) {
1166+
nvme_msg(r, LOG_ERR,
1167+
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
1168+
name, retries, args->max_retries, errno, status);
11681169
goto out_free_log;
11691170
}
11701171

@@ -1194,10 +1195,10 @@ static struct nvmf_discovery_log *nvme_discovery_log(
11941195
log_args.lpo = sizeof(*log);
11951196
log_args.log = log->entries;
11961197
log_args.len = entries_size;
1197-
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) {
1198-
nvme_msg(r, LOG_INFO,
1199-
"%s: discover try %d/%d failed, error %d\n",
1200-
name, retries, args->max_retries, errno);
1198+
if ((status = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args))) {
1199+
nvme_msg(r, LOG_ERR,
1200+
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
1201+
name, retries, args->max_retries, errno, status);
12011202
goto out_free_log;
12021203
}
12031204

@@ -1210,10 +1211,10 @@ static struct nvmf_discovery_log *nvme_discovery_log(
12101211
log_args.lpo = 0;
12111212
log_args.log = log;
12121213
log_args.len = DISCOVERY_HEADER_LEN;
1213-
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) {
1214-
nvme_msg(r, LOG_INFO,
1215-
"%s: discover try %d/%d failed, error %d\n",
1216-
name, retries, args->max_retries, errno);
1214+
if ((status = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args))) {
1215+
nvme_msg(r, LOG_ERR,
1216+
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
1217+
name, retries, args->max_retries, errno, status);
12171218
goto out_free_log;
12181219
}
12191220
} while (genctr != le64_to_cpu(log->genctr) &&
@@ -1234,6 +1235,8 @@ static struct nvmf_discovery_log *nvme_discovery_log(
12341235

12351236
out_free_log:
12361237
free(log);
1238+
if (!errno)
1239+
errno = nvme_status_to_errno(status, true);
12371240
return NULL;
12381241
}
12391242

0 commit comments

Comments
 (0)