|
|
4e1cde |
commit 4bad11866a349b7ae5d10869474f7c0fee740845
|
|
|
4e1cde |
Author: Wen Xiong <wenxiong@linux.vnet.ibm.com>
|
|
|
4e1cde |
Date: Wed Jan 8 12:24:41 2020 -0800
|
|
|
4e1cde |
|
|
|
4e1cde |
Add additional smart log critical warn decoding
|
|
|
4e1cde |
|
|
|
4e1cde |
Provide a user option to request additional smart log page decoding,
|
|
|
4e1cde |
and print out detailed critical warning when requested.
|
|
|
4e1cde |
|
|
|
4e1cde |
Signed-off-by: Wendy Xiong<wenxiong@linux.vnet.ibm.com>
|
|
|
4e1cde |
[merge up, rename json keys]
|
|
|
4e1cde |
Signed-off-by: Keith Busch <kbusch@kernel.org>
|
|
|
4e1cde |
|
|
|
4e1cde |
diff --git a/nvme-print.c b/nvme-print.c
|
|
|
4e1cde |
index 2ba1de1..46d5228 100644
|
|
|
4e1cde |
--- a/nvme-print.c
|
|
|
4e1cde |
+++ b/nvme-print.c
|
|
|
4e1cde |
@@ -585,10 +585,11 @@ static void json_endurance_log(struct nvme_endurance_group_log *endurance_group,
|
|
|
4e1cde |
json_free_object(root);
|
|
|
4e1cde |
}
|
|
|
4e1cde |
|
|
|
4e1cde |
-static void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid)
|
|
|
4e1cde |
+static void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
|
|
|
4e1cde |
+ enum nvme_print_flags flags)
|
|
|
4e1cde |
{
|
|
|
4e1cde |
+ int c, human = flags & VERBOSE;
|
|
|
4e1cde |
struct json_object *root;
|
|
|
4e1cde |
- int c;
|
|
|
4e1cde |
char key[21];
|
|
|
4e1cde |
|
|
|
4e1cde |
unsigned int temperature = ((smart->temperature[1] << 8) |
|
|
|
4e1cde |
@@ -607,8 +608,22 @@ static void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid)
|
|
|
4e1cde |
|
|
|
4e1cde |
root = json_create_object();
|
|
|
4e1cde |
|
|
|
4e1cde |
- json_object_add_value_int(root, "critical_warning",
|
|
|
4e1cde |
- smart->critical_warning);
|
|
|
4e1cde |
+ if (human) {
|
|
|
4e1cde |
+ struct json_object *crt = json_create_object();
|
|
|
4e1cde |
+
|
|
|
4e1cde |
+ json_object_add_value_int(crt, "value", smart->critical_warning);
|
|
|
4e1cde |
+ json_object_add_value_int(crt, "available_spare", smart->critical_warning & 0x01);
|
|
|
4e1cde |
+ json_object_add_value_int(crt, "temp_threshold", (smart->critical_warning & 0x02) >> 1);
|
|
|
4e1cde |
+ json_object_add_value_int(crt, "reliability_degraded", (smart->critical_warning & 0x04) >> 2);
|
|
|
4e1cde |
+ json_object_add_value_int(crt, "ro", (smart->critical_warning & 0x08) >> 3);
|
|
|
4e1cde |
+ json_object_add_value_int(crt, "vmbu_failed", (smart->critical_warning & 0x10) >> 4);
|
|
|
4e1cde |
+ json_object_add_value_int(crt, "pmr_ro", (smart->critical_warning & 0x20) >> 5);
|
|
|
4e1cde |
+
|
|
|
4e1cde |
+ json_object_add_value_object(root, "critical_warning", crt);
|
|
|
4e1cde |
+ } else
|
|
|
4e1cde |
+ json_object_add_value_int(root, "critical_warning",
|
|
|
4e1cde |
+ smart->critical_warning);
|
|
|
4e1cde |
+
|
|
|
4e1cde |
json_object_add_value_int(root, "temperature", temperature);
|
|
|
4e1cde |
json_object_add_value_int(root, "avail_spare", smart->avail_spare);
|
|
|
4e1cde |
json_object_add_value_int(root, "spare_thresh", smart->spare_thresh);
|
|
|
4e1cde |
@@ -3400,16 +3415,26 @@ void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
|
|
|
4e1cde |
/* convert temperature from Kelvin to Celsius */
|
|
|
4e1cde |
int temperature = ((smart->temperature[1] << 8) |
|
|
|
4e1cde |
smart->temperature[0]) - 273;
|
|
|
4e1cde |
- int i;
|
|
|
4e1cde |
+ int i, human = flags & VERBOSE;
|
|
|
4e1cde |
|
|
|
4e1cde |
if (flags & BINARY)
|
|
|
4e1cde |
return d_raw((unsigned char *)smart, sizeof(*smart));
|
|
|
4e1cde |
else if (flags & JSON)
|
|
|
4e1cde |
- return json_smart_log(smart, nsid);
|
|
|
4e1cde |
+ return json_smart_log(smart, nsid, flags);
|
|
|
4e1cde |
|
|
|
4e1cde |
printf("Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid);
|
|
|
4e1cde |
printf("critical_warning : %#x\n",
|
|
|
4e1cde |
smart->critical_warning);
|
|
|
4e1cde |
+
|
|
|
4e1cde |
+ if (human) {
|
|
|
4e1cde |
+ printf(" Available Spare[0] : %d\n", smart->critical_warning & 0x01);
|
|
|
4e1cde |
+ printf(" Temp. Threshold[1] : %d\n", (smart->critical_warning & 0x02) >> 1);
|
|
|
4e1cde |
+ printf(" NVM subsystem Reliability[2] : %d\n", (smart->critical_warning & 0x04) >> 2);
|
|
|
4e1cde |
+ printf(" Read-only[3] : %d\n", (smart->critical_warning & 0x08) >> 3);
|
|
|
4e1cde |
+ printf(" Volatile mem. backup failed[4] : %d\n", (smart->critical_warning & 0x10) >> 4);
|
|
|
4e1cde |
+ printf(" Persistent Mem. RO[5] : %d\n", (smart->critical_warning & 0x20) >> 5);
|
|
|
4e1cde |
+ }
|
|
|
4e1cde |
+
|
|
|
4e1cde |
printf("temperature : %d C\n",
|
|
|
4e1cde |
temperature);
|
|
|
4e1cde |
printf("available_spare : %u%%\n",
|
|
|
4e1cde |
diff --git a/nvme.c b/nvme.c
|
|
|
4e1cde |
index 3b386bc..dd3ab58 100644
|
|
|
4e1cde |
--- a/nvme.c
|
|
|
4e1cde |
+++ b/nvme.c
|
|
|
4e1cde |
@@ -218,6 +218,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
|
|
|
4e1cde |
"(default) or binary.";
|
|
|
4e1cde |
const char *namespace = "(optional) desired namespace";
|
|
|
4e1cde |
const char *raw = "output in binary format";
|
|
|
4e1cde |
+ const char *human_readable = "show info in readable format";
|
|
|
4e1cde |
enum nvme_print_flags flags;
|
|
|
4e1cde |
int err, fd;
|
|
|
4e1cde |
|
|
|
4e1cde |
@@ -225,6 +226,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
|
|
|
4e1cde |
__u32 namespace_id;
|
|
|
4e1cde |
int raw_binary;
|
|
|
4e1cde |
char *output_format;
|
|
|
4e1cde |
+ int human_readable;
|
|
|
4e1cde |
};
|
|
|
4e1cde |
|
|
|
4e1cde |
struct config cfg = {
|
|
|
4e1cde |
@@ -234,9 +236,10 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
|
|
|
4e1cde |
|
|
|
4e1cde |
|
|
|
4e1cde |
OPT_ARGS(opts) = {
|
|
|
4e1cde |
- OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace),
|
|
|
4e1cde |
- OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
|
|
|
4e1cde |
- OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
|
|
|
4e1cde |
+ OPT_UINT("namespace-id", 'n', &cfg.namespace_id, namespace),
|
|
|
4e1cde |
+ OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
|
|
|
4e1cde |
+ OPT_FLAG("raw-binary", 'b', &cfg.raw_binary, raw),
|
|
|
4e1cde |
+ OPT_FLAG("human-readable", 'H', &cfg.human_readable, human_readable),
|
|
|
4e1cde |
OPT_END()
|
|
|
4e1cde |
};
|
|
|
4e1cde |
|
|
|
4e1cde |
@@ -249,6 +252,8 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
|
|
|
4e1cde |
goto close_fd;
|
|
|
4e1cde |
if (cfg.raw_binary)
|
|
|
4e1cde |
flags = BINARY;
|
|
|
4e1cde |
+ if (cfg.human_readable)
|
|
|
4e1cde |
+ flags |= VERBOSE;
|
|
|
4e1cde |
|
|
|
4e1cde |
err = nvme_smart_log(fd, cfg.namespace_id, &smart_log);
|
|
|
4e1cde |
if (!err)
|