diff --git a/fabrics.c b/fabrics.c index 9a1f0a0e98..77f7e7f092 100644 --- a/fabrics.c +++ b/fabrics.c @@ -152,7 +152,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log) fd = open(raw, O_CREAT | O_RDWR | O_TRUNC, 0600); if (fd < 0) { - fprintf(stderr, "failed to open %s: %s\n", raw, strerror(errno)); + fprintf(stderr, "failed to open %s: %s\n", raw, nvme_strerror(errno)); return; } @@ -161,7 +161,7 @@ static void save_discovery_log(char *raw, struct nvmf_discovery_log *log) ret = write(fd, log, len); if (ret < 0) fprintf(stderr, "failed to write to %s: %s\n", - raw, strerror(errno)); + raw, nvme_strerror(errno)); else printf("Discovery log is saved to %s\n", raw); @@ -183,7 +183,7 @@ static bool cb_decide_retry(struct nvmf_context *fctx, int err, void *user_data) { if (err == -EAGAIN || (err == -EINTR && !nvme_sigint_received)) { - print_debug("nvmf_add_ctrl returned '%s'\n", strerror(-err)); + print_debug("nvmf_add_ctrl returned '%s'\n", nvme_strerror(-err)); return true; } diff --git a/libnvme/src/nvme/fabrics.c b/libnvme/src/nvme/fabrics.c index 40b15bb141..9414709b87 100644 --- a/libnvme/src/nvme/fabrics.c +++ b/libnvme/src/nvme/fabrics.c @@ -846,7 +846,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx) fd = open(nvmf_dev, O_RDONLY); if (fd < 0) { nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", - nvmf_dev, strerror(errno)); + nvmf_dev, nvme_strerror(errno)); return -ENVME_CONNECT_OPEN; } @@ -866,7 +866,7 @@ static int __nvmf_supported_options(struct nvme_global_ctx *ctx) } nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - nvmf_dev, strerror(errno)); + nvmf_dev, nvme_strerror(errno)); return -ENVME_CONNECT_READ; } @@ -927,7 +927,7 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr) fd = open(nvmf_dev, O_RDWR); if (fd < 0) { nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", - nvmf_dev, strerror(errno)); + nvmf_dev, nvme_strerror(errno)); return -ENVME_CONNECT_OPEN; } @@ -936,7 +936,7 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr) ret = write(fd, argstr, len); if (ret != len) { nvme_msg(ctx, LOG_INFO, "Failed to write to %s: %s\n", - nvmf_dev, strerror(errno)); + nvmf_dev, nvme_strerror(errno)); switch (errno) { case EALREADY: return -ENVME_CONNECT_ALREADY; @@ -963,7 +963,7 @@ static int __nvmf_add_ctrl(struct nvme_global_ctx *ctx, const char *argstr) len = read(fd, buf, sizeof(buf) - 1); if (len < 0) { nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - nvmf_dev, strerror(errno)); + nvmf_dev, nvme_strerror(errno)); return -ENVME_CONNECT_READ; } nvme_msg(ctx, LOG_DEBUG, "connect ctrl, response '%.*s'\n", @@ -1793,9 +1793,12 @@ static int nvmf_dim(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u8 trtype, MIN(sizeof(dim->eid), strlen(c->s->h->hostnqn))); ret = get_entity_name(dim->ename, sizeof(dim->ename)); - if (ret <= 0) + if (ret < 0) nvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME. %s.\n", - c->name, strerror(ret)); + c->name, nvme_strerror(-ret)); + else if (ret == 0) + nvme_msg(ctx, LOG_INFO, "%s: Failed to retrieve ENAME.\n", + c->name); ret = get_entity_version(dim->ever, sizeof(dim->ever)); if (ret <= 0) diff --git a/libnvme/src/nvme/json.c b/libnvme/src/nvme/json.c index 41f7862b25..2acc1630ee 100644 --- a/libnvme/src/nvme/json.c +++ b/libnvme/src/nvme/json.c @@ -243,7 +243,7 @@ int json_read_config(struct nvme_global_ctx *ctx, const char *config_file) fd = open(config_file, O_RDONLY); if (fd < 0) { nvme_msg(ctx, LOG_DEBUG, "Error opening %s, %s\n", - config_file, strerror(errno)); + config_file, nvme_strerror(errno)); return fd; } json_root = parse_json(ctx, fd); diff --git a/libnvme/src/nvme/nbft.c b/libnvme/src/nvme/nbft.c index dc8582f112..9eb5e53db3 100644 --- a/libnvme/src/nvme/nbft.c +++ b/libnvme/src/nvme/nbft.c @@ -750,14 +750,14 @@ int nvme_nbft_read(struct nvme_global_ctx *ctx, struct nbft_info **nbft, raw_nbft_fp = fopen(filename, "rb"); if (raw_nbft_fp == NULL) { nvme_msg(ctx, LOG_ERR, "Failed to open %s: %s\n", - filename, strerror(errno)); + filename, nvme_strerror(errno)); return -EINVAL; } i = fseek(raw_nbft_fp, 0L, SEEK_END); if (i) { nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - filename, strerror(errno)); + filename, nvme_strerror(errno)); fclose(raw_nbft_fp); return -EINVAL; } @@ -776,7 +776,7 @@ int nvme_nbft_read(struct nvme_global_ctx *ctx, struct nbft_info **nbft, i = fread(raw_nbft, sizeof(*raw_nbft), raw_nbft_size, raw_nbft_fp); if (i != raw_nbft_size) { nvme_msg(ctx, LOG_ERR, "Failed to read from %s: %s\n", - filename, strerror(errno)); + filename, nvme_strerror(errno)); fclose(raw_nbft_fp); free(raw_nbft); return -EINVAL; diff --git a/libnvme/src/nvme/tree.c b/libnvme/src/nvme/tree.c index 9b59b19825..4653920da9 100644 --- a/libnvme/src/nvme/tree.c +++ b/libnvme/src/nvme/tree.c @@ -289,7 +289,7 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void * ctrls.num = nvme_scan_ctrls(&ctrls.ents); if (ctrls.num < 0) { nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrls: %s\n", - strerror(-ctrls.num)); + nvme_strerror(-ctrls.num)); return ctrls.num; } @@ -297,9 +297,9 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void * nvme_ctrl_t c; ret = nvme_scan_ctrl(ctx, ctrls.ents[i]->d_name, &c); - if (!ret) { + if (ret < 0) { nvme_msg(ctx, LOG_DEBUG, "failed to scan ctrl %s: %s\n", - ctrls.ents[i]->d_name, strerror(ret)); + ctrls.ents[i]->d_name, nvme_strerror(-ret)); continue; } } @@ -307,7 +307,7 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void * subsys.num = nvme_scan_subsystems(&subsys.ents); if (subsys.num < 0) { nvme_msg(ctx, LOG_DEBUG, "failed to scan subsystems: %s\n", - strerror(-subsys.num)); + nvme_strerror(-subsys.num)); return subsys.num; } @@ -316,7 +316,7 @@ int nvme_scan_topology(struct nvme_global_ctx *ctx, nvme_scan_filter_t f, void * if (ret < 0) { nvme_msg(ctx, LOG_DEBUG, "failed to scan subsystem %s: %s\n", - subsys.ents[i]->d_name, strerror(-ret)); + subsys.ents[i]->d_name, nvme_strerror(-ret)); } } @@ -843,7 +843,7 @@ static int nvme_subsystem_scan_namespaces(struct nvme_global_ctx *ctx, nvme_subs if (namespaces.num < 0) { nvme_msg(ctx, LOG_DEBUG, "failed to scan namespaces for subsys %s: %s\n", - s->subsysnqn, strerror(-namespaces.num)); + s->subsysnqn, nvme_strerror(-namespaces.num)); return namespaces.num; } @@ -853,7 +853,7 @@ static int nvme_subsystem_scan_namespaces(struct nvme_global_ctx *ctx, nvme_subs if (ret < 0) nvme_msg(ctx, LOG_DEBUG, "failed to scan namespace %s: %s\n", - namespaces.ents[i]->d_name, strerror(-ret)); + namespaces.ents[i]->d_name, nvme_strerror(-ret)); } return 0; diff --git a/logging.c b/logging.c index dcb8e7638b..b13a4ca5a9 100644 --- a/logging.c +++ b/logging.c @@ -103,7 +103,7 @@ static void nvme_log_retry(int errnum) if (log_level < LOG_DEBUG) return; - printf("passthru command returned '%s'\n", strerror(errnum)); + printf("passthru command returned '%s'\n", nvme_strerror(errnum)); } void *nvme_submit_entry(struct nvme_transport_handle *hdl, diff --git a/nvme-models.c b/nvme-models.c index f638e4d03d..84ede6eaaf 100644 --- a/nvme-models.c +++ b/nvme-models.c @@ -9,6 +9,7 @@ #include #include #include "nvme-models.h" +#include "nvme.h" static char *_fmt1 = "/sys/class/nvme/nvme%d/device/subsystem_vendor"; 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) fd = open(where, O_RDONLY); if (fd < 0) { fprintf(stderr, "Failed to open %s with errno %s\n", - where, strerror(errno)); + where, nvme_strerror(errno)); return 1; } /* -1 so we can safely use strstr below */ @@ -327,7 +328,7 @@ char *nvme_product_name(int id) line = malloc(1024); if (!line) { - fprintf(stderr, "malloc: %s\n", strerror(errno)); + fprintf(stderr, "malloc: %s\n", nvme_strerror(errno)); goto error0; } diff --git a/nvme-print-json.c b/nvme-print-json.c index 73b0c52e0a..1ccdadf6d8 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -5344,7 +5344,7 @@ static void json_output_perror(const char *msg, va_list ap) if (vasprintf(&error, msg, ap) < 0) error = alloc_error; - obj_add_key(r, "error", "%s: %s", error, strerror(errno)); + obj_add_key(r, "error", "%s: %s", error, nvme_strerror(errno)); json_output_object(r); } diff --git a/nvme-rpmb.c b/nvme-rpmb.c index 5e955846c7..5d2fb1df60 100644 --- a/nvme-rpmb.c +++ b/nvme-rpmb.c @@ -168,7 +168,7 @@ static int read_file(const char *file, unsigned char **data, unsigned int *len) if (file == NULL) return err; if ((fd = open(file, O_RDONLY)) < 0) { - fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno)); + fprintf(stderr, "Failed to open %s: %s\n", file, nvme_strerror(errno)); return fd; } @@ -189,7 +189,7 @@ static int read_file(const char *file, unsigned char **data, unsigned int *len) if (err < 0) { err = -errno; fprintf(stderr, "Failed to read data from file" - " %s with %s\n", file, strerror(errno)); + " %s with %s\n", file, nvme_strerror(errno)); free(buf); goto out; } diff --git a/nvme.c b/nvme.c index f229b7447b..884c98fa94 100644 --- a/nvme.c +++ b/nvme.c @@ -935,7 +935,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, output = open(cfg.file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { nvme_show_error("Failed to open output file %s: %s!", - cfg.file_name, strerror(errno)); + cfg.file_name, nvme_strerror(errno)); return output; } @@ -970,7 +970,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, if (data_written < 0) { err = -errno; nvme_show_error("ERROR: %s: : write failed with error : %s", - __func__, strerror(errno)); + __func__, nvme_strerror(errno)); break; } else if (data_written <= data_remaining) { data_remaining -= data_written; @@ -985,7 +985,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *acmd, } if (fsync(output) < 0) { - nvme_show_error("ERROR : %s: : fsync : %s", __func__, strerror(errno)); + nvme_show_error("ERROR : %s: : fsync : %s", __func__, nvme_strerror(errno)); return -1; } @@ -1895,7 +1895,7 @@ static int get_boot_part_log(int argc, char **argv, struct command *acmd, struct output = open(cfg.file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { nvme_show_error("Failed to open output file %s: %s!", - cfg.file_name, strerror(errno)); + cfg.file_name, nvme_strerror(errno)); return output; } @@ -5183,7 +5183,7 @@ static int fw_download(int argc, char **argv, struct command *acmd, struct plugi fw_fd = open(cfg.fw, O_RDONLY); cfg.offset <<= 2; if (fw_fd < 0) { - nvme_show_error("Failed to open firmware file %s: %s", cfg.fw, strerror(errno)); + nvme_show_error("Failed to open firmware file %s: %s", cfg.fw, nvme_strerror(errno)); return -EINVAL; } @@ -5224,7 +5224,7 @@ static int fw_download(int argc, char **argv, struct command *acmd, struct plugi if (read(fw_fd, fw_buf, fw_size) != ((ssize_t)(fw_size))) { err = -errno; - nvme_show_error("read :%s :%s", cfg.fw, strerror(errno)); + nvme_show_error("read :%s :%s", cfg.fw, nvme_strerror(errno)); return err; } @@ -5829,7 +5829,7 @@ static void *mmap_registers(struct nvme_transport_handle *hdl, bool writable) if (fd < 0) { if (log_level >= LOG_INFO) nvme_show_error("%s did not find a pci resource, open failed %s", - nvme_transport_handle_get_name(hdl), strerror(errno)); + nvme_transport_handle_get_name(hdl), nvme_strerror(errno)); return NULL; } @@ -6968,14 +6968,14 @@ static int set_feature(int argc, char **argv, struct command *acmd, struct plugi if (ffd < 0) { nvme_show_error("Failed to open file %s: %s", - cfg.file, strerror(errno)); + cfg.file, nvme_strerror(errno)); return -EINVAL; } err = read(ffd, buf, cfg.data_len); if (err < 0) { nvme_show_error("failed to read data buffer from input file: %s", - strerror(errno)); + nvme_strerror(errno)); return -errno; } } @@ -7077,7 +7077,7 @@ static int sec_send(int argc, char **argv, struct command *acmd, struct plugin * } else { sec_fd = open(cfg.file, O_RDONLY); if (sec_fd < 0) { - nvme_show_error("Failed to open %s: %s", cfg.file, strerror(errno)); + nvme_show_error("Failed to open %s: %s", cfg.file, nvme_strerror(errno)); return -EINVAL; } @@ -7097,7 +7097,7 @@ static int sec_send(int argc, char **argv, struct command *acmd, struct plugin * err = read(sec_fd, sec_buf, sec_size); if (err < 0) { nvme_show_error("Failed to read data from security file %s with %s", cfg.file, - strerror(errno)); + nvme_strerror(errno)); return -errno; } @@ -7218,7 +7218,7 @@ static int dir_send(int argc, char **argv, struct command *acmd, struct plugin * ffd = open(cfg.file, O_RDONLY); if (ffd <= 0) { nvme_show_error("Failed to open file %s: %s", - cfg.file, strerror(errno)); + cfg.file, nvme_strerror(errno)); return -EINVAL; } } @@ -7226,7 +7226,7 @@ static int dir_send(int argc, char **argv, struct command *acmd, struct plugin * if (err < 0) { nvme_show_error( "failed to read data buffer from input file %s", - strerror(errno)); + nvme_strerror(errno)); return -errno; } } @@ -8572,7 +8572,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char err = read(dfd, (void *)buffer, cfg.data_size); if (err < 0) { err = -errno; - nvme_show_error("failed to read data buffer from input file %s", strerror(errno)); + nvme_show_error("failed to read data buffer from input file %s", nvme_strerror(errno)); return err; } } @@ -8581,7 +8581,7 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char err = read(mfd, (void *)mbuffer, mbuffer_size); if (err < 0) { err = -errno; - nvme_show_error("failed to read meta-data buffer from input file %s", strerror(errno)); + nvme_show_error("failed to read meta-data buffer from input file %s", nvme_strerror(errno)); return err; } } @@ -8640,13 +8640,13 @@ static int submit_io(int opcode, char *command, const char *desc, int argc, char if (!(opcode & 1) && write(dfd, (void *)buffer, buffer_size) < 0) { nvme_show_error( "write: %s: failed to write buffer to output file", - strerror(errno)); + nvme_strerror(errno)); err = -EINVAL; } else if (!(opcode & 1) && cfg.metadata_size && write(mfd, (void *)mbuffer, mbuffer_size) < 0) { nvme_show_error( "write: %s: failed to write meta-data buffer to output file", - strerror(errno)); + nvme_strerror(errno)); err = -EINVAL; } else { fprintf(stderr, "%s: Success\n", command); @@ -9426,7 +9426,7 @@ static int passthru(int argc, char **argv, bool admin, } else if (cfg.write) { if (read(dfd, data, cfg.data_len) < 0) { err = -errno; - nvme_show_error("failed to read write buffer %s", strerror(errno)); + nvme_show_error("failed to read write buffer %s", nvme_strerror(errno)); return err; } } @@ -9795,7 +9795,7 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, err = nvme_lookup_keyring(ctx, keyring, &kr_id); if (err) { nvme_show_error("Failed to lookup keyring '%s', %s", - keyring, strerror(-err)); + keyring, nvme_strerror(-err)); return err; } @@ -9813,7 +9813,7 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, err = nvme_read_key(ctx, kr_id, id, &key_len, &key_data); if (err) { nvme_show_error("Failed to read back derive TLS PSK, %s", - strerror(-err)); + nvme_strerror(-err)); return err; } @@ -9821,7 +9821,7 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, key_len, &exported_key); if (err) { nvme_show_error("Failed to export key, %s", - strerror(-err)); + nvme_strerror(-err)); return err; } @@ -9830,15 +9830,15 @@ static int append_keyfile(struct nvme_global_ctx *ctx, const char *keyring, fd = fopen(keyfile, "a"); if (!fd) { nvme_show_error("Failed to open '%s', %s", - keyfile, strerror(errno)); + keyfile, nvme_strerror(errno)); err = -errno; goto out; } err = fprintf(fd, "%s %s\n", identity, exported_key); if (err < 0) { - nvme_show_error("Failed to append key to '%', %s", - keyfile, strerror(errno)); + nvme_show_error("Failed to append key to '%s', %s", + keyfile, nvme_strerror(errno)); err = -errno; } else { err = 0; @@ -9975,7 +9975,7 @@ static int gen_tls_key(int argc, char **argv, struct command *acmd, struct plugi err = nvme_export_tls_key(ctx, raw_secret, key_len, &encoded_key); if (err) { - nvme_show_error("Failed to export key, %s", strerror(-err)); + nvme_show_error("Failed to export key, %s", nvme_strerror(-err)); return err; } printf("%s\n", encoded_key); @@ -10563,7 +10563,7 @@ static int nvme_mi(int argc, char **argv, __u8 admin_opcode, const char *desc) if (send) { if (read(fd, data, cfg.data_len) < 0) { err = -errno; - nvme_show_error("failed to read write buffer %s", strerror(errno)); + nvme_show_error("failed to read write buffer %s", nvme_strerror(errno)); return err; } } diff --git a/plugins/feat/feat-nvme.c b/plugins/feat/feat-nvme.c index ef8a817f6a..0d17680809 100644 --- a/plugins/feat/feat-nvme.c +++ b/plugins/feat/feat-nvme.c @@ -175,13 +175,13 @@ static int perfc_set(struct nvme_transport_handle *hdl, __u8 fid, __u32 cdw11, ffd = open(cfg->vs_data, O_RDONLY); if (ffd < 0) { nvme_show_error("Failed to open file %s: %s", cfg->vs_data, - strerror(errno)); + nvme_strerror(errno)); return -EINVAL; } err = read(ffd, data.vs_perf->vs, data.vs_perf->attrl); if (err < 0) { nvme_show_error("failed to read data buffer from input file: %s", - strerror(errno)); + nvme_strerror(errno)); return -errno; } } diff --git a/plugins/huawei/huawei-nvme.c b/plugins/huawei/huawei-nvme.c index 8ae01c49c1..07a8920b33 100644 --- a/plugins/huawei/huawei-nvme.c +++ b/plugins/huawei/huawei-nvme.c @@ -345,7 +345,7 @@ static int huawei_list(int argc, char **argv, struct command *acmd, ret = nvme_open(ctx, path, &hdl); if (ret) { fprintf(stderr, "Cannot open device %s: %s\n", - path, strerror(-ret)); + path, nvme_strerror(-ret)); continue; } ret = huawei_get_nvme_info(hdl, &list_items[huawei_num], path); diff --git a/plugins/lm/lm-nvme.c b/plugins/lm/lm-nvme.c index 6f65f6b3d8..d1efb975da 100644 --- a/plugins/lm/lm-nvme.c +++ b/plugins/lm/lm-nvme.c @@ -102,7 +102,7 @@ static int lm_create_cdq(int argc, char **argv, struct command *acmd, struct plu queue = nvme_alloc_huge(cfg.sz << 2, &mh); if (!queue) { nvme_show_error("ERROR: nvme_alloc of size %dB failed %s", cfg.sz << 2, - strerror(errno)); + nvme_strerror(errno)); return -ENOMEM; } @@ -235,7 +235,7 @@ static int lm_track_send(int argc, char **argv, struct command *acmd, struct plu nvme_init_lm_track_send(&cmd, cfg.sel, cfg.mos, cfg.cdqid); err = nvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_track_send() failed %s", strerror(errno)); + nvme_show_error("ERROR: nvme_lm_track_send() failed %s", nvme_strerror(errno)); else if (err) nvme_show_status(err); else @@ -372,7 +372,7 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct fclose(file); if (n_data != (size_t)(cfg.numd << 2)) { - nvme_show_error("failed to read controller state data %s", strerror(errno)); + nvme_show_error("failed to read controller state data %s", nvme_strerror(errno)); return -errno; } } @@ -384,7 +384,7 @@ static int lm_migration_send(int argc, char **argv, struct command *acmd, struct (cfg.numd << 2)); err = nvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_migration_send() failed %s", strerror(errno)); + nvme_show_error("ERROR: nvme_lm_migration_send() failed %s", nvme_strerror(errno)); else if (err > 0) nvme_show_status(err); else @@ -498,7 +498,7 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct (cfg.numd + 1) << 2); err = nvme_submit_admin_passthru(hdl, &cmd); if (err < 0) - nvme_show_error("ERROR: nvme_lm_migration_recv() failed %s", strerror(errno)); + nvme_show_error("ERROR: nvme_lm_migration_recv() failed %s", nvme_strerror(errno)); else if (err) nvme_show_status(err); else if (cfg.sel == NVME_LM_SEL_GET_CONTROLLER_STATE) { @@ -511,7 +511,7 @@ static int lm_migration_recv(int argc, char **argv, struct command *acmd, struct if (cfg.output && strlen(cfg.output)) { if (fwrite(data, 1, cfg.numd << 2, fd) != (cfg.numd << 2)) { nvme_show_error("ERROR: %s: failed to write buffer to output file", - strerror(errno)); + nvme_strerror(errno)); err = -errno; } } else { diff --git a/plugins/netapp/netapp-nvme.c b/plugins/netapp/netapp-nvme.c index 05ee21cd57..63c1fcd81d 100644 --- a/plugins/netapp/netapp-nvme.c +++ b/plugins/netapp/netapp-nvme.c @@ -764,7 +764,7 @@ static int netapp_smdevices_get_info(struct nvme_transport_handle *hdl, if (err) { fprintf(stderr, "Identify Controller failed to %s (%s)\n", dev, - err < 0 ? strerror(-err) : + err < 0 ? nvme_strerror(-err) : nvme_status_to_string(err, false)); return 0; } @@ -780,7 +780,7 @@ static int netapp_smdevices_get_info(struct nvme_transport_handle *hdl, if (err) { fprintf(stderr, "Unable to identify namespace for %s (%s)\n", - dev, err < 0 ? strerror(-err) : + dev, err < 0 ? nvme_strerror(-err) : nvme_status_to_string(err, false)); return 0; } @@ -799,7 +799,7 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, err = nvme_identify_ctrl(hdl, &item->ctrl); if (err) { fprintf(stderr, "Identify Controller failed to %s (%s)\n", - dev, err < 0 ? strerror(-err) : + dev, err < 0 ? nvme_strerror(-err) : nvme_status_to_string(err, false)); return 0; } @@ -813,7 +813,7 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, err = nvme_identify_ns(hdl, item->nsid, &item->ns); if (err) { fprintf(stderr, "Unable to identify namespace for %s (%s)\n", - dev, err < 0 ? strerror(-err) : + dev, err < 0 ? nvme_strerror(-err) : nvme_status_to_string(err, false)); return 0; } @@ -828,7 +828,7 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, err = nvme_identify_ns_descs_list(hdl, item->nsid, nsdescs); if (err) { fprintf(stderr, "Unable to identify namespace descriptor for %s (%s)\n", - dev, err < 0 ? strerror(-err) : + dev, err < 0 ? nvme_strerror(-err) : nvme_status_to_string(err, false)); free(nsdescs); return 0; @@ -840,7 +840,7 @@ static int netapp_ontapdevices_get_info(struct nvme_transport_handle *hdl, err = nvme_get_ontap_c2_log(hdl, item->nsid, item->log_data, ONTAP_C2_LOG_SIZE); if (err) { fprintf(stderr, "Unable to get log page data for %s (%s)\n", - dev, err < 0 ? strerror(-err) : + dev, err < 0 ? nvme_strerror(-err) : nvme_status_to_string(err, false)); return 0; } @@ -967,7 +967,7 @@ static int netapp_smdevices(int argc, char **argv, struct command *acmd, ret = nvme_open(ctx, path, &hdl); if (ret) { fprintf(stderr, "Unable to open %s: %s\n", path, - strerror(-ret)); + nvme_strerror(-ret)); continue; } @@ -1078,7 +1078,7 @@ static int netapp_ontapdevices(int argc, char **argv, struct command *acmd, ret = nvme_open(ctx, path, &hdl); if (ret) { fprintf(stderr, "Unable to open %s: %s\n", path, - strerror(-ret)); + nvme_strerror(-ret)); continue; } diff --git a/plugins/ocp/ocp-hardware-component-log.c b/plugins/ocp/ocp-hardware-component-log.c index 8339a11d84..0cd10946ce 100644 --- a/plugins/ocp/ocp-hardware-component-log.c +++ b/plugins/ocp/ocp-hardware-component-log.c @@ -217,7 +217,7 @@ static int get_hwcomp_log_data(struct nvme_transport_handle *hdl, struct hwcomp_ log->desc = calloc(1, len); if (!log->desc) { - fprintf(stderr, "error: ocp: calloc: %s\n", strerror(errno)); + fprintf(stderr, "error: ocp: calloc: %s\n", nvme_strerror(errno)); return -errno; } diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c index 288293d070..0668d1d955 100644 --- a/plugins/ocp/ocp-nvme.c +++ b/plugins/ocp/ocp-nvme.c @@ -213,7 +213,7 @@ static int get_c3_log_page(struct nvme_transport_handle *hdl, char *format) data = malloc(sizeof(__u8) * C3_LATENCY_MON_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C3_LATENCY_MON_LOG_BUF_LEN); @@ -1201,7 +1201,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, telemetry_log = malloc(bs); if (!hdr || !telemetry_log) { fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n", - bs, strerror(errno)); + bs, nvme_strerror(errno)); err = -ENOMEM; goto exit_status; } @@ -1210,7 +1210,7 @@ static int get_telemetry_log_page_data(struct nvme_transport_handle *hdl, fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { fprintf(stderr, "Failed to open output file %s: %s!\n", - output_file, strerror(errno)); + output_file, nvme_strerror(errno)); err = fd; goto exit_status; } @@ -1299,7 +1299,7 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, header_data = (__u8 *)malloc(sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN); if (!header_data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(header_data, 0, sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN); @@ -1341,7 +1341,7 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, pC9_string_buffer = (__u8 *)malloc(sizeof(__u8) * total_log_page_sz); if (!pC9_string_buffer) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(pC9_string_buffer, 0, sizeof(__u8) * total_log_page_sz); @@ -1355,7 +1355,7 @@ static int get_c9_log_page_data(struct nvme_transport_handle *hdl, fd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { fprintf(stderr, "Failed to open output file %s: %s!\n", output_file, - strerror(errno)); + nvme_strerror(errno)); return fd; } @@ -1654,7 +1654,7 @@ static int get_c5_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C5_UNSUPPORTED_REQS_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C5_UNSUPPORTED_REQS_LEN); @@ -1758,7 +1758,7 @@ static int get_c1_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C1_ERROR_RECOVERY_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C1_ERROR_RECOVERY_LOG_BUF_LEN); @@ -1861,7 +1861,7 @@ static int get_c4_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C4_DEV_CAP_REQ_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C4_DEV_CAP_REQ_LEN); @@ -2565,7 +2565,7 @@ static int get_c7_log_page(struct nvme_transport_handle *hdl, char *format) data = (__u8 *)malloc(sizeof(__u8) * C7_TCG_CONFIGURATION_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C7_TCG_CONFIGURATION_LEN); @@ -2695,7 +2695,7 @@ static int error_injection_get(struct nvme_transport_handle *hdl, const __u8 sel entry = nvme_alloc(data_len); if (!entry) { - nvme_show_error("malloc: %s", strerror(errno)); + nvme_show_error("malloc: %s", nvme_strerror(errno)); return -ENOMEM; } @@ -2776,20 +2776,20 @@ static int error_injection_set(struct nvme_transport_handle *hdl, struct erri_co data_len = cfg->number * sizeof(struct erri_entry); entry = nvme_alloc(data_len); if (!entry) { - nvme_show_error("malloc: %s", strerror(errno)); + nvme_show_error("malloc: %s", nvme_strerror(errno)); return -ENOMEM; } if (cfg->file && strlen(cfg->file)) { ffd = open(cfg->file, O_RDONLY); if (ffd < 0) { - nvme_show_error("Failed to open file %s: %s", cfg->file, strerror(errno)); + nvme_show_error("Failed to open file %s: %s", cfg->file, nvme_strerror(errno)); return -EINVAL; } err = read(ffd, entry, data_len); if (err < 0) { nvme_show_error("failed to read data buffer from input file: %s", - strerror(errno)); + nvme_strerror(errno)); return -errno; } } else { diff --git a/plugins/ocp/ocp-smart-extended-log.c b/plugins/ocp/ocp-smart-extended-log.c index 3eef14a9a7..0db198d56b 100644 --- a/plugins/ocp/ocp-smart-extended-log.c +++ b/plugins/ocp/ocp-smart-extended-log.c @@ -44,7 +44,7 @@ static int get_c0_log_page(struct nvme_transport_handle *hdl, char *format, data = malloc(sizeof(__u8) * C0_SMART_CLOUD_ATTR_LEN); if (!data) { - fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno)); + fprintf(stderr, "ERROR : OCP : malloc : %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * C0_SMART_CLOUD_ATTR_LEN); diff --git a/plugins/sandisk/sandisk-nvme.c b/plugins/sandisk/sandisk-nvme.c index aa73b25771..c709be33a4 100644 --- a/plugins/sandisk/sandisk-nvme.c +++ b/plugins/sandisk/sandisk-nvme.c @@ -104,7 +104,7 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", - __func__, file, strerror(errno)); + __func__, file, nvme_strerror(errno)); return output; } @@ -154,7 +154,7 @@ static int sndk_do_cap_telemetry_log(struct nvme_global_ctx *ctx, } if (fsync(output) < 0) { - fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, strerror(errno)); + fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, nvme_strerror(errno)); err = -1; } @@ -211,7 +211,7 @@ static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file, if (!log) { fprintf(stderr, "%s: ERROR: log header malloc failed : status %s, size 0x%x\n", - __func__, strerror(errno), udui_log_hdr_size); + __func__, nvme_strerror(errno), udui_log_hdr_size); return -1; } memset(log, 0, udui_log_hdr_size); @@ -239,7 +239,7 @@ static int sndk_do_cap_udui(struct nvme_transport_handle *hdl, char *file, output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", __func__, file, - strerror(errno)); + nvme_strerror(errno)); goto out; } @@ -387,7 +387,7 @@ static int sndk_vs_internal_fw_log(int argc, char **argv, /* verify file name and path is valid before getting dump data */ verify_file = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (verify_file < 0) { - fprintf(stderr, "ERROR: SNDK: open: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: SNDK: open: %s\n", nvme_strerror(errno)); goto out; } close(verify_file); @@ -854,7 +854,7 @@ static int sndk_get_fw_act_history_C2(struct nvme_global_ctx *ctx, struct nvme_t data = (__u8 *)malloc(sizeof(__u8) * SNDK_FW_ACT_HISTORY_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: SNDK: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: SNDK: malloc: %s\n", nvme_strerror(errno)); return -1; } diff --git a/plugins/sandisk/sandisk-utils.c b/plugins/sandisk/sandisk-utils.c index 1b28f9e1da..4efc687080 100644 --- a/plugins/sandisk/sandisk-utils.c +++ b/plugins/sandisk/sandisk-utils.c @@ -439,7 +439,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, data = (__u8 *)malloc(sizeof(__u8) * SNDK_DEV_MGMNT_LOG_PAGE_LEN); if (!data) { - fprintf(stderr, "ERROR: SNDK: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: SNDK: malloc: %s\n", nvme_strerror(errno)); return false; } @@ -468,7 +468,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, free(data); data = calloc(length, sizeof(__u8)); if (!data) { - fprintf(stderr, "ERROR: SNDK: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: SNDK: malloc: %s\n", nvme_strerror(errno)); goto end; } @@ -493,7 +493,7 @@ bool sndk_get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, /* Ensure size of log data matches length in log header */ *log_data = calloc(length, sizeof(__u8)); if (!*log_data) { - fprintf(stderr, "ERROR: SNDK: calloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: SNDK: calloc: %s\n", nvme_strerror(errno)); valid = false; goto end; } diff --git a/plugins/wdc/wdc-nvme.c b/plugins/wdc/wdc-nvme.c index bd4510e1c0..8e7aee4ca6 100644 --- a/plugins/wdc/wdc-nvme.c +++ b/plugins/wdc/wdc-nvme.c @@ -2257,14 +2257,14 @@ static int wdc_create_log_file(const char *file, const __u8 *drive_log_data, fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) { - fprintf(stderr, "ERROR: WDC: open: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: open: %s\n", nvme_strerror(errno)); return -1; } while (drive_log_length > WRITE_SIZE) { ret = write(fd, drive_log_data, WRITE_SIZE); if (ret < 0) { - fprintf(stderr, "ERROR: WDC: write: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: write: %s\n", nvme_strerror(errno)); close(fd); return -1; } @@ -2274,13 +2274,13 @@ static int wdc_create_log_file(const char *file, const __u8 *drive_log_data, ret = write(fd, drive_log_data, drive_log_length); if (ret < 0) { - fprintf(stderr, "ERROR: WDC: write: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: write: %s\n", nvme_strerror(errno)); close(fd); return -1; } if (fsync(fd) < 0) { - fprintf(stderr, "ERROR: WDC: fsync: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: fsync: %s\n", nvme_strerror(errno)); close(fd); return -1; } @@ -2556,7 +2556,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * data = (__u8 *)malloc(sizeof(__u8) * WDC_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return false; } @@ -2585,7 +2585,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * free(data); data = calloc(length, sizeof(__u8)); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); goto end; } @@ -2610,7 +2610,7 @@ static bool get_dev_mgmt_log_page_data(struct nvme_transport_handle *hdl, void * /* Ensure size of log data matches length in log header */ *log_data = calloc(length, sizeof(__u8)); if (!*log_data) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); valid = false; goto end; } @@ -2641,7 +2641,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, data = (__u8 *)malloc(sizeof(__u8) * WDC_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return false; } @@ -2669,7 +2669,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, free(data); data = calloc(length, sizeof(__u8)); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); goto end; } @@ -2696,7 +2696,7 @@ static bool get_dev_mgmt_log_page_lid_data(struct nvme_transport_handle *hdl, if (found) { *cbs_data = calloc(le32_to_cpu(sph->length), sizeof(__u8)); if (!*cbs_data) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); found = false; goto end; } @@ -3122,7 +3122,7 @@ static int wdc_do_dump(struct nvme_transport_handle *hdl, __u32 opcode, __u32 da dump_data = (__u8 *)malloc(sizeof(__u8) * dump_length); if (!dump_data) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); return -1; } memset(dump_data, 0, sizeof(__u8) * dump_length); @@ -3190,7 +3190,7 @@ static int wdc_do_dump_e6(struct nvme_transport_handle *hdl, __u32 opcode, __u32 dump_data = (__u8 *)malloc(sizeof(__u8) * data_len); if (!dump_data) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); return -1; } memset(dump_data, 0, sizeof(__u8) * data_len); @@ -3320,7 +3320,7 @@ static int wdc_do_cap_telemetry_log(struct nvme_global_ctx *ctx, output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", - __func__, file, strerror(errno)); + __func__, file, nvme_strerror(errno)); return output; } @@ -3369,7 +3369,7 @@ static int wdc_do_cap_telemetry_log(struct nvme_global_ctx *ctx, } if (fsync(output) < 0) { - fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, strerror(errno)); + fprintf(stderr, "ERROR: %s: fsync: %s\n", __func__, nvme_strerror(errno)); err = -1; } @@ -3389,7 +3389,7 @@ static int wdc_do_cap_diag(struct nvme_global_ctx *ctx, struct nvme_transport_ha log_hdr = (struct wdc_e6_log_hdr *)malloc(e6_log_hdr_size); if (!log_hdr) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); ret = -1; goto out; } @@ -3483,7 +3483,7 @@ static int wdc_do_cap_dui_v1(struct nvme_transport_handle *hdl, char *file, __u3 dump_data = (__u8 *)malloc(sizeof(__u8) * xfer_size); if (!dump_data) { fprintf(stderr, "%s: ERROR: dump data V1 malloc failed : status %s, size = 0x%x\n", - __func__, strerror(errno), (unsigned int)xfer_size); + __func__, nvme_strerror(errno), (unsigned int)xfer_size); return -1; } memset(dump_data, 0, sizeof(__u8) * xfer_size); @@ -3491,7 +3491,7 @@ static int wdc_do_cap_dui_v1(struct nvme_transport_handle *hdl, char *file, __u3 output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", __func__, file, - strerror(errno)); + nvme_strerror(errno)); free(dump_data); return output; } @@ -3617,7 +3617,7 @@ static int wdc_do_cap_dui_v2_v3(struct nvme_transport_handle *hdl, char *file, _ if (!dump_data) { fprintf(stderr, "%s: ERROR: dump data v3 malloc failed : status %s, size = 0x%"PRIx64"\n", - __func__, strerror(errno), (uint64_t)xfer_size_long); + __func__, nvme_strerror(errno), (uint64_t)xfer_size_long); return -1; } memset(dump_data, 0, sizeof(__u8) * xfer_size_long); @@ -3625,7 +3625,7 @@ static int wdc_do_cap_dui_v2_v3(struct nvme_transport_handle *hdl, char *file, _ output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", - __func__, file, strerror(errno)); + __func__, file, nvme_strerror(errno)); free(dump_data); return output; } @@ -3758,7 +3758,7 @@ static int wdc_do_cap_dui_v4(struct nvme_transport_handle *hdl, char *file, __u3 dump_data = (__u8 *)malloc(sizeof(__u8) * xfer_size_long); if (!dump_data) { fprintf(stderr, "%s: ERROR: dump data V4 malloc failed : status %s, size = 0x%x\n", - __func__, strerror(errno), (unsigned int)xfer_size_long); + __func__, nvme_strerror(errno), (unsigned int)xfer_size_long); return -1; } memset(dump_data, 0, sizeof(__u8) * xfer_size_long); @@ -3766,7 +3766,7 @@ static int wdc_do_cap_dui_v4(struct nvme_transport_handle *hdl, char *file, __u3 output = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { fprintf(stderr, "%s: Failed to open output file %s: %s!\n", __func__, file, - strerror(errno)); + nvme_strerror(errno)); free(dump_data); return output; } @@ -3841,7 +3841,7 @@ static int wdc_do_cap_dui(struct nvme_transport_handle *hdl, char *file, __u32 x log_hdr = (struct wdc_dui_log_hdr *)malloc(dui_log_hdr_size); if (!log_hdr) { fprintf(stderr, "%s: ERROR: log header malloc failed : status %s, size 0x%x\n", - __func__, strerror(errno), dui_log_hdr_size); + __func__, nvme_strerror(errno), dui_log_hdr_size); return -1; } memset(log_hdr, 0, dui_log_hdr_size); @@ -3959,7 +3959,7 @@ static int wdc_do_get_sn730_log_len(struct nvme_transport_handle *hdl, uint32_t output = (uint32_t *)malloc(sizeof(uint32_t)); if (!output) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } memset(output, 0, sizeof(uint32_t)); @@ -3986,7 +3986,7 @@ static int wdc_do_get_sn730_log(struct nvme_transport_handle *hdl, void *log_buf output = (uint8_t *)calloc(SN730_LOG_CHUNK_SIZE, sizeof(uint8_t)); if (!output) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); return -1; } memset(&admin_cmd, 0, sizeof(struct nvme_passthru_cmd)); @@ -4012,7 +4012,7 @@ static int get_sn730_log_chunks(struct nvme_transport_handle *hdl, uint8_t *log_ chunk_buf = (uint8_t *)malloc(sizeof(uint8_t) * SN730_LOG_CHUNK_SIZE); if (!chunk_buf) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); ret = -1; goto out; } @@ -4055,7 +4055,7 @@ static int wdc_do_sn730_get_and_tar(struct nvme_transport_handle *hdl, char *out tarInfo = (struct tarfile_metadata *)malloc(sizeof(struct tarfile_metadata)); if (!tarInfo) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); ret = -1; goto free_buf; } @@ -4115,7 +4115,7 @@ static int wdc_do_sn730_get_and_tar(struct nvme_transport_handle *hdl, char *out extended_log_buf = (uint8_t *) calloc(extended_log_len, sizeof(uint8_t)); if (!full_log_buf || !key_log_buf || !core_dump_log_buf || !extended_log_buf) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); ret = -1; goto free_buf; } @@ -4200,7 +4200,7 @@ static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir hdr = malloc(bs); telemetry_log = malloc(bs); if (!hdr || !telemetry_log) { - fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n", bs, strerror(errno)); + fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n", bs, nvme_strerror(errno)); err = -ENOMEM; goto free_mem; } @@ -4209,7 +4209,7 @@ static int dump_internal_logs(struct nvme_transport_handle *hdl, const char *dir sprintf(file_path, "%s/telemetry.bin", dir_name); output = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (output < 0) { - fprintf(stderr, "Failed to open output file %s: %s!\n", file_path, strerror(errno)); + fprintf(stderr, "Failed to open output file %s: %s!\n", file_path, nvme_strerror(errno)); err = output; goto free_mem; } @@ -4377,7 +4377,7 @@ static int wdc_vs_internal_fw_log(int argc, char **argv, struct command *acmd, /* verify file name and path is valid before getting dump data */ verify_file = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (verify_file < 0) { - fprintf(stderr, "ERROR: WDC: open: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: open: %s\n", nvme_strerror(errno)); goto out; } close(verify_file); @@ -4680,7 +4680,7 @@ static int wdc_do_drive_log(struct nvme_transport_handle *hdl, const char *file) drive_log_data = (__u8 *)malloc(sizeof(__u8) * drive_log_length); if (!drive_log_data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -6329,7 +6329,7 @@ static int nvme_get_print_ocp_cloud_smart_log(struct nvme_transport_handle *hdl, log_ptr = (struct ocp_cloud_smart_log *)malloc(sizeof(__u8) * length); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -6394,7 +6394,7 @@ static int nvme_get_print_c0_eol_log(struct nvme_transport_handle *hdl, log_ptr = (void *)malloc(sizeof(__u8) * length); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -6436,7 +6436,7 @@ static int nvme_get_ext_smart_cloud_log(struct nvme_transport_handle *hdl, __u8 log_ptr = (__u8 *)malloc(sizeof(__u8) * WDC_NVME_SMART_CLOUD_ATTR_LEN); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -6483,7 +6483,7 @@ static int nvme_get_hw_rev_log(struct nvme_transport_handle *hdl, __u8 **data, i log_ptr = (struct wdc_nvme_hw_rev_log *)malloc(sizeof(__u8) * WDC_NVME_HW_REV_LOG_PAGE_LEN); if (!log_ptr) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -7526,7 +7526,7 @@ static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor if (cust_id == WDC_CUSTOMER_ID_0x1005) { data = (__u8 *)malloc(sizeof(__u8) * WDC_FB_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -7562,7 +7562,7 @@ static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor if (cust_id == WDC_CUSTOMER_ID_0x1005) { data = (__u8 *)malloc(sizeof(__u8) * WDC_FB_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -7586,7 +7586,7 @@ static int wdc_get_ca_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor (cust_id == WDC_CUSTOMER_ID_BD)) { data = (__u8 *)malloc(sizeof(__u8) * WDC_BD_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -7649,7 +7649,7 @@ static int wdc_get_c1_log_page(struct nvme_global_ctx *ctx, data = (__u8 *)malloc(sizeof(__u8) * WDC_ADD_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_ADD_LOG_BUF_LEN); @@ -7698,7 +7698,7 @@ static int wdc_get_c3_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor data = (__u8 *)malloc(sizeof(__u8) * WDC_LATENCY_MON_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_LATENCY_MON_LOG_BUF_LEN); @@ -7770,7 +7770,7 @@ static int wdc_get_ocp_c1_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data = (__u8 *)malloc(sizeof(__u8) * WDC_ERROR_REC_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_ERROR_REC_LOG_BUF_LEN); @@ -7842,7 +7842,7 @@ static int wdc_get_ocp_c4_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data = (__u8 *)malloc(sizeof(__u8) * WDC_DEV_CAP_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_DEV_CAP_LOG_BUF_LEN); @@ -7912,7 +7912,7 @@ static int wdc_get_ocp_c5_log_page(struct nvme_global_ctx *ctx, struct nvme_tran data = (__u8 *)malloc(sizeof(__u8) * WDC_UNSUPPORTED_REQS_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_UNSUPPORTED_REQS_LOG_BUF_LEN); @@ -7990,7 +7990,7 @@ static int wdc_get_d0_log_page(struct nvme_global_ctx *ctx, struct nvme_transpor data = (__u8 *)malloc(sizeof(__u8) * WDC_NVME_VU_SMART_LOG_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } memset(data, 0, sizeof(__u8) * WDC_NVME_VU_SMART_LOG_LEN); @@ -8507,7 +8507,7 @@ static int wdc_cu_smart_log(int argc, char **argv, struct command *acmd, case WDC_NVME_SN861_DEV_ID_1: data = (__u8 *)malloc(WDC_BD_CA_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); ret = -1; break; } @@ -9320,7 +9320,7 @@ static int wdc_get_fw_act_history(struct nvme_global_ctx *ctx, struct nvme_trans data = (__u8 *)malloc(sizeof(__u8) * WDC_FW_ACT_HISTORY_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -9400,7 +9400,7 @@ static int wdc_get_fw_act_history_C2(struct nvme_global_ctx *ctx, struct nvme_tr data = (__u8 *)malloc(sizeof(__u8) * WDC_FW_ACT_HISTORY_C2_LOG_BUF_LEN); if (!data) { - fprintf(stderr, "ERROR: WDC: malloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: malloc: %s\n", nvme_strerror(errno)); return -1; } @@ -10648,7 +10648,7 @@ static int wdc_reason_identifier(int argc, char **argv, /* verify the passed in file name and path is valid before getting the dump data */ verify_file = open(cfg.file, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (verify_file < 0) { - fprintf(stderr, "ERROR: WDC: open: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: open: %s\n", nvme_strerror(errno)); return -1; } close(verify_file); @@ -11087,7 +11087,7 @@ static int wdc_save_reason_id(struct nvme_transport_handle *hdl, __u8 *rsn_ident if (stat(reason_id_path, &st) == -1) { if (mkdir(reason_id_path, 0700) < 0) { fprintf(stderr, "%s: ERROR: failed to mkdir %s: %s\n", - __func__, reason_id_path, strerror(errno)); + __func__, reason_id_path, nvme_strerror(errno)); return -1; } } @@ -11166,7 +11166,7 @@ static int wdc_do_get_reason_id(struct nvme_transport_handle *hdl, const char *f log_hdr = (struct nvme_telemetry_log *)malloc(log_hdr_size); if (!log_hdr) { - fprintf(stderr, "%s: ERROR: malloc failed, size : 0x%x, status: %s\n", __func__, log_hdr_size, strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc failed, size : 0x%x, status: %s\n", __func__, log_hdr_size, nvme_strerror(errno)); ret = -1; goto out; } @@ -11581,7 +11581,7 @@ static int wdc_do_vs_nand_stats(struct nvme_transport_handle *hdl, char *format) output = (uint8_t *)calloc(WDC_NVME_NAND_STATS_SIZE, sizeof(uint8_t)); if (!output) { - fprintf(stderr, "ERROR: WDC: calloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: calloc: %s\n", nvme_strerror(errno)); ret = -1; goto out; } @@ -11737,7 +11737,7 @@ static int wdc_vs_pcie_stats(int argc, char **argv, struct command *acmd, pcieStatsPtr = nvme_alloc_huge(pcie_stats_size, &mh); if (!pcieStatsPtr) { - fprintf(stderr, "ERROR: WDC: PCIE Stats alloc: %s\n", strerror(errno)); + fprintf(stderr, "ERROR: WDC: PCIE Stats alloc: %s\n", nvme_strerror(errno)); ret = -1; goto out; } @@ -12421,7 +12421,7 @@ static int wdc_enc_get_log(int argc, char **argv, struct command *acmd, struct p output_fd = fopen(cfg.file, "wb"); if (!output_fd) { fprintf(stderr, "%s: ERROR: opening:%s: %s\n", __func__, cfg.file, - strerror(errno)); + nvme_strerror(errno)); return -EINVAL; } } else { @@ -12466,7 +12466,7 @@ static int wdc_enc_submit_move_data(struct nvme_transport_handle *hdl, char *cmd buf = (char *)malloc(sizeof(__u8) * xfer_size); if (!buf) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); return -1; } /* send something no matter what */ @@ -12564,7 +12564,7 @@ static int wdc_enc_get_nic_log(struct nvme_transport_handle *hdl, __u8 log_id, _ dump_data = (__u8 *)malloc(sizeof(__u8) * dump_length); if (!dump_data) { - fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, strerror(errno)); + fprintf(stderr, "%s: ERROR: malloc: %s\n", __func__, nvme_strerror(errno)); return -1; } memset(dump_data, 0, sizeof(__u8) * dump_length); diff --git a/unit/test-argconfig-parse.c b/unit/test-argconfig-parse.c index d861d69279..cecad9b9b3 100644 --- a/unit/test-argconfig-parse.c +++ b/unit/test-argconfig-parse.c @@ -11,6 +11,8 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +const char *nvme_strerror(int errnum); + static int test_rc; union val { @@ -219,7 +221,7 @@ int main(void) setlocale(LC_NUMERIC, "C"); f = freopen("/dev/null", "w", stderr); if (!f) - printf("ERROR: reopening stderr failed: %s\n", strerror(errno)); + printf("ERROR: reopening stderr failed: %s\n", nvme_strerror(errno)); for (i = 0; i < ARRAY_SIZE(toval_tests); i++) toval_test(&toval_tests[i]); diff --git a/util/argconfig.c b/util/argconfig.c index 1fabfed4b9..d3e121164b 100644 --- a/util/argconfig.c +++ b/util/argconfig.c @@ -44,6 +44,8 @@ #include #include +const char *nvme_strerror(int errnum); + static bool is_null_or_empty(const char *s) { return !s || !*s; @@ -315,7 +317,7 @@ int argconfig_parse(int argc, char *argv[], const char *program_desc, short_opts = calloc(options_count * 3 + 3, sizeof(*short_opts)); if (!long_opts || !short_opts) { - fprintf(stderr, "failed to allocate memory for opts: %s\n", strerror(errno)); + fprintf(stderr, "failed to allocate memory for opts: %s\n", nvme_strerror(errno)); return -errno; }