krishnanadh / rpms / rasdaemon

Forked from rpms/rasdaemon a year ago
Clone

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

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