krishnanadh / rpms / rasdaemon

Forked from rpms/rasdaemon a year ago
Clone

Blame SOURCES/0068-rasdaemon-add-support-for-non-standard-error-decoder.patch

ac32bf
From 873e88d6ba1ce5ec97f5cc0f4f0b45dfd2026b9f Mon Sep 17 00:00:00 2001
ac32bf
From: "shiju.jose@huawei.com" <shiju.jose@huawei.com>
ac32bf
Date: Wed, 4 Oct 2017 10:11:08 +0100
ac32bf
Subject: [PATCH] rasdaemon:add support for non-standard error decoder
ac32bf
ac32bf
This patch add support to decode the non-standard
ac32bf
error information.
ac32bf
ac32bf
Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
ac32bf
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
ac32bf
---
ac32bf
 ras-non-standard-handler.c | 62 +++++++++++++++++++++++++++++++++++++++++++++-
ac32bf
 ras-non-standard-handler.h | 10 ++++++++
ac32bf
 2 files changed, 71 insertions(+), 1 deletion(-)
ac32bf
ac32bf
diff --git a/ras-non-standard-handler.c b/ras-non-standard-handler.c
ac32bf
index 4c154e5..21e6a76 100644
ac32bf
--- a/ras-non-standard-handler.c
ac32bf
+++ b/ras-non-standard-handler.c
ac32bf
@@ -13,6 +13,7 @@
ac32bf
 
ac32bf
 #include <stdio.h>
ac32bf
 #include <stdlib.h>
ac32bf
+#include <stdbool.h>
ac32bf
 #include <string.h>
ac32bf
 #include <unistd.h>
ac32bf
 #include "libtrace/kbuffer.h"
ac32bf
@@ -21,6 +22,31 @@
ac32bf
 #include "ras-logger.h"
ac32bf
 #include "ras-report.h"
ac32bf
 
ac32bf
+static p_ns_dec_tab * ns_dec_tab;
ac32bf
+static size_t dec_tab_count;
ac32bf
+
ac32bf
+int register_ns_dec_tab(const p_ns_dec_tab tab)
ac32bf
+{
ac32bf
+	ns_dec_tab = (p_ns_dec_tab *)realloc(ns_dec_tab,
ac32bf
+					    (dec_tab_count + 1) * sizeof(tab));
ac32bf
+	if (ns_dec_tab == NULL) {
ac32bf
+		printf("%s p_ns_dec_tab malloc failed", __func__);
ac32bf
+		return -1;
ac32bf
+	}
ac32bf
+	ns_dec_tab[dec_tab_count] = tab;
ac32bf
+	dec_tab_count++;
ac32bf
+	return 0;
ac32bf
+}
ac32bf
+
ac32bf
+void unregister_ns_dec_tab(void)
ac32bf
+{
ac32bf
+	if (ns_dec_tab) {
ac32bf
+		free(ns_dec_tab);
ac32bf
+		ns_dec_tab = NULL;
ac32bf
+		dec_tab_count = 0;
ac32bf
+	}
ac32bf
+}
ac32bf
+
ac32bf
 void print_le_hex(struct trace_seq *s, const uint8_t *buf, int index) {
ac32bf
 	trace_seq_printf(s, "%02x%02x%02x%02x", buf[index+3], buf[index+2], buf[index+1], buf[index]);
ac32bf
 }
ac32bf
@@ -49,16 +75,32 @@ static char *uuid_le(const char *uu)
ac32bf
 	return uuid;
ac32bf
 }
ac32bf
 
