]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
nvme-cli: add support for options to effects-log subcommand
authorMinwoo Im <minwoo.im.dev@gmail.com>
Sat, 13 Jan 2018 12:20:52 +0000 (21:20 +0900)
committerMinwoo Im <minwoo.im.dev@gmail.com>
Sat, 13 Jan 2018 12:20:52 +0000 (21:20 +0900)
Add support for options below to to effects-log subcommand.
    --output-format=<fmt>, -o <fmt>    normal|json|binary
    --human-readable, -H
    --raw-binary, -b

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
nvme-ioctl.c
nvme-ioctl.h
nvme-print.c
nvme-print.h
nvme.c

index c032d8b3eec0a0e95461a0b7344011374d67a5d5..5145d5e285653941015d77e0f988f5d94d8bb640 100644 (file)
@@ -413,6 +413,11 @@ int nvme_smart_log(int fd, __u32 nsid, struct nvme_smart_log *smart_log)
        return nvme_get_log(fd, nsid, NVME_LOG_SMART, sizeof(*smart_log), smart_log);
 }
 
+int nvme_effects_log(int fd, struct nvme_effects_log_page *effects_log)
+{
+       return nvme_get_log(fd, 0, NVME_LOG_CMD_EFFECTS, sizeof(*effects_log), effects_log);
+}
+
 int nvme_discovery_log(int fd, struct nvmf_disc_rsp_page_hdr *log, __u32 size)
 {
        return nvme_get_log(fd, 0, NVME_LOG_DISC, size, log);
index e562b25b69eaf70435f8db5b796eb325f9950307..bc6358ce055f3069157efe03e98aa6fa5aa19700 100644 (file)
@@ -83,6 +83,7 @@ int nvme_get_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data);
 int nvme_fw_log(int fd, struct nvme_firmware_log_page *fw_log);
 int nvme_error_log(int fd, int entries, struct nvme_error_log_page *err_log);
 int nvme_smart_log(int fd, __u32 nsid, struct nvme_smart_log *smart_log);
+int nvme_effects_log(int fd, struct nvme_effects_log_page *effects_log);
 int nvme_discovery_log(int fd, struct nvmf_disc_rsp_page_hdr *log, __u32 size);
 int nvme_sanitize_log(int fd, struct nvme_sanitize_log_page *sanitize_log);
 
index 80604d7b232d84a59f8ac0ab132f79373c716ccc..a414f035825b388c9026192bf791ae92581294a8 100644 (file)
@@ -1023,20 +1023,52 @@ void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname)
                                                fw_to_string(fw_log->frs[i]));
 }
 
-void show_effects_log(struct nvme_effects_log_page *effects)
+static void show_effects_log_human(__u32 effect)
+{
+       const char *set = "+";
+       const char *clr = "-";
+
+       printf("  CSUPP+");
+       printf("  LBCC%s", (effect & NVME_CMD_EFFECTS_LBCC) ? set : clr);
+       printf("  NCC%s", (effect & NVME_CMD_EFFECTS_NCC) ? set : clr);
+       printf("  NIC%s", (effect & NVME_CMD_EFFECTS_NIC) ? set : clr);
+       printf("  CCC%s", (effect & NVME_CMD_EFFECTS_CCC) ? set : clr);
+
+       if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 0)
+               printf("  No command restriction\n");
+       else if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 1)
+               printf("  No other command for same namespace\n");
+       else if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 2)
+               printf("  No other command for any namespace\n");
+       else
+               printf("  Reserved CSE\n");
+}
+
+void show_effects_log(struct nvme_effects_log_page *effects, unsigned int flags)
 {
        int i;
+       int human = flags & HUMAN;
        __u32 effect;
 
        for (i = 0; i < 256; i++) {
                effect = le32_to_cpu(effects->acs[i]);
-               if (effect & 1)
-                       printf("ACS%-4d: %08x\n", i, effects->acs[i]);
+               if (effect & NVME_CMD_EFFECTS_CSUPP) {
+                       printf("ACS%-4d: %08x", i, effect);
+                       if (human)
+                               show_effects_log_human(effect);
+                       else
+                               printf("\n");
+               }
        }
        for (i = 0; i < 256; i++) {
-               effect = le32_to_cpu(effects->acs[i]);
-               if (effect & 1)
-                       printf("IOCS%-3d: %08x\n", i, effects->iocs[i]);
+               effect = le32_to_cpu(effects->iocs[i]);
+               if (effect & NVME_CMD_EFFECTS_CSUPP) {
+                       printf("IOCS%-3d: %08x", i, effect);
+                       if (human)
+                               show_effects_log_human(effect);
+                       else
+                               printf("\n");
+               }
        }
 }
 
