From c3427b24e2942f78092a3dabf60358858cc8e213 Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Thu, 29 Oct 2020 18:59:48 +0100 Subject: [PATCH] nvme-print: Adding enum nvme_feat MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch switch the feature_id into an named enum called nvme_feat. Having named enum ease the implementation as Werror=switch compile flag will detect forgotten case statements. A build failure looks like : nvme-print.c:4525:2: error: enumeration value ‘NVME_FEAT_RRL’ not handled in switch [-Werror=switch] This patch adds the NVME_FEAT_SANITIZE & NVME_FEAT_RRL inside nvme_feature_show_fields(). A NVME_FEAT_NONE=0 value is added to give a neutral/default value when needed. Signed-off-by: Erwan Velu --- linux/nvme.h | 40 +++++++++++++++++++--------------- nvme-print.c | 17 ++++++++++++--- nvme-print.h | 4 ++-- plugins/shannon/shannon-nvme.c | 4 ++-- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/linux/nvme.h b/linux/nvme.h index de250292..08fd6b90 100644 --- a/linux/nvme.h +++ b/linux/nvme.h @@ -1026,6 +1026,27 @@ enum { NVME_SQ_PRIO_HIGH = (1 << 1), NVME_SQ_PRIO_MEDIUM = (2 << 1), NVME_SQ_PRIO_LOW = (3 << 1), + NVME_LOG_ERROR = 0x01, + NVME_LOG_SMART = 0x02, + NVME_LOG_FW_SLOT = 0x03, + NVME_LOG_CHANGED_NS = 0x04, + NVME_LOG_CMD_EFFECTS = 0x05, + NVME_LOG_DEVICE_SELF_TEST = 0x06, + NVME_LOG_TELEMETRY_HOST = 0x07, + NVME_LOG_TELEMETRY_CTRL = 0x08, + NVME_LOG_ENDURANCE_GROUP = 0x09, + NVME_LOG_ANA = 0x0c, + NVME_LOG_DISC = 0x70, + NVME_LOG_RESERVATION = 0x80, + NVME_LOG_SANITIZE = 0x81, + NVME_LOG_ZONE_CHANGED_LIST = 0xbf, + NVME_FWACT_REPL = (0 << 3), + NVME_FWACT_REPL_ACTV = (1 << 3), + NVME_FWACT_ACTV = (2 << 3), +}; + +enum nvme_feat { + NVME_FEAT_NONE = 0x0, NVME_FEAT_ARBITRATION = 0x01, NVME_FEAT_POWER_MGMT = 0x02, NVME_FEAT_LBA_RANGE = 0x03, @@ -1054,24 +1075,7 @@ enum { NVME_FEAT_RESV_MASK = 0x82, NVME_FEAT_RESV_PERSIST = 0x83, NVME_FEAT_WRITE_PROTECT = 0x84, - NVME_LOG_ERROR = 0x01, - NVME_LOG_SMART = 0x02, - NVME_LOG_FW_SLOT = 0x03, - NVME_LOG_CHANGED_NS = 0x04, - NVME_LOG_CMD_EFFECTS = 0x05, - NVME_LOG_DEVICE_SELF_TEST = 0x06, - NVME_LOG_TELEMETRY_HOST = 0x07, - NVME_LOG_TELEMETRY_CTRL = 0x08, - NVME_LOG_ENDURANCE_GROUP = 0x09, - NVME_LOG_ANA = 0x0c, - NVME_LOG_DISC = 0x70, - NVME_LOG_RESERVATION = 0x80, - NVME_LOG_SANITIZE = 0x81, - NVME_LOG_ZONE_CHANGED_LIST = 0xbf, - NVME_FWACT_REPL = (0 << 3), - NVME_FWACT_REPL_ACTV = (1 << 3), - NVME_FWACT_ACTV = (2 << 3), -}; +} __attribute__ ((__packed__)); enum { NVME_NO_LOG_LSP = 0x0, diff --git a/nvme-print.c b/nvme-print.c index 2e3646f0..55299358 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -4003,9 +4003,10 @@ void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize, le32_to_cpu(sanitize->est_crypto_erase_time_with_no_deallocate)); } -const char *nvme_feature_to_string(int feature) +const char *nvme_feature_to_string(enum nvme_feat feature) { switch (feature) { + case NVME_FEAT_NONE: return "None"; case NVME_FEAT_ARBITRATION: return "Arbitration"; case NVME_FEAT_POWER_MGMT: return "Power Management"; case NVME_FEAT_LBA_RANGE: return "LBA Range Type"; @@ -4034,8 +4035,13 @@ const char *nvme_feature_to_string(int feature) case NVME_FEAT_HCTM: return "Host Controlled Thermal Management"; case NVME_FEAT_HOST_BEHAVIOR: return "Host Behavior"; case NVME_FEAT_SANITIZE: return "Sanitize"; - default: return "Unknown"; } + /* + * We don't use the "default:" statement to let the compiler warning if + * some values of the enum nvme_feat are missing in the switch(). + * The following return is acting as the default: statement. + */ + return "Unknown"; } const char *nvme_register_to_string(int reg) @@ -4517,7 +4523,7 @@ static void nvme_show_plm_config(struct nvme_plm_config *plmcfg) printf("\tDTWIN Time Threshold :%"PRIu64"\n", le64_to_cpu(plmcfg->dtwin_time_thresh)); } -void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf) +void nvme_feature_show_fields(enum nvme_feat fid, unsigned int result, unsigned char *buf) { __u8 field; uint64_t ull; @@ -4637,6 +4643,11 @@ void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf case NVME_FEAT_HOST_BEHAVIOR: printf("\tHost Behavior Support: %s\n", (buf[0] & 0x1) ? "True" : "False"); break; + case NVME_FEAT_NONE: + case NVME_FEAT_SANITIZE: + case NVME_FEAT_RRL: + printf("\t%s: to be implemented\n", nvme_feature_to_string(fid)); + break; } } diff --git a/nvme-print.h b/nvme-print.h index 6c3a45b1..a1d1ad42 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -55,7 +55,7 @@ void nvme_show_id_uuid_list(const struct nvme_id_uuid_list *uuid_list, enum nvme_print_flags flags); void nvme_show_id_iocs(struct nvme_id_iocs *iocs); -void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf); +void nvme_feature_show_fields(enum nvme_feat fid, unsigned int result, unsigned char *buf); void nvme_directive_show(__u8 type, __u8 oper, __u16 spec, __u32 nsid, __u32 result, void *buf, __u32 len, enum nvme_print_flags flags); void nvme_show_select_result(__u32 result); @@ -70,7 +70,7 @@ void nvme_show_zns_report_zones(void *report, __u32 descs, const char *nvme_status_to_string(__u32 status); const char *nvme_select_to_string(int sel); -const char *nvme_feature_to_string(int feature); +const char *nvme_feature_to_string(enum nvme_feat feature); const char *nvme_register_to_string(int reg); #endif diff --git a/plugins/shannon/shannon-nvme.c b/plugins/shannon/shannon-nvme.c index 3aa6f8a4..a1fa9ecc 100644 --- a/plugins/shannon/shannon-nvme.c +++ b/plugins/shannon/shannon-nvme.c @@ -182,7 +182,7 @@ static int get_additional_feature(int argc, char **argv, struct command *cmd, st struct config { __u32 namespace_id; - __u32 feature_id; + enum nvme_feat feature_id; __u8 sel; __u32 cdw11; __u32 data_len; @@ -192,7 +192,7 @@ static int get_additional_feature(int argc, char **argv, struct command *cmd, st struct config cfg = { .namespace_id = 1, - .feature_id = 0, + .feature_id = NVME_FEAT_NONE, .sel = 0, .cdw11 = 0, .data_len = 0, -- 2.50.1