]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
rasdaemon:add support for non-standard error decoder
authorshiju.jose@huawei.com <shiju.jose@huawei.com>
Wed, 4 Oct 2017 09:11:08 +0000 (10:11 +0100)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Sat, 14 Oct 2017 09:01:49 +0000 (06:01 -0300)
This patch add support to decode the non-standard
error information.

Signed-off-by: Shiju Jose <shiju.jose@huawei.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
ras-non-standard-handler.c
ras-non-standard-handler.h

index 4c154e5e7d59919eaa2f2ab04e6dbf15a494ae27..21e6a764f4d1aa57c3affb4fee3d233c522c99bf 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 #include "libtrace/kbuffer.h"
 #include "ras-logger.h"
 #include "ras-report.h"
 
+static p_ns_dec_tab * ns_dec_tab;
+static size_t dec_tab_count;
+
+int register_ns_dec_tab(const p_ns_dec_tab tab)
+{
+       ns_dec_tab = (p_ns_dec_tab *)realloc(ns_dec_tab,
+                                           (dec_tab_count + 1) * sizeof(tab));
+       if (ns_dec_tab == NULL) {
+               printf("%s p_ns_dec_tab malloc failed", __func__);
+               return -1;
+       }
+       ns_dec_tab[dec_tab_count] = tab;
+       dec_tab_count++;
+       return 0;
+}
+
+void unregister_ns_dec_tab(void)
+{
+       if (ns_dec_tab) {
+               free(ns_dec_tab);
+               ns_dec_tab = NULL;
+               dec_tab_count = 0;
+       }
+}
+
 void print_le_hex(struct trace_seq *s, const uint8_t *buf, int index) {
        trace_seq_printf(s, "%02x%02x%02x%02x", buf[index+3], buf[index+2], buf[index+1], buf[index]);
 }
@@ -49,16 +75,32 @@ static char *uuid_le(const char *uu)
        return uuid;
 }
 
+static int uuid_le_cmp(const char *sec_type, const char *uuid2)
+{
+       static char uuid1[32];
+       char *p = uuid1;
+       int i;
+       static const unsigned char le[16] = {
+                       3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15};
+
+       for (i = 0; i < 16; i++)
+               p += sprintf(p, "%.2x", sec_type[le[i]]);
+       *p = 0;
+       return strncmp(uuid1, uuid2, 32);
+}
+
 int ras_non_standard_event_handler(struct trace_seq *s,
                         struct pevent_record *record,
                         struct event_format *event, void *context)
 {
-       int len, i, line_count;
+       int len, i, line_count, count;
        unsigned long long val;
        struct ras_events *ras = context;
        time_t now;
        struct tm *tm;
        struct ras_non_standard_event ev;
+       p_ns_dec_tab dec_tab;
+       bool dec_done = false;
 
        /*
         * Newer kernels (3.10-rc1 or upper) provide an uptime clock.
@@ -133,6 +175,18 @@ int ras_non_standard_event_handler(struct trace_seq *s,
                        trace_seq_printf(s, " ");
        }
 
+       for (count = 0; count < dec_tab_count && !dec_done; count++) {
+               dec_tab = ns_dec_tab[count];
+               for (i = 0; i < dec_tab[0].len; i++) {
+                       if (uuid_le_cmp(ev.sec_type,
+                                       dec_tab[i].sec_type) == 0) {
+                               dec_tab[i].decode(s, ev.error);
+                               dec_done = true;
+                               break;
+                       }
+               }
+       }
+
        /* Insert data into the SGBD */
 #ifdef HAVE_SQLITE3
        ras_store_non_standard_record(ras, &ev);
@@ -145,3 +199,9 @@ int ras_non_standard_event_handler(struct trace_seq *s,
 
        return 0;
 }
+
+__attribute__((destructor))
+static void ns_exit(void)
+{
+       unregister_ns_dec_tab();
+}
index 2b5ac359ee75f660033d92a00d63967f72b5eb1e..a183d1a334cf65bece442ce4fd43d80f5fc48a73 100644 (file)
 #include "ras-events.h"
 #include "libtrace/event-parse.h"
 
+typedef struct ras_ns_dec_tab {
+       const char *sec_type;
+       int (*decode)(struct trace_seq *s, const void *err);
+       size_t len;
+} *p_ns_dec_tab;
+
 int ras_non_standard_event_handler(struct trace_seq *s,
                         struct pevent_record *record,
                         struct event_format *event, void *context);
 
 void print_le_hex(struct trace_seq *s, const uint8_t *buf, int index);
 
+int register_ns_dec_tab(const p_ns_dec_tab tab);
+
+void unregister_ns_dec_tab(void);
+
 #endif