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>
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);
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);
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");
+ }
}
}
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;
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);
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);
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}
};
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);