From 676e8a6c473ceea4260589efe0de771389e181de Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Wed, 11 Aug 2021 09:50:15 +0200 Subject: [PATCH] nvme: use libnvme for printing status With commit fe62ba7 ("util: Add nvme_status_to_string()") libnvme now has a 'nvme_status_to_string()' function, which clashes with the one provided here. So drop the function in favour of the libnvme one, and convert all plugins to use nvme_show_status(). Signed-off-by: Hannes Reinecke --- nvme-print.c | 182 ++----------------------------- nvme-print.h | 1 - nvme.h | 1 - plugins/dera/dera-nvme.c | 4 +- plugins/intel/intel-nvme.c | 30 ++--- plugins/memblaze/memblaze-nvme.c | 23 ++-- plugins/micron/micron-nvme.c | 16 +-- plugins/scaleflux/sfx-nvme.c | 24 ++-- plugins/seagate/seagate-nvme.c | 31 ++---- plugins/shannon/shannon-nvme.c | 11 +- plugins/toshiba/toshiba-nvme.c | 11 +- plugins/wdc/wdc-nvme.c | 142 +++++++++++++----------- plugins/ymtc/ymtc-nvme.c | 4 +- 13 files changed, 153 insertions(+), 327 deletions(-) diff --git a/nvme-print.c b/nvme-print.c index 86ede4e7..9ef3ab29 100755 --- a/nvme-print.c +++ b/nvme-print.c @@ -2603,8 +2603,8 @@ void d_raw(unsigned char *buf, unsigned len) void nvme_show_status(__u16 status) { - fprintf(stderr, "NVMe status: %s(%#x)\n", nvme_status_to_string(status), - status); + fprintf(stderr, "NVMe status: %s(%#x)\n", + nvme_status_to_string(status, false), status); } static const char *nvme_uuid_to_string(uuid_t uuid) @@ -4560,15 +4560,16 @@ void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries, entries); printf(".................\n"); for (i = 0; i < entries; i++) { + __u16 status = le16_to_cpu(err_log[i].status_field) >> 0x1; + printf(" Entry[%2d] \n", i); printf(".................\n"); printf("error_count : %"PRIu64"\n", le64_to_cpu(err_log[i].error_count)); printf("sqid : %d\n", err_log[i].sqid); printf("cmdid : %#x\n", err_log[i].cmdid); - printf("status_field : %#x(%s)\n", err_log[i].status_field >> 0x1, - nvme_status_to_string( - le16_to_cpu(err_log[i].status_field) >> 1)); + printf("status_field : %#x(%s)\n", status, + nvme_status_to_string(status, false)); printf("phase_tag : %#x\n", le16_to_cpu(err_log[i].status_field & 0x1)); printf("parm_err_loc : %#x\n", @@ -4992,7 +4993,7 @@ static void nvme_show_self_test_result(struct nvme_st_result *res, printf(" Status Code : %#x", res->sc); if (flags & VERBOSE) printf(" %s", nvme_status_to_string( - (res->sct & 7) << 8 | res->sc)); + (res->sct & 7) << 8 | res->sc, false)); printf("\n"); } printf(" Vendor Specific : %#x %#x\n", @@ -5180,175 +5181,6 @@ void nvme_show_select_result(__u32 result) printf(" Feature is changeable\n"); } -static const char * const generic_status[] = { - [NVME_SC_SUCCESS] = "Successful Completion: The command completed without error", - [NVME_SC_INVALID_OPCODE] = "Invalid Command Opcode: A reserved coded value or an unsupported value in the command opcode field", - [NVME_SC_INVALID_FIELD] = "Invalid Field in Command: A reserved coded value or an unsupported value in a defined field", - [NVME_SC_CMDID_CONFLICT] = "Command ID Conflict: The command identifier is already in use", - [NVME_SC_DATA_XFER_ERROR] = "Data Transfer Error: Transferring the data or metadata associated with a command experienced an error", - [NVME_SC_POWER_LOSS] = "Commands Aborted due to Power Loss Notification: Indicates that the command was aborted due to a power loss notification", - [NVME_SC_INTERNAL] = "Internal Error: The command was not completed successfully due to an internal error", - [NVME_SC_ABORT_REQ] = "Command Abort Requested: The command was aborted due to an Abort command", - [NVME_SC_ABORT_QUEUE] = "Command Aborted due to SQ Deletion: The command was aborted due to a Delete I/O Submission Queue", - [NVME_SC_FUSED_FAIL] = "Command Aborted due to Failed Fused Command: The command was aborted due to the other command in a fused operation failing", - [NVME_SC_FUSED_MISSING] = "Command Aborted due to Missing Fused Command: The fused command was aborted due to the adjacent submission queue entry not containing a fused command", - [NVME_SC_INVALID_NS] = "Invalid Namespace or Format: The namespace or the format of that namespace is invalid", - [NVME_SC_CMD_SEQ_ERROR] = "Command Sequence Error: The command was aborted due to a protocol violation in a multi- command sequence", - [NVME_SC_SGL_INVALID_LAST] = "Invalid SGL Segment Descriptor: The command includes an invalid SGL Last Segment or SGL Segment descriptor", - [NVME_SC_SGL_INVALID_COUNT] = "Invalid Number of SGL Descriptors: There is an SGL Last Segment descriptor or an SGL Segment descriptor in a location other than the last descriptor of a segment based on the length indicated", - [NVME_SC_SGL_INVALID_DATA] = "Data SGL Length Invalid: The length of a Data SGL is too short or too long and the controller does not support SGL transfers longer than the amount of data to be transferred", - [NVME_SC_SGL_INVALID_METADATA] = "Metadata SGL Length Invalid: The length of a Metadata SGL is too short or too long and the controller does not support SGL transfers longer than the amount of data to be transferred", - [NVME_SC_SGL_INVALID_TYPE] = "SGL Descriptor Type Invalid: The type of an SGL Descriptor is a type that is not supported by the controller", - [NVME_SC_CMB_INVALID_USE] = "Invalid Use of Controller Memory Buffer: The attempted use of the Controller Memory Buffer is not supported by the controller", - [NVME_SC_PRP_INVALID_OFFSET] = "PRP Offset Invalid: The Offset field for a PRP entry is invalid", - [NVME_SC_AWU_EXCEEDED] = "Atomic Write Unit Exceeded: The length specified exceeds the atomic write unit size", - [NVME_SC_OP_DENIED] = "Operation Denied: The command was denied due to lack of access rights", - [NVME_SC_SGL_INVALID_OFFSET] = "SGL Offset Invalid: The offset specified in a descriptor is invalid", - [NVME_SC_HOSTID_FORMAT] = "Host Identifier Inconsistent Format: The NVM subsystem detected the simultaneous use of 64- bit and 128-bit Host Identifier values on different controllers", - [NVME_SC_KAT_EXPIRED] = "Keep Alive Timer Expired: The Keep Alive Timer expired", - [NVME_SC_KAT_INVALID] = "Keep Alive Timeout Invalid: The Keep Alive Timeout value specified is invalid", - [NVME_SC_CMD_ABORTED_PREMEPT] = "Command Aborted due to Preempt and Abort: The command was aborted due to a Reservation Acquire command", - [NVME_SC_SANITIZE_FAILED] = "Sanitize Failed: The most recent sanitize operation failed and no recovery action has been successfully completed", - [NVME_SC_SANITIZE_IN_PROGRESS] = "Sanitize In Progress: The requested function is prohibited while a sanitize operation is in progress", - [NVME_SC_SGL_INVALID_GRANULARITY] = "SGL Data Block Granularity Invalid: The Address alignment or Length granularity for an SGL Data Block descriptor is invalid", - [NVME_SC_CMD_IN_CMBQ_NOT_SUPP] = "Command Not Supported for Queue in CMB: The controller does not support Submission Queue in the Controller Memory Buffer or Completion Queue in the Controller Memory Buffer", - [NVME_SC_NS_WRITE_PROTECTED] = "Namespace is Write Protected: The command is prohibited while the namespace is write protected", - [NVME_SC_CMD_INTERRUPTED] = "Command Interrupted: Command processing was interrupted and the controller is unable to successfully complete the command", - [NVME_SC_TRAN_TPORT_ERROR] = "Transient Transport Error: A transient transport error was detected", - [NVME_SC_LBA_RANGE] = "LBA Out of Range: The command references an LBA that exceeds the size of the namespace", - [NVME_SC_CAP_EXCEEDED] = "Capacity Exceeded: Execution of the command has caused the capacity of the namespace to be exceeded", - [NVME_SC_NS_NOT_READY] = "Namespace Not Ready: The namespace is not ready to be accessed", - [NVME_SC_RESERVATION_CONFLICT] = "Reservation Conflict: The command was aborted due to a conflict with a reservation held on the accessed namespace", - [NVME_SC_FORMAT_IN_PROGRESS] = "Format In Progress: A Format NVM command is in progress on the namespace", -}; - -static const char * const cmd_spec_status[] = { - [NVME_SC_CQ_INVALID] = "Completion Queue Invalid: The Completion Queue identifier specified in the command does not exist", - [NVME_SC_QID_INVALID] = "Invalid Queue Identifier: The creation of the I/O Completion Queue failed due to an invalid queue identifier specified as part of the command", - [NVME_SC_QUEUE_SIZE] = "Invalid Queue Size: The host attempted to create an I/O Completion Queue with an invalid number of entries", - [NVME_SC_ABORT_LIMIT] = "Abort Command Limit Exceeded: The number of concurrently outstanding Abort commands has exceeded the limit indicated in the Identify Controller data structure", - [NVME_SC_ASYNC_LIMIT] = "Asynchronous Event Request Limit Exceeded: The number of concurrently outstanding Asynchronous Event Request commands has been exceeded", - [NVME_SC_FIRMWARE_SLOT] = "Invalid Firmware Slot: The firmware slot indicated is invalid or read only", - [NVME_SC_FIRMWARE_IMAGE] = "Invalid Firmware Image: The firmware image specified for activation is invalid and not loaded by the controller", - [NVME_SC_INVALID_VECTOR] = "Invalid Interrupt Vector: The creation of the I/O Completion Queue failed due to an invalid interrupt vector specified as part of the command", - [NVME_SC_INVALID_LOG_PAGE] = "Invalid Log Page: The log page indicated is invalid", - [NVME_SC_INVALID_FORMAT] = "Invalid Format: The LBA Format specified is not supported", - [NVME_SC_FW_NEEDS_CONV_RESET] = "Firmware Activation Requires Conventional Reset: The firmware commit was successful, however, activation of the firmware image requires a conventional reset", - [NVME_SC_INVALID_QUEUE] = "Invalid Queue Deletion: Invalid I/O Completion Queue specified to delete", - [NVME_SC_FEATURE_NOT_SAVEABLE] = "Feature Identifier Not Saveable: The Feature Identifier specified does not support a saveable value", - [NVME_SC_FEATURE_NOT_CHANGEABLE] = "Feature Not Changeable: The Feature Identifier is not able to be changed", - [NVME_SC_FEATURE_NOT_PER_NS] = "Feature Not Namespace Specific: The Feature Identifier specified is not namespace specific", - [NVME_SC_FW_NEEDS_SUBSYS_RESET] = "Firmware Activation Requires NVM Subsystem Reset: The firmware commit was successful, however, activation of the firmware image requires an NVM Subsystem", - [NVME_SC_FW_NEEDS_RESET] = "Firmware Activation Requires Controller Level Reset: The firmware commit was successful; however, the image specified does not support being activated without a reset", - [NVME_SC_FW_NEEDS_MAX_TIME] = "Firmware Activation Requires Maximum Time Violation: The image specified if activated immediately would exceed the Maximum Time for Firmware Activation (MTFA) value reported in Identify Controller", - [NVME_SC_FW_ACTIVATE_PROHIBITED] = "Firmware Activation Prohibited: The image specified is being prohibited from activation by the controller for vendor specific reasons", - [NVME_SC_OVERLAPPING_RANGE] = "Overlapping Range: The downloaded firmware image has overlapping ranges", - [NVME_SC_NS_INSUFFICIENT_CAP] = "Namespace Insufficient Capacity: Creating the namespace requires more free space than is currently available", - [NVME_SC_NS_ID_UNAVAILABLE] = "Namespace Identifier Unavailable: The number of namespaces supported has been exceeded", - [NVME_SC_NS_ALREADY_ATTACHED] = "Namespace Already Attached: The controller is already attached to the namespace specified", - [NVME_SC_NS_IS_PRIVATE] = "Namespace Is Private: The namespace is private and is already attached to one controller", - [NVME_SC_NS_NOT_ATTACHED] = "Namespace Not Attached: The request to detach the controller could not be completed because the controller is not attached to the namespace", - [NVME_SC_THIN_PROV_NOT_SUPP] = "Thin Provisioning Not Supported: Thin provisioning is not supported by the controller", - [NVME_SC_CTRL_LIST_INVALID] = "Controller List Invalid: The controller list provided contains invalid controller ids", - [NVME_SC_SELF_TEST_IN_PROGRESS] = "Device Self-test In Progress", - [NVME_SC_BP_WRITE_PROHIBITED] = "Boot Partition Write Prohibited: The command tried to modify a locked Boot Partition", - [NVME_SC_INVALID_CTRL_ID] = "Invalid Controller Identifier: An invalid controller id was specified", - [NVME_SC_INVALID_SEC_CTRL_STATE] = "Invalid Secondary Controller State: The requested secondary controller action is invalid based on the secondary and primary controllers current states", - [NVME_SC_INVALID_CTRL_RESOURCES] = "Invalid Number of Controller Resources: The specified number of Flexible Resources is invalid", - [NVME_SC_INVALID_RESOURCE_ID] = "Invalid Resource Identifier: At least one of the specified resource identifiers was invalid", - [NVME_SC_PMR_SAN_PROHIBITED] = "Sanitize Prohibited While Persistent Memory Region is Enabled", - [NVME_SC_ANA_GROUP_ID_INVALID] = "ANA Group Identifier Invalid", - [NVME_SC_ANA_ATTACH_FAILED] = "ANA Attach Failed: The command's specified ANA Group Identifier is not supported", -}; - -static const char * const nvm_status[] = { - [NVME_SC_BAD_ATTRIBUTES] = "Conflicting Attributes: The attributes specified in the command are conflicting", - [NVME_SC_INVALID_PI] = "Invalid Protection Information: The command's Protection Information Field settings are invalid for the namespace's Protection Information format", - [NVME_SC_READ_ONLY] = "Attempted Write to Read Only Range: The LBA range specified contains read-only blocks", -}; - -static const char * const nvmf_status[] = { - [NVME_SC_CONNECT_FORMAT] = "Incompatible Format: The NVM subsystem does not support the record format specified by the host", - [NVME_SC_CONNECT_CTRL_BUSY] = "Controller Busy: The controller is already associated with a host", - [NVME_SC_CONNECT_INVALID_PARAM] = "Connect Invalid Parameters: One or more of the command parameters", - [NVME_SC_CONNECT_RESTART_DISC] = "Connect Restart Discovery: The NVM subsystem requested is not available", - [NVME_SC_CONNECT_INVALID_HOST] = "Connect Invalid Host: The host is not allowed to establish an association to either any controller in the NVM subsystem or the specified controller", - [NVME_SC_DISCONNECT_INVALID_QTYPE] = "Invalid Queue Type: The command was sent on the wrong queue type", - [NVME_SC_DISCOVERY_RESTART] = "Discover Restart: The snapshot of the records is now invalid or out of date", - [NVME_SC_AUTH_REQUIRED] = "Authentication Required: NVMe in-band authentication is required and the queue has not yet been authenticated", -}; - -static const char * const media_status[] = { - [NVME_SC_WRITE_FAULT] = "Write Fault: The write data could not be committed to the media", - [NVME_SC_READ_ERROR] = "Unrecovered Read Error: The read data could not be recovered from the media", - [NVME_SC_GUARD_CHECK] = "End-to-end Guard Check Error: The command was aborted due to an end-to-end guard check failure", - [NVME_SC_APPTAG_CHECK] = "End-to-end Application Tag Check Error: The command was aborted due to an end-to-end application tag check failure", - [NVME_SC_REFTAG_CHECK] = "End-to-end Reference Tag Check Error: The command was aborted due to an end-to-end reference tag check failure", - [NVME_SC_COMPARE_FAILED] = "Compare Failure: The command failed due to a miscompare during a Compare command", - [NVME_SC_ACCESS_DENIED] = "Access Denied: Access to the namespace and/or LBA range is denied due to lack of access rights", - [NVME_SC_UNWRITTEN_BLOCK] = "Deallocated or Unwritten Logical Block: The command failed due to an attempt to read from or verify an LBA range containing a deallocated or unwritten logical block", -}; - -static const char * const path_status[] = { - [NVME_SC_ANA_INTERNAL_PATH_ERROR] = "Internal Path Error: An internal error specific to the controller processing the commmand prevented completion", - [NVME_SC_ANA_PERSISTENT_LOSS] = "Asymmetric Access Persistent Loss: The controller is in a persistent loss state with the requested namespace", - [NVME_SC_ANA_INACCESSIBLE] = "Asymmetric Access Inaccessible: The controller is in an inaccessible state with the requested namespace", - [NVME_SC_ANA_TRANSITION] = "Asymmetric Access Transition: The controller is currently transitioning states with the requested namespace", - [NVME_SC_CTRL_PATH_ERROR] = "Controller Pathing Error: A pathing error was detected by the controller", - [NVME_SC_HOST_PATH_ERROR] = "Host Pathing Error: A pathing error was detected by the host", - [NVME_SC_CMD_ABORTED_BY_HOST] = "Command Aborted By Host: The command was aborted as a result of host action", -}; - -#define ARGSTR(s, i) arg_str(s, ARRAY_SIZE(s), i) - -static const char *arg_str(const char * const *strings, - size_t array_size, size_t idx) -{ - if (idx < array_size && strings[idx]) - return strings[idx]; - return "unrecognized"; -} - -const char *nvme_status_to_string(__u16 status) -{ - const char *s = "Unknown status"; - __u16 sc, sct; - bool fabrics = false; /* make this a parameter */ - - if (status < 0) - return strerror(errno); - - sc = nvme_status_code(status); - sct = nvme_status_code_type(status); - - switch (sct) { - case NVME_SCT_GENERIC: - s = ARGSTR(generic_status, sc); - break; - case NVME_SCT_CMD_SPECIFIC: - if (sc < ARRAY_SIZE(cmd_spec_status)) - s = ARGSTR(cmd_spec_status, sc); - else if (fabrics) - s = ARGSTR(nvmf_status, sc); - else - s = ARGSTR(nvm_status, sc); - break; - case NVME_SCT_MEDIA: - s = ARGSTR(media_status, sc); - break; - case NVME_SCT_PATH: - s = ARGSTR(path_status, sc); - break; - case NVME_SCT_VS: - s = "Vendor Specific Status"; - break; - default: - break; - } - - return s; -} - static const char *nvme_feature_lba_type_to_string(__u8 type) { switch (type) { diff --git a/nvme-print.h b/nvme-print.h index efecf402..0a606f4e 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -105,7 +105,6 @@ void nvme_show_zns_report_zones(void *report, __u32 descs, __u8 ext_size, __u32 report_size, unsigned long flags); const char *nvme_cmd_to_string(int admin, __u8 opcode); -const char *nvme_status_to_string(__u16 status); const char *nvme_select_to_string(int sel); const char *nvme_feature_to_string(enum nvme_features_id feature); const char *nvme_register_to_string(int reg); diff --git a/nvme.h b/nvme.h index 50e7bdf7..63cb6c89 100644 --- a/nvme.h +++ b/nvme.h @@ -80,7 +80,6 @@ unsigned long long elapsed_utime(struct timeval start_time, struct timeval end_time); /* nvme-print.c */ -const char *nvme_status_to_string(uint16_t status); const char *nvme_select_to_string(int sel); void d(unsigned char *buf, int len, int width, int group); diff --git a/plugins/dera/dera-nvme.c b/plugins/dera/dera-nvme.c index f4163bae..976e084b 100644 --- a/plugins/dera/dera-nvme.c +++ b/plugins/dera/dera-nvme.c @@ -12,6 +12,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "dera-nvme.h" @@ -200,7 +202,7 @@ static int get_status(int argc, char **argv, struct command *cmd, struct plugin exit: if (err > 0) - fprintf(stderr, "\nNVMe status:%s(0x%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); return err; } diff --git a/plugins/intel/intel-nvme.c b/plugins/intel/intel-nvme.c index 77abdc91..ba173753 100644 --- a/plugins/intel/intel-nvme.c +++ b/plugins/intel/intel-nvme.c @@ -10,6 +10,7 @@ #include "libnvme.h" #include "plugin.h" #include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "intel-nvme.h" @@ -375,8 +376,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd, d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -411,8 +411,7 @@ static int get_market_log(int argc, char **argv, struct command *cmd, struct plu else d_raw((unsigned char *)&log, sizeof(log)); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -472,8 +471,7 @@ static int get_temp_stats_log(int argc, char **argv, struct command *cmd, struct else d_raw((unsigned char *)&stats, sizeof(stats)); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -1059,8 +1057,8 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct err = nvme_get_features(fd, 0xf7, 0, 0, cfg.write ? 0x1 : 0x0, 0, sizeof(thresholds), thresholds, &result); if (err) { - fprintf(stderr, "Quering thresholds failed. NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + fprintf(stderr, "Quering thresholds failed. "); + nvme_show_status(err); goto close_fd; } @@ -1089,8 +1087,7 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct else d_raw((unsigned char *)&stats, sizeof(stats)); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); close_fd: close(fd); return err; @@ -1467,8 +1464,7 @@ static int get_internal_log(int argc, char **argv, struct command *command, err = 0; out: if (err > 0) { - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); } else if (err < 0) { perror("intel log"); err = EIO; @@ -1547,8 +1543,7 @@ static int enable_lat_stats_tracking(int argc, char **argv, err = nvme_set_features(fd, fid, nsid, option, cdw12, save, 0, 0, data_len, buf, &result); if (err > 0) { - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); } else if (err < 0) { perror("Enable latency tracking"); fprintf(stderr, "Command failed while parsing.\n"); @@ -1607,8 +1602,8 @@ static int set_lat_stats_thresholds(int argc, char **argv, err = nvme_get_log_simple(fd, 0xc2, sizeof(media_version), media_version); if (err) { - fprintf(stderr, "Querying media version failed. NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + fprintf(stderr, "Querying media version failed. "); + nvme_show_status(err); goto close_fd; } @@ -1629,8 +1624,7 @@ static int set_lat_stats_thresholds(int argc, char **argv, thresholds, &result); if (err > 0) { - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); } else if (err < 0) { perror("Enable latency tracking"); fprintf(stderr, "Command failed while parsing.\n"); diff --git a/plugins/memblaze/memblaze-nvme.c b/plugins/memblaze/memblaze-nvme.c index 0ace7d51..1d45ee74 100644 --- a/plugins/memblaze/memblaze-nvme.c +++ b/plugins/memblaze/memblaze-nvme.c @@ -8,6 +8,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "memblaze-nvme.h" @@ -468,7 +470,7 @@ static int mb_get_additional_smart_log(int argc, char **argv, struct command *cm d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -506,7 +508,7 @@ static int mb_get_powermanager_status(int argc, char **argv, struct command *cmd mb_feature_to_string(feature_id), nvme_select_to_string(0), result); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -548,7 +550,7 @@ static int mb_set_powermanager_status(int argc, char **argv, struct command *cmd printf("set-feature:%02x (%s), value:%#08x\n", cfg.feature_id, mb_feature_to_string(cfg.feature_id), cfg.value); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -606,7 +608,7 @@ static int mb_set_high_latency_log(int argc, char **argv, struct command *cmd, s printf("set-feature:0x%02X (%s), value:%#08x\n", cfg.feature_id, mb_feature_to_string(cfg.feature_id), cfg.value); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -723,7 +725,7 @@ static int mb_high_latency_log_print(int argc, char **argv, struct command *cmd, if (!glp_high_latency(fdi, buf, LOG_PAGE_SIZE, DO_PRINT_FLAG)) break; err = nvme_get_log_simple(fd, GLP_ID_VU_GET_HIGH_LATENCY_LOG, sizeof(buf), &buf); if ( err) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); break; } } @@ -840,8 +842,7 @@ static int mb_selective_download(int argc, char **argv, struct command *cmd, str perror("fw-download"); goto out; } else if (err != 0) { - fprintf(stderr, "NVME Admin command error:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); goto out; } fw_buf += xfer; @@ -995,7 +996,7 @@ static int mb_lat_stats_log_print(int argc, char **argv, struct command *cmd, st io_latency_histogram(cfg.write ? f2 : f1, stats, DO_PRINT_FLAG, cfg.write ? GLP_ID_VU_GET_WRITE_LATENCY_HISTOGRAM : GLP_ID_VU_GET_READ_LATENCY_HISTOGRAM); else - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); close(fd); return err; @@ -1042,7 +1043,8 @@ static int memblaze_clear_error_log(int argc, char **argv, struct command *cmd, if (!err) { printf("set-feature:%02x (%s), value:%#08x\n", cfg.feature_id, mb_feature_to_string(cfg.feature_id), cfg.value); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); + /* struct nvme_admin_cmd admin_cmd = { .opcode = OP, @@ -1128,8 +1130,7 @@ static int mb_set_lat_stats(int argc, char **argv, err = nvme_set_features(fd, fid, nsid, option, cdw12, save, 0, 0, data_len, buf, &result); if (err > 0) { - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); } else if (err < 0) { perror("Enable latency tracking"); fprintf(stderr, "Command failed while parsing.\n"); diff --git a/plugins/micron/micron-nvme.c b/plugins/micron/micron-nvme.c index c50de546..6665a0e1 100644 --- a/plugins/micron/micron-nvme.c +++ b/plugins/micron/micron-nvme.c @@ -12,6 +12,9 @@ #include "nvme.h" #include "libnvme.h" #include +#include "linux/types.h" +#include "nvme-print.h" + #define CREATE_CMD #include "micron-nvme.h" @@ -555,8 +558,7 @@ static int micron_selective_download(int argc, char **argv, perror("fw-download"); goto out; } else if (err != 0) { - fprintf(stderr, "NVME Admin command error:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); goto out; } fw_buf += xfer; @@ -933,8 +935,7 @@ static int micron_clear_pcie_correctable_errors(int argc, char **argv, if (err == 0 && (err = (int)result) == 0) printf("Device correctable errors cleared!\n"); else if (err > 0) - fprintf(stderr, "NVMe status: %s(%#x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else printf("Error clearing Device correctable errors = 0x%x\n", err); goto out; @@ -1395,8 +1396,8 @@ static int micron_nand_stats(int argc, char **argv, out: close(fd); if (err > 0) - fprintf(stderr, "NVMe status: %s(%#x)\n", nvme_status_to_string(err), - err); + nvme_show_status(err); + return nvme_status_to_errno(err, false); } @@ -2139,8 +2140,7 @@ static int micron_ocp_smart_health_logs(int argc, char **argv, struct command *c out: close(fd); if (err > 0) - fprintf(stderr, "NVMe status: %s(%#x)\n", nvme_status_to_string(err), - err); + nvme_show_status(err); return nvme_status_to_errno(err, false); } diff --git a/plugins/scaleflux/sfx-nvme.c b/plugins/scaleflux/sfx-nvme.c index 8938ae93..3753cec5 100644 --- a/plugins/scaleflux/sfx-nvme.c +++ b/plugins/scaleflux/sfx-nvme.c @@ -13,6 +13,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "sfx-nvme.h" @@ -364,8 +366,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd, d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -442,8 +443,7 @@ static int get_lat_stats_log(int argc, char **argv, struct command *cmd, struct else d_raw((unsigned char *)&stats, sizeof(stats)); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -574,8 +574,7 @@ static int sfx_get_bad_block(int argc, char **argv, struct command *cmd, struct if (err < 0) { perror("get-bad-block"); } else if (err != 0) { - fprintf(stderr, "NVMe IO command error:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); } else { bd_table_show(data_buf, buf_size); printf("ScaleFlux get bad block table: success\n"); @@ -781,8 +780,7 @@ static int change_cap(int argc, char **argv, struct command *cmd, struct plugin if (err < 0) perror("sfx-change-cap"); else if (err != 0) - fprintf(stderr, "NVMe IO command error:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else { printf("ScaleFlux change-capacity: success\n"); ioctl(fd, BLKRRPART); @@ -898,9 +896,7 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl if (err < 0) perror("identify-namespace"); else - fprintf(stderr, - "NVMe Admin command error:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } /* @@ -932,8 +928,7 @@ static int sfx_set_feature(int argc, char **argv, struct command *cmd, struct pl printf("ScaleFlux set-feature:%#02x (%s), value:%d\n", cfg.feature_id, sfx_feature_to_string(cfg.feature_id), cfg.value); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -981,8 +976,7 @@ static int sfx_get_feature(int argc, char **argv, struct command *cmd, struct pl printf("ScaleFlux get-feature:%02x (%s), value:%d\n", cfg.feature_id, sfx_feature_to_string(cfg.feature_id), result); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; diff --git a/plugins/seagate/seagate-nvme.c b/plugins/seagate/seagate-nvme.c index 28f86a18..cf14571c 100644 --- a/plugins/seagate/seagate-nvme.c +++ b/plugins/seagate/seagate-nvme.c @@ -31,6 +31,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD @@ -195,8 +197,7 @@ static int log_pages_supp(int argc, char **argv, struct command *cmd, } if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -770,8 +771,7 @@ static int vs_smart_log(int argc, char **argv, struct command *cmd, struct plugi } else if (!strcmp(cfg.output_format, "json")) json_print_object(root, NULL); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -871,8 +871,7 @@ static int temp_stats(int argc, char **argv, struct command *cmd, struct plugin } } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); cf_err = nvme_get_log_simple(fd, 0xCF, sizeof(ExtdSMARTInfo), &logPageCF); @@ -1011,7 +1010,7 @@ static int vs_pcie_error_log(int argc, char **argv, struct command *cmd, struct json_vs_pcie_error_log(pcieErrorLog); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -1106,8 +1105,7 @@ static int get_host_tele(int argc, char **argv, struct command *cmd, struct plug } else seaget_d_raw((unsigned char *)(&tele_log), sizeof(tele_log), dump_fd); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else perror("log page"); @@ -1140,8 +1138,7 @@ static int get_host_tele(int argc, char **argv, struct command *cmd, struct plug } else seaget_d_raw((unsigned char *)log, blksToGet * 512, dump_fd); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else perror("log page"); @@ -1204,8 +1201,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *cmd, struct plug } else seaget_d_raw((unsigned char *)(&tele_log), sizeof(tele_log), dump_fd); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else perror("log page"); @@ -1238,8 +1234,7 @@ static int get_ctrl_tele(int argc, char **argv, struct command *cmd, struct plug } else seaget_d_raw((unsigned char *)log, blksToGet * 512, dump_fd); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else perror("log page"); @@ -1323,8 +1318,7 @@ static int vs_internal_log(int argc, char **argv, struct command *cmd, struct pl */ seaget_d_raw((unsigned char *)(&tele_log), sizeof(tele_log), dump_fd); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else perror("log page"); @@ -1354,8 +1348,7 @@ static int vs_internal_log(int argc, char **argv, struct command *cmd, struct pl seaget_d_raw((unsigned char *)log, blksToGet * 512, dump_fd); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); else perror("log page"); diff --git a/plugins/shannon/shannon-nvme.c b/plugins/shannon/shannon-nvme.c index 09ce5549..e7659c1f 100644 --- a/plugins/shannon/shannon-nvme.c +++ b/plugins/shannon/shannon-nvme.c @@ -9,6 +9,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "shannon-nvme.h" @@ -144,8 +146,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd, d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -244,8 +245,7 @@ static int get_additional_feature(int argc, char **argv, struct command *cmd, st } #endif } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); if (buf) free(buf); return err; @@ -353,8 +353,7 @@ static int set_additional_feature(int argc, char **argv, struct command *cmd, st if (buf) d(buf, cfg.data_len, 16, 1); } else if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + nvme_show_status(err); free: if (buf) diff --git a/plugins/toshiba/toshiba-nvme.c b/plugins/toshiba/toshiba-nvme.c index 1302ec97..8b8b2168 100644 --- a/plugins/toshiba/toshiba-nvme.c +++ b/plugins/toshiba/toshiba-nvme.c @@ -10,6 +10,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "toshiba-nvme.h" @@ -471,7 +473,7 @@ static int vendor_log(int argc, char **argv, struct command *cmd, struct plugin fprintf(stderr, "%s: couldn't get vendor log 0x%x\n", __func__, cfg.log); end: if (err > 0) - fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(err), err); + nvme_show_status(err); return err; } @@ -513,8 +515,8 @@ static int internal_log(int argc, char **argv, struct command *cmd, struct plugi if (err < 0) fprintf(stderr, "%s: couldn't get fw log \n", __func__); if (err > 0) - fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, - nvme_status_to_string(err), err); + nvme_show_status(err); + return err; } @@ -552,7 +554,6 @@ static int clear_correctable_errors(int argc, char **argv, struct command *cmd, __func__); end: if (err > 0) - fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, - nvme_status_to_string(err), err); + nvme_show_status(err); return err; } diff --git a/plugins/wdc/wdc-nvme.c b/plugins/wdc/wdc-nvme.c index 4d145ca0..6dc484c5 100644 --- a/plugins/wdc/wdc-nvme.c +++ b/plugins/wdc/wdc-nvme.c @@ -34,6 +34,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "wdc-nvme.h" @@ -1724,7 +1726,7 @@ static int wdc_do_clear_dump(int fd, __u8 opcode, __u32 cdw12) if (ret != 0) { fprintf(stdout, "ERROR : WDC : Crash dump erase failed\n"); } - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); return ret; } @@ -1748,7 +1750,7 @@ static __u32 wdc_dump_length(int fd, __u32 opcode, __u32 cdw10, __u32 cdw12, __u l->log_size = 0; ret = -1; fprintf(stderr, "ERROR : WDC : reading dump length failed\n"); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); return ret; } @@ -1774,7 +1776,7 @@ static __u32 wdc_dump_length_e6(int fd, __u32 opcode, __u32 cdw10, __u32 cdw12, ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); if (ret != 0) { fprintf(stderr, "ERROR : WDC : reading dump length failed\n"); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); } return ret; @@ -1801,7 +1803,7 @@ static __u32 wdc_dump_dui_data(int fd, __u32 dataLen, __u32 offset, __u8 *dump_d ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); if (ret != 0) { fprintf(stderr, "ERROR : WDC : reading DUI data failed\n"); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); } return ret; @@ -1832,7 +1834,7 @@ static __u32 wdc_dump_dui_data_v2(int fd, __u32 dataLen, __u64 offset, __u8 *dum ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); if (ret != 0) { fprintf(stderr, "ERROR : WDC : reading DUI data V2 failed\n"); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); } return ret; @@ -1869,8 +1871,7 @@ static int wdc_do_dump(int fd, __u32 opcode,__u32 data_len, while (curr_data_offset < data_len) { ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); if (ret != 0) { - fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n", - __func__, nvme_status_to_string(ret), ret); + nvme_show_status(ret); fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%x, offset = 0x%x, addr = 0x%lx\n", __func__, i, admin_cmd.data_len, curr_data_offset, (long unsigned int)admin_cmd.addr); break; @@ -1890,7 +1891,7 @@ static int wdc_do_dump(int fd, __u32 opcode,__u32 data_len, } if (ret == 0) { - fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + nvme_show_status(ret); ret = wdc_create_log_file(file, dump_data, dump_length); } free(dump_data); @@ -1934,7 +1935,7 @@ static int wdc_do_dump_e6(int fd, __u32 opcode,__u32 data_len, ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); if (ret != 0) { - fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + nvme_show_status(ret); fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%x, offset = 0x%x, addr = 0x%lx\n", __func__, i, admin_cmd.data_len, curr_data_offset, (long unsigned int)admin_cmd.addr); break; @@ -1946,9 +1947,11 @@ static int wdc_do_dump_e6(int fd, __u32 opcode,__u32 data_len, } if (ret == 0) { - fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + fprintf(stderr, "%s: ", __func__); + nvme_show_status(ret); } else { - fprintf(stderr, "%s: FAILURE: NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + fprintf(stderr, "%s: FAILURE: ", __func__); + nvme_show_status(ret); fprintf(stderr, "%s: Partial data may have been captured\n", __func__); snprintf(file + strlen(file), PATH_MAX, "%s", "-PARTIAL"); } @@ -1990,8 +1993,8 @@ static int wdc_do_cap_telemetry_log(int fd, char *file, __u32 bs, int type, int goto close_fd; } } else { - fprintf(stderr, "ERROR : WDC: Get telemetry option feature failed. NVMe Status:%s(%x)\n", - nvme_status_to_string(err), err); + fprintf(stderr, "ERROR : WDC: Get telemetry option feature failed."); + nvme_show_status(err); err = -EPERM; goto close_fd; } @@ -2035,7 +2038,7 @@ static int wdc_do_cap_telemetry_log(int fd, char *file, __u32 bs, int type, int if (err < 0) perror("get-telemetry-log"); else if (err > 0) { - fprintf(stderr, "NVMe status: %s(%#x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); fprintf(stderr, "%s: Failed to acquire telemetry header!\n", __func__); goto close_output; } @@ -2079,7 +2082,7 @@ static int wdc_do_cap_telemetry_log(int fd, char *file, __u32 bs, int type, int perror("get-telemetry-log"); break; } else if (err > 0) { - fprintf(stderr, "NVMe status: %s(%#x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); fprintf(stderr, "%s: Failed to acquire full telemetry log!\n", __func__); break; } @@ -2184,7 +2187,8 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in ret = wdc_dump_dui_data(fd, WDC_NVME_CAP_DUI_HEADER_SIZE, 0x00, (__u8 *)log_hdr, last_xfer); if (ret != 0) { fprintf(stderr, "%s: ERROR : WDC : Get DUI headers failed\n", __func__); - fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + fprintf(stderr, "%s: ERROR : WDC : ", __func__); + nvme_show_status(ret); goto out; } @@ -2265,7 +2269,9 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in if (ret != 0) { fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%"PRIx64", offset = 0x%x, addr = %p\n", __func__, i, (uint64_t)log_size, curr_data_offset, buffer_addr); - fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + fprintf(stderr, "%s: ERROR : WDC : ", + __func__); + nvme_show_status(ret); break; } @@ -2377,7 +2383,8 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in if (ret != 0) { fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%"PRIx64", offset = 0x%"PRIx64", addr = %p\n", __func__, i, (uint64_t)total_size, (uint64_t)curr_data_offset, buffer_addr); - fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + fprintf(stderr, "%s: ERROR : WDC : ", __func__); + nvme_show_status(ret); break; } @@ -2491,7 +2498,8 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in if (ret != 0) { fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%"PRIx64", offset = 0x%"PRIx64", addr = %p\n", __func__, i, (uint64_t)log_size, (uint64_t)curr_data_offset, buffer_addr); - fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + fprintf(stderr, "%s: ERROR : WDC :", __func__); + nvme_show_status(ret); break; } @@ -2513,8 +2521,7 @@ static int wdc_do_cap_dui(int fd, char *file, __u32 xfer_size, int data_area, in goto out; } - - fprintf(stderr, "%s: NVMe Status:%s(%x)\n", __func__, nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (verbose) fprintf(stderr, "INFO : WDC : Capture Device Unit Info log, length = 0x%"PRIx64"\n", (uint64_t)total_size); @@ -2717,22 +2724,22 @@ static int wdc_do_sn730_get_and_tar(int fd, char * outputName) ret = wdc_do_get_sn730_log_len(fd, &full_log_len, SN730_GET_FULL_LOG_LENGTH); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } ret = wdc_do_get_sn730_log_len(fd, &key_log_len, SN730_GET_KEY_LOG_LENGTH); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } ret = wdc_do_get_sn730_log_len(fd, &core_dump_log_len, SN730_GET_COREDUMP_LOG_LENGTH); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } ret = wdc_do_get_sn730_log_len(fd, &extended_log_len, SN730_GET_EXTENDED_LOG_LENGTH); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } @@ -2750,28 +2757,28 @@ static int wdc_do_sn730_get_and_tar(int fd, char * outputName) /* Get the full log */ ret = get_sn730_log_chunks(fd, full_log_buf, full_log_len, SN730_GET_FULL_LOG_SUBOPCODE); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } /* Get the key log */ ret = get_sn730_log_chunks(fd, key_log_buf, key_log_len, SN730_GET_KEY_LOG_SUBOPCODE); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } /* Get the core dump log */ ret = get_sn730_log_chunks(fd, core_dump_log_buf, core_dump_log_len, SN730_GET_CORE_LOG_SUBOPCODE); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } /* Get the extended log */ ret = get_sn730_log_chunks(fd, extended_log_buf, extended_log_len, SN730_GET_EXTEND_LOG_SUBOPCODE); if (ret) { - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); goto free_buf; } @@ -3086,8 +3093,7 @@ static int wdc_do_drive_log(int fd, char *file) WDC_NVME_SUBCMD_SHIFT) | WDC_NVME_DRIVE_LOG_SIZE_CMD); ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), - ret); + nvme_show_status(ret); if (ret == 0) { ret = wdc_create_log_file(file, drive_log_data, drive_log_length); } @@ -3342,7 +3348,7 @@ static int wdc_purge(int argc, char **argv, } fprintf(stderr, "%s", err_str); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); } nvme_free_tree(r); return ret; @@ -3400,7 +3406,7 @@ static int wdc_purge_monitor(int argc, char **argv, } } - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); } nvme_free_tree(r); return ret; @@ -4684,7 +4690,7 @@ static int wdc_get_c0_log_page(nvme_root_t r, int fd, char *format, NVME_LOG_LSP_NONE, 0, false, uuid_index, 0, WDC_NVME_SMART_CLOUD_ATTR_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { @@ -4731,7 +4737,7 @@ static int wdc_get_c0_log_page(nvme_root_t r, int fd, char *format, NVME_LOG_LSP_NONE, 0, false, uuid_index, 0, WDC_NVME_EOL_STATUS_LOG_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -4758,7 +4764,7 @@ static int wdc_get_c0_log_page(nvme_root_t r, int fd, char *format, WDC_NVME_EOL_STATUS_LOG_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -4784,7 +4790,7 @@ static int wdc_get_c0_log_page(nvme_root_t r, int fd, char *format, WDC_NVME_SMART_CLOUD_ATTR_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -4925,7 +4931,7 @@ static int wdc_get_ca_log_page(nvme_root_t r, int fd, char *format) ret = nvme_get_log_simple(fd, WDC_NVME_GET_DEVICE_INFO_LOG_OPCODE, WDC_FB_CA_LOG_BUF_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -4961,7 +4967,7 @@ static int wdc_get_ca_log_page(nvme_root_t r, int fd, char *format) ret = nvme_get_log_simple(fd, WDC_NVME_GET_DEVICE_INFO_LOG_OPCODE, WDC_FB_CA_LOG_BUF_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -4983,7 +4989,7 @@ static int wdc_get_ca_log_page(nvme_root_t r, int fd, char *format) ret = nvme_get_log_simple(fd, WDC_NVME_GET_DEVICE_INFO_LOG_OPCODE, WDC_BD_CA_LOG_BUF_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -5048,7 +5054,7 @@ static int wdc_get_c1_log_page(nvme_root_t r, int fd, ret = nvme_get_log_simple(fd, WDC_NVME_ADD_LOG_OPCODE, WDC_ADD_LOG_BUF_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { l = (struct wdc_log_page_header*)data; total_subpages = l->num_subpages + WDC_NVME_GET_STAT_PERF_INTERVAL_LIFETIME - 1; @@ -5101,7 +5107,7 @@ static int wdc_get_d0_log_page(nvme_root_t r, int fd, char *format) ret = nvme_get_log_simple(fd, WDC_NVME_GET_VU_SMART_LOG_OPCODE, WDC_NVME_VU_SMART_LOG_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -5255,7 +5261,7 @@ static int wdc_do_clear_pcie_correctable_errors(int fd) WDC_NVME_CLEAR_PCIE_CORR_CMD); ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); return ret; } @@ -5268,7 +5274,7 @@ static int wdc_do_clear_pcie_correctable_errors_vuc(int fd) admin_cmd.opcode = WDC_NVME_CLEAR_PCIE_CORR_OPCODE_VUC; ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); return ret; } @@ -5281,7 +5287,7 @@ static int wdc_do_clear_pcie_correctable_errors_fid(int fd) ret = nvme_set_features_simple(fd, WDC_NVME_CLEAR_PCIE_CORR_FEATURE_ID, 0, value, false, &result); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); return ret; } @@ -5487,7 +5493,7 @@ static int wdc_clear_assert_dump(int argc, char **argv, struct command *command, WDC_NVME_CLEAR_ASSERT_DUMP_CMD); ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); } else fprintf(stderr, "INFO : WDC : No Assert Dump Present\n"); @@ -5529,7 +5535,7 @@ static int wdc_get_fw_act_history(nvme_root_t r, int fd, char *format) WDC_FW_ACT_HISTORY_LOG_BUF_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -5586,7 +5592,7 @@ static int wdc_get_fw_act_history_C2(nvme_root_t r, int fd, char *format) WDC_FW_ACT_HISTORY_C2_LOG_BUF_LEN, data); if (strcmp(format, "json")) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); if (ret == 0) { /* parse the data */ @@ -5714,7 +5720,7 @@ static int wdc_do_clear_fw_activate_history_vuc(int fd) WDC_NVME_CLEAR_FW_ACT_HIST_CMD); ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); return ret; } @@ -5728,7 +5734,7 @@ static int wdc_do_clear_fw_activate_history_fid(int fd) ret = nvme_set_features_simple(fd, WDC_NVME_CLEAR_FW_ACT_HIST_VU_FID, 0, value, false, &result); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); return ret; } @@ -5842,7 +5848,7 @@ static int wdc_vs_telemetry_controller_option(int argc, char **argv, struct comm else fprintf(stderr, "Controller Option Telemetry Log Page State: Enabled\n"); } else { - fprintf(stderr, "ERROR : WDC: NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); } } else { @@ -5928,8 +5934,10 @@ static int wdc_de_VU_read_size(int fd, __u32 fileId, __u16 spiDestn, __u32* logS if (!ret && logSize) *logSize = cmd.result; - if( ret != WDC_STATUS_SUCCESS) - fprintf(stderr, "ERROR : WDC : VUReadSize() failed, status:%s(0x%x)\n", nvme_status_to_string(ret), ret); + if( ret != WDC_STATUS_SUCCESS) { + fprintf(stderr, "ERROR : WDC : VUReadSize() failed, "); + nvme_show_status(ret); + } end: return ret; @@ -5961,8 +5969,10 @@ static int wdc_de_VU_read_buffer(int fd, __u32 fileId, __u16 spiDestn, __u32 off ret = nvme_submit_admin_passthru(fd, &cmd, NULL); - if( ret != WDC_STATUS_SUCCESS) - fprintf(stderr, "ERROR : WDC : VUReadBuffer() failed, status:%s(0x%x)\n", nvme_status_to_string(ret), ret); + if( ret != WDC_STATUS_SUCCESS) { + fprintf(stderr, "ERROR : WDC : VUReadBuffer() failed, "); + nvme_show_status(ret); + } end: return ret; @@ -6692,7 +6702,7 @@ static int wdc_drive_resize(int argc, char **argv, if (!ret) printf("New size: %" PRIu64 " GB\n", cfg.size); - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); nvme_free_tree(r); return ret; } @@ -6749,7 +6759,7 @@ static int wdc_namespace_resize(int argc, char **argv, ret = -1; } - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); nvme_free_tree(r); return ret; } @@ -6840,7 +6850,7 @@ static int wdc_reason_identifier(int argc, char **argv, ret = -1; } - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); close_fd: close(fd); @@ -7091,7 +7101,7 @@ static int wdc_dump_telemetry_hdr(int fd, int log_id, struct nvme_telemetry_log if (ret < 0) perror("get-telemetry-log"); else if (ret > 0) { - fprintf(stderr, "NVMe status: %s(%#x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); fprintf(stderr, "%s: ERROR : Failed to acquire telemetry header, ret = %d!\n", __func__, ret); } @@ -7769,7 +7779,7 @@ static int wdc_vs_drive_info(int argc, char **argv, } - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); nvme_free_tree(r); return ret; } @@ -7885,7 +7895,7 @@ static int wdc_vs_temperature_stats(int argc, char **argv, printf("%s: Invalid format\n", __func__); END: - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(ret), ret); + nvme_show_status(ret); nvme_free_tree(r); return ret; } @@ -8157,8 +8167,8 @@ static int wdc_enc_submit_move_data(int fd, char *cmd, int len, int xfer_size, F __func__, log_id); } else if (err != 0) { - fprintf(stderr, "%s: ERROR : WDC : NVMe Snd Mgmt Status:%s(x%x)\n", - __func__, nvme_status_to_string(err), err ); + fprintf(stderr, "%s: ERROR : WDC : NVMe Snd Mgmt\n", __func__); + nvme_show_status(err); } else { if (nvme_cmd.result == WDC_RESULT_NOT_AVAILABLE) { @@ -8182,8 +8192,8 @@ static int wdc_enc_submit_move_data(int fd, char *cmd, int len, int xfer_size, F err = nvme_submit_admin_passthru(fd, &nvme_cmd, NULL); if (err != 0) { more = 0; - fprintf(stderr, "%s: ERROR : WDC : NVMe Rcv Mgmt Status:%s(x%x)\n", - __func__, nvme_status_to_string(err), err); + fprintf(stderr, "%s: ERROR : WDC : NVMe Rcv Mgmt ", __func__); + nvme_show_status(err); } else { more = nvme_cmd.result & WDC_RESULT_MORE_DATA; response_size = nvme_cmd.result & ~WDC_RESULT_MORE_DATA; @@ -8238,7 +8248,7 @@ static int wdc_enc_get_nic_log(int fd, __u8 log_id, __u32 xfer_size, __u32 data_ #endif ret = nvme_submit_admin_passthru(fd, &admin_cmd, NULL); if (ret !=0 ) { - fprintf(stderr, "%s: ERROR : WDC : NVMe Status:%s(%x)\n",__func__, nvme_status_to_string(ret), ret); + nvme_show_status(ret); fprintf(stderr, "%s: ERROR : WDC : Get chunk %d, size = 0x%x, offset = 0x%x, addr = 0x%lx\n", __func__, i, admin_cmd.data_len, curr_data_offset, (long unsigned int)admin_cmd.addr); break; diff --git a/plugins/ymtc/ymtc-nvme.c b/plugins/ymtc/ymtc-nvme.c index 2958ee08..8aae45fe 100644 --- a/plugins/ymtc/ymtc-nvme.c +++ b/plugins/ymtc/ymtc-nvme.c @@ -7,6 +7,8 @@ #include "nvme.h" #include "libnvme.h" #include "plugin.h" +#include "linux/types.h" +#include "nvme-print.h" #define CREATE_CMD #include "ymtc-nvme.h" @@ -136,7 +138,7 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd, d_raw((unsigned char *)&smart_log, sizeof(smart_log)); } if (err > 0) - fprintf(stderr, "NVMe Status:%s(%x)\n", nvme_status_to_string(err), err); + nvme_show_status(err); return err; } -- 2.50.1