From: Minwoo Im Date: Sat, 13 Jan 2018 12:20:52 +0000 (+0900) Subject: nvme-cli: add support for options to effects-log subcommand X-Git-Tag: v1.6~122^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a1df29ae18d870b8c67b8ab19eecb5cd933d9772;p=users%2Fhch%2Fnvme-cli.git nvme-cli: add support for options to effects-log subcommand Add support for options below to to effects-log subcommand. --output-format=, -o normal|json|binary --human-readable, -H --raw-binary, -b Signed-off-by: Minwoo Im --- diff --git a/nvme-ioctl.c b/nvme-ioctl.c index c032d8b..5145d5e 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -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); diff --git a/nvme-ioctl.h b/nvme-ioctl.h index e562b25..bc6358c 100644 --- a/nvme-ioctl.h +++ b/nvme-ioctl.h @@ -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); diff --git a/nvme-print.c b/nvme-print.c index 80604d7..a414f03 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -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; diff --git a/nvme-print.h b/nvme-print.h index 5903716..2c94477 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -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 e8edcde..a6f0639 100644 --- 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);