Skip to content

Commit ec22339

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 ec22339

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/nvme/fabrics.c

Lines changed: 15 additions & 9 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+
int err;
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,11 @@ 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+
err = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args);
1166+
if (err) {
11651167
nvme_msg(r, LOG_INFO,
1166-
"%s: discover try %d/%d failed, error %d\n",
1167-
name, retries, args->max_retries, errno);
1168+
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
1169+
name, retries, args->max_retries, errno, err);
11681170
goto out_free_log;
11691171
}
11701172

@@ -1194,10 +1196,11 @@ static struct nvmf_discovery_log *nvme_discovery_log(
11941196
log_args.lpo = sizeof(*log);
11951197
log_args.log = log->entries;
11961198
log_args.len = entries_size;
1197-
if (nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args)) {
1199+
err = nvme_get_log_page(fd, NVME_LOG_PAGE_PDU_SIZE, &log_args);
1200+
if (err) {
11981201
nvme_msg(r, LOG_INFO,
1199-
"%s: discover try %d/%d failed, error %d\n",
1200-
name, retries, args->max_retries, errno);
1202+
"%s: discover try %d/%d failed, errno %d status 0x%x\n",
1203+
name, retries, args->max_retries, errno, err);
12011204
goto out_free_log;
12021205
}
12031206

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

12351239
out_free_log:
12361240
free(log);
1241+
if (!errno)
1242+
errno = nvme_status_to_errno(err, true);
12371243
return NULL;
12381244
}
12391245

0 commit comments

Comments
 (0)