Skip to content

Commit f757c60

Browse files
committed
nvme: check errno not return value
Unfortunately, libnvme follows the POSIX way to return errors. This means the return value is not containing the error code, it is in errno. While at it, also print the returned value only when debug mode is enabled. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 130640a commit f757c60

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

fabrics.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,15 @@ static int nvme_add_ctrl(nvme_host_t h, nvme_ctrl_t c,
179179

180180
retry:
181181
ret = nvmf_add_ctrl(h, c, cfg);
182-
if (ret == EAGAIN || (ret == EINTR && !nvme_sigint_received)) {
183-
printf("nvmf_add_ctrl returned '%s'\n", strerror(ret));
182+
if (!ret)
183+
return 0;
184+
185+
if (errno == EAGAIN || (errno == EINTR && !nvme_sigint_received)) {
186+
print_debug("nvmf_add_ctrl returned '%s'\n", strerror(errno));
184187
goto retry;
185188
}
186189

187-
return ret;
190+
return -errno;
188191
}
189192

190193
static nvme_ctrl_t __create_discover_ctrl(nvme_root_t r, nvme_host_t h,

util/logging.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ int nvme_submit_passthru(int fd, unsigned long ioctl_cmd,
116116
if (!dry_run) {
117117
retry:
118118
err = ioctl(fd, ioctl_cmd, cmd);
119-
if (err == EAGAIN || (err == EINTR && !nvme_sigint_received)) {
120-
nvme_log_retry(err);
119+
if (err && (errno == EAGAIN ||
120+
(errno == EINTR && !nvme_sigint_received))) {
121+
nvme_log_retry(errno);
121122
goto retry;
122123
}
123124
}
@@ -148,8 +149,9 @@ int nvme_submit_passthru64(int fd, unsigned long ioctl_cmd,
148149
if (!dry_run) {
149150
retry:
150151
err = ioctl(fd, ioctl_cmd, cmd);
151-
if (err == EAGAIN || (err == EINTR && !nvme_sigint_received)) {
152-
nvme_log_retry(err);
152+
if (err && (errno == EAGAIN ||
153+
(errno == EINTR && !nvme_sigint_received))) {
154+
nvme_log_retry(errno);
153155
goto retry;
154156
}
155157
}

0 commit comments

Comments
 (0)