Skip to content

Commit 56b5f7c

Browse files
committed
nvme: standardize nvme_strerror() usage
nvme_strerror() is a useful wrapper function for printing proper error messages corresponding to error codes including library specific error codes too. So it would be helpful to standardize the use of the same here across the codebase. Signed-off-by: Martin George <[email protected]>
1 parent ceaa310 commit 56b5f7c

22 files changed

Lines changed: 152 additions & 149 deletions

fabrics.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log)
152152

153153
fd = open(raw, O_CREAT | O_RDWR | O_TRUNC, 0600);
154154
if (fd < 0) {
155-
fprintf(stderr, "failed to open %s: %s\n", raw, strerror(errno));
155+
fprintf(stderr, "failed to open %s: %s\n", raw, nvme_strerror(errno));
156156
return;
157157
}
158158

@@ -161,7 +161,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log)
161161
ret = write(fd, log, len);
162162
if (ret < 0)
163163
fprintf(stderr, "failed to write to %s: %s\n",
164-
raw, strerror(errno));
164+
raw, nvme_strerror(errno));
165165
else
166166
printf("Discovery log is saved to %s\n", raw);
167167

@@ -183,7 +183,7 @@ static bool cb_decide_retry(struct nvmf_context *fctx, int err,
183183
void *user_data)
184184
{
185185
if (err == -EAGAIN || (err == -EINTR && !nvme_sigint_received)) {
186-
print_debug("nvmf_add_ctrl returned '%s'\n", strerror(-err));
186+
print_debug("nvmf_add_ctrl returned '%s'\n", nvme_strerror(-err));
187187
return true;
188188
}
189189

libnvme/src/nvme/fabrics.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx)
846846
fd = open(nvmf_dev, O_RDONLY);
847847
if (fd < 0) {
848848
nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n",
849-
nvmf_dev, strerror(errno));
849+
nvmf_dev, nvme_strerror(errno));
850850
return -ENVME_CONNECT_OPEN;
851851
}
852852

@@ -866,7 +866,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx)
866866
}
867867

868868
nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n",
869-
nvmf_dev, strerror(errno));
869+
nvmf_dev, nvme_strerror(errno));
870870
return -ENVME_CONNECT_READ;
871871
}
872872

@@ -927,7 +927,7 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr)
927927
fd = open(nvmf_dev, O_RDWR);
928928
if (fd < 0) {
929929
nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n",
930-
nvmf_dev, strerror(errno));
930+
nvmf_dev, nvme_strerror(errno));
931931
return -ENVME_CONNECT_OPEN;
932932
}
933933

@@ -936,7 +936,7 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr)
936936
ret = write(fd, argstr, len);
937937
if (ret != len) {
938938
nvme_msg(ctx, LOG_INFO, "Failed to write to %s: %s\n",
939-
nvmf_dev, strerror(errno));
939+
nvmf_dev, nvme_strerror(errno));
940940
switch (errno) {
941941
case EALREADY:
942942
return -ENVME_CONNECT_ALREADY;
@@ -963,7 +963,7 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr)
963963
len = read(fd, buf, sizeof(buf) - 1);
964964
if (len < 0) {
965965
nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n",
966-
nvmf_dev, strerror(errno));
966+
nvmf_dev, nvme_strerror(errno));
967967
return -ENVME_CONNECT_READ;
968968
}
969969
nvme_msg(ctx, LOG_DEBUG, "connect ctrl, response '%.*s'\n",
@@ -1795,7 +1795,7 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype,
17951795
ret = get_entity_name(dim->ename, sizeof(dim->ename));
17961796
if (ret <= 0)
17971797
nvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME. %s.\n",
1798-
c->name, strerror(ret));
1798+
c->name, nvme_strerror(ret));
17991799

18001800
ret = get_entity_version(dim->ever, sizeof(dim->ever));
18011801
if (ret <= 0)

libnvme/src/nvme/json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ int json_read_config(struct nvme_global_ctx *ctx, const char *config_file)
243243
fd = open(config_file, O_RDONLY);
244244
if (fd < 0) {
245245
nvme_msg(ctx, LOG_DEBUG, "Error opening %s, %s\n",
246-
config_file, strerror(errno));
246+
config_file, nvme_strerror(errno));
247247
return fd;
248248
}
249249
json_root = parse_json(ctx, fd);

libnvme/src/nvme/nbft.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,14 +750,14 @@ int nvme_nbft_read(struct nvme_global_ctx *ctx, struct nbft_info **nbft,
750750
raw_nbft_fp = fopen(filename, "rb");
751751
if (raw_nbft_fp == NULL) {
752752
nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n",
753-
filename, strerror(errno));
753+
filename, nvme_strerror(errno));
754754
return -EINVAL;
755755
}
756756

757757
i = fseek(raw_nbft_fp, 0L, SEEK_END);
758758
if (i) {
759759
nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n",
760-
filename, strerror(errno));
760+
filename, nvme_strerror(errno));
761761
fclose(raw_nbft_fp);
762762
return -EINVAL;
763763
}
@@ -776,7 +776,7 @@ int nvme_nbft_read(struct nvme_global_ctx *ctx, struct nbft_info **nbft,
776776
i = fread(raw_nbft, sizeof(*raw_nbft), raw_nbft_size, raw_nbft_fp);
777777
if (i != raw_nbft_size) {
778778
nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n",
779-
filename, strerror(errno));
779+
filename, nvme_strerror(errno));
780780
fclose(raw_nbft_fp);
781781
free(raw_nbft);
782782
return -EINVAL;