@@ -1970,6 +2002,32 @@ void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char
        json_free_object(root);
 }
 
+void json_effects_log(struct nvme_effects_log_page *effects_log, const char *devname)
+{
+       struct json_object *root;
+       unsigned int opcode;
+       char key[16];
+       __u32 effect;
+
+       root = json_create_object();
+
+       for (opcode = 0; opcode < 256; opcode++) {
+               sprintf(key, "ACS%-4d", opcode);
+               effect = le32_to_cpu(effects_log->acs[opcode]);
+               json_object_add_value_int(root, key, effect);
+       }
+
+       for (opcode = 0; opcode < 256; opcode++) {
+               sprintf(key, "IOCS%-3d", opcode);
+               effect = le32_to_cpu(effects_log->iocs[opcode]);
+               json_object_add_value_int(root, key, effect);
+       }
+
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
+}
+
 void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log, const char *devname)
 {
        struct json_object *root;
index 590371688723ee453d8c0fa99bd6c90d5ec1f754..2c94477cd8d033347cb096f6402f574ca556f075 100644 (file)
@@ -25,7 +25,7 @@ void show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges);
 void show_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname);
 void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
 void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
-void show_effects_log(struct nvme_effects_log_page *effects);
+void show_effects_log(struct nvme_effects_log_page *effects, unsigned int flags);
 void show_sanitize_log(struct nvme_sanitize_log_page *sanitize, unsigned int mode, const char *devname);
 void show_ctrl_registers(void *bar, unsigned int mode, bool fabrics);
 void show_nvme_id_ns_descs(void *data);
@@ -42,6 +42,7 @@ void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags);
 void json_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11);
 void json_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname);
 void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
+void json_effects_log(struct nvme_effects_log_page *effects_log, const char *devname);
 void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log, const char *devname);
 void json_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
 void json_print_list_items(struct list_item *items, unsigned amnt);
diff --git a/nvme.c b/nvme.c
index e8edcde98bbe2e0e058dfd4c65ed505aff2432bb..a6f0639ded1eac962bbdc3f09681ac9b0ee0a149 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -226,17 +226,28 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
 static int get_effects_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
        const char *desc = "Retrieve command effects log page and print the table.";
+       const char *raw_binary = "show infos in binary format";
+       const char *human_readable = "show infos in readable format";
        struct nvme_effects_log_page effects;
 
        int err, fd;
+       int fmt;
+       unsigned int flags = 0;
 
        struct config {
+               int   raw_binary;
+               int   human_readable;
+               char *output_format;
        };
 
        struct config cfg = {
+               .output_format = "normal",
        };
 
        const struct argconfig_commandline_options command_line_options[] = {
+               {"output-format", 'o', "FMT", CFG_STRING,   &cfg.output_format, required_argument, output_format},
+               {"human-readable",'H', "",    CFG_NONE,     &cfg.human_readable,no_argument,       human_readable},
+               {"raw-binary",    'b', "",    CFG_NONE,     &cfg.raw_binary,    no_argument,       raw_binary},
                {NULL}
        };
 
@@ -244,9 +255,24 @@ static int get_effects_log(int argc, char **argv, struct command *cmd, struct pl
        if (fd < 0)
                return fd;
 
-       err = nvme_get_log(fd, NVME_NSID_ALL, 5, 4096, &effects);
-       if (!err)
-               show_effects_log(&effects);
+       fmt = validate_output_format(cfg.output_format);
+       if (fmt < 0)
+               return fmt;
+       if (cfg.raw_binary)
+               fmt = BINARY;
+
+       if (cfg.human_readable)
+               flags |= HUMAN;
+
+       err = nvme_effects_log(fd, &effects);
+       if (!err) {
+               if (fmt == BINARY)
+                       d_raw((unsigned char *)&effects, sizeof(effects));
+               else if (fmt == JSON)
+                       json_effects_log(&effects, devicename);
+               else
+                       show_effects_log(&effects, flags);
+       }
        else if (err > 0)
                fprintf(stderr, "NVMe Status:%s(%x)\n",
                                nvme_status_to_string(err), err);