]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: Adding enum nvme_feat
authorErwan Velu <e.velu@criteo.com>
Thu, 29 Oct 2020 17:59:48 +0000 (18:59 +0100)
committerKeith Busch <kbusch@kernel.org>
Tue, 17 Nov 2020 21:45:12 +0000 (13:45 -0800)
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 <e.velu@criteo.com>
linux/nvme.h
nvme-print.c
nvme-print.h
plugins/shannon/shannon-nvme.c

index de2502929ebb67b06f92d6a46e69d446723536a4..08fd6b905f3ce0ad78e403e49da32696703d0df6 100644 (file)
@@ -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,
index 2e3646f0467cf19a85441b35d2d76c35bb9677ed..55299358aa9f49b02577fc7cf9521b7eff2bd438 100644 (file)
@@ -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;
        }
 }
 
index 6c3a45b179e9e95ebf8bd1a7ce06d1514206fae7..a1d1ad42cc0ab4a7a0c1d717cc1a60e7619f3487 100644 (file)
@@ -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
index 3aa6f8a4063d9f4ab670d0d801b0bb1254d33381..a1fa9eccea73342b9d32650fec89844a0003d851 100644 (file)
@@ -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,