linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme-cli: improvment critical warning format
@ 2019-11-04 19:28 wenxiong
  2019-11-04 22:57 ` Keith Busch
  0 siblings, 1 reply; 4+ messages in thread
From: wenxiong @ 2019-11-04 19:28 UTC (permalink / raw)
  To: linux-nvme; +Cc: keith.busch, Wen Xiong, wenxiong

From: Wen Xiong <wenxiong@linux.vnet.ibm.com>

This patch improves the critical warning format with smart-log.

Signed-off-by: Wendy Xiong<wenxiong@linux.vnet.ibm.com>
---
 nvme-print.c |   28 +++++++++++++++++++++++++---
 nvme-print.h |    4 ++--
 nvme.c       |   11 +++++++++--
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/nvme-print.c b/nvme-print.c
index d3e3307..d64ae07 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -1722,15 +1722,26 @@ void show_endurance_log(struct nvme_endurance_group_log *endurance_group,
 		int128_to_double(endurance_group->num_err_info_log_entries));
 }
 
-void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname)
+void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag)
 {
 	/* convert temperature from Kelvin to Celsius */
 	int temperature = ((smart->temperature[1] << 8) |
 		smart->temperature[0]) - 273;
 	int i;
+	int human = flag & HUMAN;
 
 	printf("Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid);
-	printf("critical_warning			: %#x\n", smart->critical_warning);
+	printf("critical_warning                        : %#x\n", smart->critical_warning);
+
+	if (human) {
+		printf("      [0:0]:Available Spare             : %d\n", smart->critical_warning & 0x01);
+		printf("      [1:1]:Temp. Threshold             : %d\n", (smart->critical_warning & 0x02) >> 1);
+		printf("      [2:2]:NVM subsystem Reliability   : %d\n", (smart->critical_warning & 0x04) >> 2);
+		printf("      [3:3]:Read-only                   : %d\n", (smart->critical_warning & 0x08) >> 3);
+		printf("      [4:4]:Volatile mem. backup failed : %d\n", (smart->critical_warning & 0x10) >> 4);
+		printf("      [5:5]:Persistent Mem. RO          : %d\n", (smart->critical_warning & 0x20) >> 5);
+	}
+
 	printf("temperature				: %d C\n", temperature);
 	printf("available_spare				: %u%%\n", smart->avail_spare);
 	printf("available_spare_threshold		: %u%%\n", smart->spare_thresh);
@@ -3221,11 +3232,12 @@ void json_endurance_log(struct nvme_endurance_group_log *endurance_group,
 	json_free_object(root);
 }
 
-void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname)
+void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag)
 {
 	struct json_object *root;
 	int c;
 	char key[21];
+	int human = flag & HUMAN;
 
 	unsigned int temperature = ((smart->temperature[1] << 8) |
 		smart->temperature[0]);
@@ -3244,6 +3256,16 @@ void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char
 	root = json_create_object();
 
 	json_object_add_value_int(root, "critical_warning", smart->critical_warning);
+
+	if (human) {
+		json_object_add_value_int(root,"   [0:0]:Available Spare", smart->critical_warning & 0x01);
+		json_object_add_value_int(root,"   [1:1]:Temp. Threshold", (smart->critical_warning & 0x02) >> 1);
+		json_object_add_value_int(root,"   [2:2]:NVM subsystem Reliability", (smart->critical_warning & 0x04) >> 2);
+		json_object_add_value_int(root,"   [3:3]:Read-only", (smart->critical_warning & 0x08) >> 3);
+		json_object_add_value_int(root,"   [4:4]:Volatile mem. backup failed", (smart->critical_warning & 0x10) >> 4);
+		json_object_add_value_int(root,"   [5:5]:Persistent Mem. RO", (smart->critical_warning & 0x20) >> 5);
+	}
+
 	json_object_add_value_int(root, "temperature", temperature);
 	json_object_add_value_int(root, "avail_spare", smart->avail_spare);
 	json_object_add_value_int(root, "spare_thresh", smart->spare_thresh);
diff --git a/nvme-print.h b/nvme-print.h
index dea8915..44d7ff6 100644
--- a/nvme-print.h
+++ b/nvme-print.h
@@ -24,7 +24,7 @@ void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags);
 void show_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11);
 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_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag);
 void show_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname);
 void show_self_test_log(struct nvme_self_test_log *self_test, const char *devname);
 void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
@@ -57,7 +57,7 @@ void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vend
 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_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag);
 void json_ana_log(struct nvme_ana_rsp_hdr *ana_log, 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);
diff --git a/nvme.c b/nvme.c
index 0823267..c511f9d 100644
--- a/nvme.c
+++ b/nvme.c
@@ -174,11 +174,14 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
 			"(default) or binary.";
 	const char *namespace = "(optional) desired namespace";
 	const char *raw = "output in binary format";
+	const char *human_readable = "show info in readable format";
 	int err, fmt, fd;
+	unsigned int flags = 0;
 
 	struct config {
 		__u32 namespace_id;
 		int   raw_binary;
+		int   human_readable;
 		char *output_format;
 	};
 
@@ -192,6 +195,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
 		OPT_UINT("namespace-id", 'n', &cfg.namespace_id,  namespace),
 		OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
 		OPT_FLAG("raw-binary",   'b', &cfg.raw_binary,    raw),
+		OPT_FLAG("human-readable", 'H', &cfg.human_readable,    human_readable),
 		OPT_END()
 	};
 
@@ -209,14 +213,17 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
 	if (cfg.raw_binary)
 		fmt = BINARY;
 
+	if (cfg.human_readable)
+		flags |= HUMAN;
+
 	err = nvme_smart_log(fd, cfg.namespace_id, &smart_log);
 	if (!err) {
 		if (fmt == BINARY)
 			d_raw((unsigned char *)&smart_log, sizeof(smart_log));
 		else if (fmt == JSON)
-			json_smart_log(&smart_log, cfg.namespace_id, devicename);
+			json_smart_log(&smart_log, cfg.namespace_id, devicename, flag);
 		else
-			show_smart_log(&smart_log, cfg.namespace_id, devicename);
+			show_smart_log(&smart_log, cfg.namespace_id, devicename, flag);
 	} else if (err > 0)
 		show_nvme_status(err);
 	else
-- 
1.6.0.2


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [PATCH] nvme-cli: improvment critical warning format
@ 2020-01-08 17:39 wenxiong
  2020-01-08 20:29 ` Keith Busch
  0 siblings, 1 reply; 4+ messages in thread