libnvme/src/nvme/tree.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *
289289
ctrls.num = nvme_scan_ctrls(&ctrls.ents);
290290
if (ctrls.num < 0) {
291291
nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrls: %s\n",
292-
strerror(-ctrls.num));
292+
nvme_strerror(-ctrls.num));
293293
return ctrls.num;
294294
}
295295

@@ -299,15 +299,15 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *
299299
ret = nvme_scan_ctrl(ctx, ctrls.ents[i]->d_name, &c);
300300
if (!ret) {
301301
nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrl %s: %s\n",
302-
ctrls.ents[i]->d_name, strerror(ret));
302+
ctrls.ents[i]->d_name, nvme_strerror(ret));
303303
continue;
304304
}
305305
}
306306

307307
subsys.num = nvme_scan_subsystems(&subsys.ents);
308308
if (subsys.num < 0) {
309309
nvme_msg(ctx, LOG_DEBUG, "failed to scan subsystems: %s\n",
310-
strerror(-subsys.num));
310+
nvme_strerror(-subsys.num));
311311
return subsys.num;
312312
}
313313

@@ -316,7 +316,7 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void *
316316
if (ret < 0) {
317317
nvme_msg(ctx, LOG_DEBUG,
318318
"failed to scan subsystem %s: %s\n",
319-
subsys.ents[i]->d_name, strerror(-ret));
319+
subsys.ents[i]->d_name, nvme_strerror(-ret));
320320
}
321321
}
322322

@@ -843,7 +843,7 @@ static int nvme_subsystem_scan_namespaces(struct nvme_global_ctx *ctx, nvme_subs
843843
if (namespaces.num < 0) {
844844
nvme_msg(ctx, LOG_DEBUG,
845845
"failed to scan namespaces for subsys %s: %s\n",
846-
s->subsysnqn, strerror(-namespaces.num));
846+
s->subsysnqn, nvme_strerror(-namespaces.num));
847847
return namespaces.num;
848848
}
849849

@@ -853,7 +853,7 @@ static int nvme_subsystem_scan_namespaces(struct nvme_global_ctx *ctx, nvme_subs
853853
if (ret < 0)
854854
nvme_msg(ctx, LOG_DEBUG,
855855
"failed to scan namespace %s: %s\n",
856-
namespaces.ents[i]->d_name, strerror(-ret));
856+
namespaces.ents[i]->d_name, nvme_strerror(-ret));
857857
}
858858

859859
return 0;

logging.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void nvme_log_retry(int errnum)
103103
if (log_level < LOG_DEBUG)
104104
return;
105105

106-
printf("passthru command returned '%s'\n", strerror(errnum));
106+
printf("passthru command returned '%s'\n", nvme_strerror(errnum));
107107
}
108108

109109
void *nvme_submit_entry(struct nvme_transport_handle *hdl,

nvme-models.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <unistd.h>
1010
#include <errno.h>
1111
#include "nvme-models.h"
12+
#include "nvme.h"
1213

1314
static char *_fmt1 = "/sys/class/nvme/nvme%d/device/subsystem_vendor";
1415
static char *_fmt2 = "/sys/class/nvme/nvme%d/device/subsystem_device";
@@ -244,7 +245,7 @@ static int read_sys_node(char *where, char *save, size_t savesz)
244245
fd = open(where, O_RDONLY);
245246
if (fd < 0) {
246247
fprintf(stderr, "Failed to open %s with errno %s\n",
247-
where, strerror(errno));
248+
where, nvme_strerror(errno));
248249
return 1;
249250
}
250251
/* -1 so we can safely use strstr below */
@@ -327,7 +328,7 @@ char *nvme_product_name(int id)
327328

328329
line = malloc(1024);
329330
if (!line) {
330-
fprintf(stderr, "malloc: %s\n", strerror(errno));
331+
fprintf(stderr, "malloc: %s\n", nvme_strerror(errno));
331332
goto error0;
332333
}
333334

nvme-print-json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5344,7 +5344,7 @@ static void json_output_perror(const char *msg, va_list ap)
53445344
if (vasprintf(&error, msg, ap) < 0)
53455345
error = alloc_error;
53465346

5347-
obj_add_key(r, "error", "%s: %s", error, strerror(errno));
5347+
obj_add_key(r, "error", "%s: %s", error, nvme_strerror(errno));
53485348

53495349
json_output_object(r);
53505350
}

nvme-rpmb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static int read_file(const char *file, unsigned char **data, unsigned int *len)
168168
if (file == NULL) return err;
169169

170170
if ((fd = open(file, O_RDONLY)) < 0) {
171-
fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno));
171+
fprintf(stderr, "Failed to open %s: %s\n", file, nvme_strerror(errno));
172172
return fd;
173173
}
174174

@@ -189,7 +189,7 @@ static int read_file(const char *file, unsigned char **data, unsigned int *len)
189189
if (err < 0) {
190190
err = -errno;
191191
fprintf(stderr, "Failed to read data from file"
192-
" %s with %s\n", file, strerror(errno));
192+
" %s with %s\n", file, nvme_strerror(errno));
193193
free(buf);
194194
goto out;
195195
}

0 commit comments

Comments
 (0)