[PATCH V2 1/3] nvme-cli: Add event type as filter in persistent event

wenxiong at linux.vnet.ibm.com wenxiong at linux.vnet.ibm.com
Tue May 4 14:33:45 BST 2021


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

Add -t option in persistent event log command. The customers can use
 -t to filter specific events in pel.

For example, only list hardware error(0x5).

./nvme persistent-event-log -a 0x0 -t 0x5 /dev/nvme0

Signed-off-by: Wen Xiong <wenxiong at linux.vnet.ibm.com>
---
 nvme-print.c | 21 ++++++++++++++++++---
 nvme-print.h |  4 ++--
 nvme.c       |  6 +++++-
 3 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/nvme-print.c b/nvme-print.c
index b01a842..7b43fff 100755
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -1031,7 +1031,7 @@ static const char *nvme_show_nss_hw_error(__u16 error_code)
 	}
 }
 
-void json_persistent_event_log(void *pevent_log_info, __u32 size)
+void json_persistent_event_log(__u32 event_type, void *pevent_log_info, __u32 size)
 {
 	struct json_object *root;
 	struct json_object *valid_attrs;
@@ -1115,6 +1115,14 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
 		if ((offset + pevent_entry_head->ehl + 3 +
 			le16_to_cpu(pevent_entry_head->el)) >= size)
 			break;
+
+		if ((event_type != 0) &
+				(pevent_entry_head->etype != event_type)) {
+			offset += pevent_entry_head->ehl + 3;
+			offset += le16_to_cpu(pevent_entry_head->el);
+			continue;
+		}
+
 		valid_attrs = json_create_object();
 
 		json_object_add_value_uint(valid_attrs, "event_type",
@@ -1343,7 +1351,7 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
 	json_free_object(root);
 }
 
-void nvme_show_persistent_event_log(void *pevent_log_info,
+void nvme_show_persistent_event_log(__u32 event_type, void *pevent_log_info,
 	__u8 action, __u32 size, const char *devname,
 	enum nvme_print_flags flags)
 {
@@ -1366,7 +1374,7 @@ void nvme_show_persistent_event_log(void *pevent_log_info,
 	if (flags & BINARY)
 		return d_raw((unsigned char *)pevent_log_info, size);
 	if (flags & JSON)
-		return json_persistent_event_log(pevent_log_info, size);
+		return json_persistent_event_log(event_type, pevent_log_info, size);
 
 	offset = sizeof(*pevent_log_head);
 
@@ -1423,6 +1431,13 @@ void nvme_show_persistent_event_log(void *pevent_log_info,
 			le16_to_cpu(pevent_entry_head->el)) >= size)
 			break;
 
+		if ((event_type != 0) &
+				(pevent_entry_head->etype != event_type)) {
+			offset += pevent_entry_head->ehl + 3;
+			offset += le16_to_cpu(pevent_entry_head->el);
+			continue;
+		}
+
 		printf("Event Type: %u\n", pevent_entry_head->etype);
 		printf("Event Type Revision: %u\n", pevent_entry_head->etype_rev);
 		printf("Event Header Length: %u\n", pevent_entry_head->ehl);
diff --git a/nvme-print.h b/nvme-print.h
index 2d8ed4d..ce4f0c9 100644
--- a/nvme-print.h
+++ b/nvme-print.h
@@ -49,8 +49,8 @@ void nvme_show_predictable_latency_event_agg_log(
 	struct nvme_event_agg_log_page *pea_log,
 	__u64 log_entries, __u32 size, const char *devname,
 	enum nvme_print_flags flags);
-void json_persistent_event_log(void *pevent_log_info, __u32 size);
-void nvme_show_persistent_event_log(void *pevent_log_info,
+void json_persistent_event_log(__u32 event_type, void *pevent_log_info, __u32 size);
+void nvme_show_persistent_event_log(__u32 event_type, void *pevent_log_info,
 	__u8 action, __u32 size, const char *devname,
 	enum nvme_print_flags flags);
 void json_endurance_group_event_agg_log(
diff --git a/nvme.c b/nvme.c
index a2075bf..0c8d669 100644
--- a/nvme.c
+++ b/nvme.c
@@ -911,6 +911,7 @@ static int get_persistent_event_log(int argc, char **argv,
 	const char *action = "action the controller shall take during"\
 			" processing this persistent log page command.";
 	const char *log_len = "number of bytes to retrieve";
+	const char *event_type = "event type";
 	const char *raw = "use binary output";
 	void *pevent_log_info;
 	struct nvme_persistent_event_log_head *pevent_log_head;
@@ -921,6 +922,7 @@ static int get_persistent_event_log(int argc, char **argv,
 	struct config {
 		__u8 action;
 		__u32 log_len;
+		__u32 event_type;
 		int raw_binary;
 		char *output_format;
 	};
@@ -928,12 +930,14 @@ static int get_persistent_event_log(int argc, char **argv,
 	struct config cfg = {
 		.action = 0xff,
 		.log_len = 0,
+		.event_type = 0,
 		.output_format = "normal",
 	};
 
 	OPT_ARGS(opts) = {
 		OPT_UINT("action",       'a', &cfg.action,        action),
 		OPT_UINT("log_len", 	 'l', &cfg.log_len,  	  log_len),
+		OPT_UINT("event-type",   't', &cfg.event_type,   event_type),
 		OPT_FMT("output-format", 'o', &cfg.output_format, output_format),
 		OPT_FLAG("raw-binary",   'b', &cfg.raw_binary,    raw),
 		OPT_END()
@@ -998,7 +1002,7 @@ static int get_persistent_event_log(int argc, char **argv,
 	err = nvme_persistent_event_log(fd, cfg.action,
 		cfg.log_len, pevent_log_info);
 	if (!err)
-		nvme_show_persistent_event_log(pevent_log_info, cfg.action,
+		nvme_show_persistent_event_log(cfg.event_type, pevent_log_info, cfg.action,
 			cfg.log_len, devicename, flags);
 	else if (err > 0)
 		nvme_show_status(err);
-- 
2.27.0




More information about the Linux-nvme mailing list