From: wenxiong @ 2020-01-08 17:39 UTC (permalink / raw)
  To: linux-nvme; +Cc: kbusch, Wen Xiong, wenxiong

From: Wen Xiong <wenxiong@linux.vnet.ibm.com>

This patch improves the critical warning format with smart-log.

Signed-off-by: Wendy Xiong<wenxiong@linux.vnet.ibm.com>
---
 nvme-print.c |   28 +++++++++++++++++++++++++---
 nvme-print.h |    4 ++--
 nvme.c       |   11 +++++++++--
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/nvme-print.c b/nvme-print.c
index d3e3307..d64ae07 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -1722,15 +1722,26 @@ void show_endurance_log(struct nvme_endurance_group_log *endurance_group,
 		int128_to_double(endurance_group->num_err_info_log_entries));
 }
 
-void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname)
+void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag)
 {
 	/* convert temperature from Kelvin to Celsius */
 	int temperature = ((smart->temperature[1] << 8) |
 		smart->temperature[0]) - 273;
 	int i;
+	int human = flag & HUMAN;
 
 	printf("Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid);
-	printf("critical_warning			: %#x\n", smart->critical_warning);
+	printf("critical_warning                        : %#x\n", smart->critical_warning);
+
+	if (human) {
+		printf("      Available Spare[0]             : %d\n", smart->critical_warning & 0x01);
+		printf("      Temp. Threshold[1]             : %d\n", (smart->critical_warning & 0x02) >> 1);
+		printf("      NVM subsystem Reliability[2]   : %d\n", (smart->critical_warning & 0x04) >> 2);
+		printf("      Read-only[3]                   : %d\n", (smart->critical_warning & 0x08) >> 3);
+		printf("      Volatile mem. backup failed[4] : %d\n", (smart->critical_warning & 0x10) >> 4);
+		printf("      Persistent Mem. RO[5]          : %d\n", (smart->critical_warning & 0x20) >> 5);
+	}
+
 	printf("temperature				: %d C\n", temperature);
 	printf("available_spare				: %u%%\n", smart->avail_spare);
 	printf("available_spare_threshold		: %u%%\n", smart->spare_thresh);
@@ -3221,11 +3232,12 @@ void json_endurance_log(struct nvme_endurance_group_log *endurance_group,
 	json_free_object(root);
 }
 
-void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname)
+void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag)
 {
 	struct json_object *root;
 	int c;
 	char key[21];
+	int human = flag & HUMAN;
 
 	unsigned int temperature = ((smart->temperature[1] << 8) |
 		smart->temperature[0]);
@@ -3244,6 +3256,16 @@ void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char
 	root = json_create_object();
 
 	json_object_add_value_int(root, "critical_warning", smart->critical_warning);
+
+	if (human) {
+		json_object_add_value_int(root,"   Available Spare[0]", smart->critical_warning & 0x01);
+		json_object_add_value_int(root,"   Temp. Threshold[1]", (smart->critical_warning & 0x02) >> 1);
+		json_object_add_value_int(root,"   NVM subsystem Reliability[2]", (smart->critical_warning & 0x04) >> 2);
+		json_object_add_value_int(root,"   Read-only[3]", (smart->critical_warning & 0x08) >> 3);
+		json_object_add_value_int(root,"   Volatile mem. backup failed[4]", (smart->critical_warning & 0x10) >> 4);
+		json_object_add_value_int(root,"   Persistent Mem. RO[5]", (smart->critical_warning & 0x20) >> 5);
+	}
+
 	json_object_add_value_int(root, "temperature", temperature);
 	json_object_add_value_int(root, "avail_spare", smart->avail_spare);
 	json_object_add_value_int(root, "spare_thresh", smart->spare_thresh);
diff --git a/nvme-print.h b/nvme-print.h
index dea8915..44d7ff6 100644
--- a/nvme-print.h
+++ b/nvme-print.h
@@ -24,7 +24,7 @@ void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags);
 void show_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11);
 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_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag);
 void show_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname);
 void show_self_test_log(struct nvme_self_test_log *self_test, const char *devname);
 void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