ac32bf
+static int uuid_le_cmp(const char *sec_type, const char *uuid2)
ac32bf
+{
ac32bf
+	static char uuid1[32];
ac32bf
+	char *p = uuid1;
ac32bf
+	int i;
ac32bf
+	static const unsigned char le[16] = {
ac32bf
+			3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15};
ac32bf
+
ac32bf
+	for (i = 0; i < 16; i++)
ac32bf
+		p += sprintf(p, "%.2x", sec_type[le[i]]);
ac32bf
+	*p = 0;
ac32bf
+	return strncmp(uuid1, uuid2, 32);
ac32bf
+}
ac32bf
+
ac32bf
 int ras_non_standard_event_handler(struct trace_seq *s,
ac32bf
 			 struct pevent_record *record,
ac32bf
 			 struct event_format *event, void *context)
ac32bf
 {
ac32bf
-	int len, i, line_count;
ac32bf
+	int len, i, line_count, count;
ac32bf
 	unsigned long long val;
ac32bf
 	struct ras_events *ras = context;
ac32bf
 	time_t now;
ac32bf
 	struct tm *tm;
ac32bf
 	struct ras_non_standard_event ev;
ac32bf
+	p_ns_dec_tab dec_tab;
ac32bf
+	bool dec_done = false;
ac32bf
 
ac32bf
 	/*
ac32bf
 	 * Newer kernels (3.10-rc1 or upper) provide an uptime clock.
ac32bf
@@ -133,6 +175,18 @@ int ras_non_standard_event_handler(struct trace_seq *s,
ac32bf
 			trace_seq_printf(s, " ");
ac32bf
 	}
ac32bf
 
ac32bf
+	for (count = 0; count < dec_tab_count && !dec_done; count++) {
ac32bf
+		dec_tab = ns_dec_tab[count];
ac32bf
+		for (i = 0; i < dec_tab[0].len; i++) {
ac32bf
+			if (uuid_le_cmp(ev.sec_type,
ac32bf
+					dec_tab[i].sec_type) == 0) {
ac32bf
+				dec_tab[i].decode(s, ev.error);
ac32bf
+				dec_done = true;
ac32bf
+				break;
ac32bf
+			}
ac32bf
+		}
ac32bf
+	}
ac32bf
+
ac32bf
 	/* Insert data into the SGBD */
ac32bf
 #ifdef HAVE_SQLITE3
ac32bf
 	ras_store_non_standard_record(ras, &ev;;
ac32bf
@@ -145,3 +199,9 @@ int ras_non_standard_event_handler(struct trace_seq *s,
ac32bf
 
ac32bf
 	return 0;
ac32bf
 }
ac32bf
+
ac32bf
+__attribute__((destructor))
ac32bf
+static void ns_exit(void)
ac32bf
+{
ac32bf
+	unregister_ns_dec_tab();
ac32bf
+}
ac32bf
diff --git a/ras-non-standard-handler.h b/ras-non-standard-handler.h
ac32bf
index 2b5ac35..a183d1a 100644
ac32bf
--- a/ras-non-standard-handler.h
ac32bf
+++ b/ras-non-standard-handler.h
ac32bf
@@ -17,10 +17,20 @@
ac32bf
 #include "ras-events.h"
ac32bf
 #include "libtrace/event-parse.h"
ac32bf
 
ac32bf
+typedef struct ras_ns_dec_tab {
ac32bf
+	const char *sec_type;
ac32bf
+	int (*decode)(struct trace_seq *s, const void *err);
ac32bf
+	size_t len;
ac32bf
+} *p_ns_dec_tab;
ac32bf
+
ac32bf
 int ras_non_standard_event_handler(struct trace_seq *s,
ac32bf
 			 struct pevent_record *record,
ac32bf
 			 struct event_format *event, void *context);
ac32bf
 
ac32bf
 void print_le_hex(struct trace_seq *s, const uint8_t *buf, int index);
ac32bf
 
ac32bf
+int register_ns_dec_tab(const p_ns_dec_tab tab);
ac32bf
+
ac32bf
+void unregister_ns_dec_tab(void);
ac32bf
+
ac32bf
 #endif
ac32bf
-- 
ac32bf
1.8.3.1
ac32bf