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

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