@@ -57,7 +57,7 @@ void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vend
 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_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname, unsigned int flag);
 void json_ana_log(struct nvme_ana_rsp_hdr *ana_log, 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);
diff --git a/nvme.c b/nvme.c
index 0823267..c511f9d 100644
--- a/nvme.c
+++ b/nvme.c
@@ -174,11 +174,14 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
 			"(default) or binary.";
 	const char *namespace = "(optional) desired namespace";
 	const char *raw = "output in binary format";
+	const char *human_readable = "show info in readable format";
 	int err, fmt, fd;
+	unsigned int flags = 0;
 
 	struct config {
 		__u32 namespace_id;
 		int   raw_binary;
+		int   human_readable;
 		char *output_format;
 	};
 
@@ -192,6 +195,7 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
 		OPT_UINT("namespace-id", 'n', &cfg.namespace_id,  namespace),
 		OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
 		OPT_FLAG("raw-binary",   'b', &cfg.raw_binary,    raw),
+		OPT_FLAG("human-readable", 'H', &cfg.human_readable,    human_readable),
 		OPT_END()
 	};
 
@@ -209,14 +213,17 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
 	if (cfg.raw_binary)
 		fmt = BINARY;
 
+	if (cfg.human_readable)
+		flags |= HUMAN;
+
 	err = nvme_smart_log(fd, cfg.namespace_id, &smart_log);
 	if (!err) {
 		if (fmt == BINARY)
 			d_raw((unsigned char *)&smart_log, sizeof(smart_log));
 		else if (fmt == JSON)
-			json_smart_log(&smart_log, cfg.namespace_id, devicename);
+			json_smart_log(&smart_log, cfg.namespace_id, devicename, flag);
 		else
-			show_smart_log(&smart_log, cfg.namespace_id, devicename);
+			show_smart_log(&smart_log, cfg.namespace_id, devicename, flag);
 	} else if (err > 0)
 		show_nvme_status(err);
 	else
-- 
1.6.0.2


_______________________________________________
linux-nvme mailing list
linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-01-08 20:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04 19:28 [PATCH] nvme-cli: improvment critical warning format wenxiong
2019-11-04 22:57 ` Keith Busch
2020-01-08 17:39 wenxiong
2020-01-08 20:29 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).