From: Scott Bauer Date: Tue, 20 Sep 2016 20:36:16 +0000 (-0600) Subject: JSONify SMART-add command, and rework json for fw-info-slots X-Git-Tag: v1.0~27^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4e89ebecb92c2446667b7b0dad321ecbb7b975dc;p=users%2Fsagi%2Fnvme-cli.git JSONify SMART-add command, and rework json for fw-info-slots Signed-off-by: Scott Bauer --- diff --git a/nvme-print.c b/nvme-print.c index 8296617a..0f1e8d71 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1401,29 +1401,79 @@ void json_nvme_resv_report(struct nvme_reservation_status *status) void json_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname) { struct json_object *root; - struct json_array *frs; + struct json_object *fwsi; + char fmt[21]; + char str[32]; int i; root = json_create_object(); + fwsi = json_create_object(); - json_object_add_value_int(root, "afi", fw_log->afi); - - frs = json_create_array(); - json_object_add_value_array(root, "frs", frs); + json_object_add_value_int(fwsi, "Active Firmware Slot (afi)", fw_log->afi); for (i = 0; i < 7; i++) { - struct json_object *fr = json_create_object(); - - json_object_add_value_int(fr, "frs", fw_log->frs[i]); - - json_array_add_value_object(frs, fr); - + snprintf(fmt, sizeof(fmt), "Firmware Rev Slot %d", i); + snprintf(str, sizeof(str), "%lu (%s)", (uint64_t)fw_log->frs[i], + fw_to_string(fw_log->frs[i])); + json_object_add_value_string(fwsi, fmt, str); } + json_object_add_value_object(root, devname, fwsi); json_print_object(root, NULL); printf("\n"); } +void json_add_smart_log(struct nvme_additional_smart_log *smart, + unsigned int nsid, const char *devname) +{ + struct json_object *root; + struct json_object *data; + char fmt[128]; + + root = json_create_object(); + data = json_create_object(); + + json_object_add_value_int(data, "Program Fail Count", + int48_to_long(smart->program_fail_cnt.raw)); + json_object_add_value_int(data, "Erase Fail Count", + int48_to_long(smart->erase_fail_cnt.raw)); + json_object_add_value_int(data, "Wear Leveling Min", + le16toh(smart->wear_leveling_cnt.wear_level.min)); + json_object_add_value_int(data, "Wear Leveling Max", + le16toh(smart->wear_leveling_cnt.wear_level.max)); + json_object_add_value_int(data, "Wear Leveling Avg", + le16toh(smart->wear_leveling_cnt.wear_level.avg)); + json_object_add_value_int(data, "End-to-end Error Detection Count", + int48_to_long(smart->e2e_err_cnt.raw)); + json_object_add_value_int(data, "CRC Error Count", + int48_to_long(smart->crc_err_cnt.raw)); + json_object_add_value_float(data, "Timed Workload Media Wear", + ((long double)int48_to_long(smart->timed_workload_media_wear.raw)) / 1024); + + json_object_add_value_int(data, "Timed Workload Host Reads", + int48_to_long(smart->timed_workload_host_reads.raw)); + json_object_add_value_int(data, "Timed Workload Timer", + int48_to_long(smart->timed_workload_timer.raw)); + snprintf(fmt, sizeof(fmt), "%u%%", + smart->thermal_throttle_status.thermal_throttle.pct); + json_object_add_value_string(data, "Thermal Throttle status Percentage", + fmt); + json_object_add_value_int(data, "Thermal Throttle Status Count", + smart->thermal_throttle_status.thermal_throttle.count); + json_object_add_value_int(data, "Retry Buffer Overflow Count", + int48_to_long(smart->retry_buffer_overflow_cnt.raw)); + json_object_add_value_int(data, "PLL Lock Loss Count", + int48_to_long(smart->pll_lock_loss_cnt.raw)); + json_object_add_value_int(data, "Nand Bytes Written", + int48_to_long(smart->nand_bytes_written.raw)); + json_object_add_value_int(data, "Host Bytes Written", + int48_to_long(smart->host_bytes_written.raw)); + + snprintf(fmt, sizeof(fmt), "Additional Smart Log for %s", devname); + json_object_add_value_object(root, fmt, data); + json_print_object(root, NULL); +} + void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname) { struct json_object *root; diff --git a/nvme-print.h b/nvme-print.h index 384ad61e..93131c70 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -35,6 +35,8 @@ void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags); void json_nvme_resv_report(struct nvme_reservation_status *status); 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_add_smart_log(struct nvme_additional_smart_log *smart, + unsigned int nsid, 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 1f6b4124..7cfe9706 100644 --- a/nvme.c +++ b/nvme.c @@ -213,7 +213,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct plugin *plugin) { struct nvme_additional_smart_log smart_log; - int err; + int err, fmt; char *desc = "Get Intel vendor specific additional smart log (optionally, "\ "for the specified namespace), and show it."; const char *namespace = "(optional) desired namespace"; @@ -221,26 +221,36 @@ static int get_additional_smart_log(int argc, char **argv, struct command *cmd, struct config { __u32 namespace_id; int raw_binary; + char *output_format; }; struct config cfg = { .namespace_id = 0xffffffff, + .output_format = "normal", }; const struct argconfig_commandline_options command_line_options[] = { {"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace}, {"raw-binary", 'b', "", CFG_NONE, &cfg.raw_binary, no_argument, raw}, + {"output-format", 'o', "FMT", CFG_STRING, &cfg.output_format, required_argument, output_format }, {NULL} }; parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg)); + fmt = validate_output_format(cfg.output_format); + if (fmt < 0) + return fmt; + if (cfg.raw_binary) + fmt = BINARY; err = nvme_intel_smart_log(fd, cfg.namespace_id, &smart_log); if (!err) { - if (!cfg.raw_binary) - show_intel_smart_log(&smart_log, cfg.namespace_id, devicename); - else + if (fmt == BINARY) d_raw((unsigned char *)&smart_log, sizeof(smart_log)); + if (fmt == JSON) + json_add_smart_log(&smart_log, cfg.namespace_id, devicename); + else + show_intel_smart_log(&smart_log, cfg.namespace_id, devicename); } else if (err > 0) fprintf(stderr, "NVMe Status:%s(%x)\n",