You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
4.1 KiB
142 lines
4.1 KiB
7 years ago
|
From 11004aaa98865dd7c0ee28b4af8d6ba6b6f11507 Mon Sep 17 00:00:00 2001
|
||
|
From: Mauro Carvalho Chehab <mchehab@redhat.com>
|
||
|
Date: Fri, 31 May 2013 13:54:11 -0300
|
||
|
Subject: [PATCH 06/32] Add support to record AER events
|
||
|
|
||
|
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
|
||
|
---
|
||
|
ras-aer-handler.c | 4 ++-
|
||
|
ras-record.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
|
||
|
ras-record.h | 6 +++++
|
||
|
3 files changed, 68 insertions(+), 2 deletions(-)
|
||
|
|
||
|
diff --git a/ras-aer-handler.c b/ras-aer-handler.c
|
||
|
index ec63e2a..e5abaca 100644
|
||
|
--- a/ras-aer-handler.c
|
||
|
+++ b/ras-aer-handler.c
|
||
|
@@ -111,7 +111,9 @@ int ras_aer_event_handler(struct trace_seq *s,
|
||
|
trace_seq_puts(s, ev.error_type);
|
||
|
|
||
|
/* Insert data into the SGBD */
|
||
|
-// ras_store_aer_event(ras, &ev);
|
||
|
+#ifdef HAVE_SQLITE3
|
||
|
+ ras_store_aer_event(ras, &ev);
|
||
|
+#endif
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
diff --git a/ras-record.c b/ras-record.c
|
||
|
index 36b3373..cb302ce 100644
|
||
|
--- a/ras-record.c
|
||
|
+++ b/ras-record.c
|
||
|
@@ -26,6 +26,7 @@
|
||
|
#include <unistd.h>
|
||
|
#include "ras-events.h"
|
||
|
#include "ras-mc-handler.h"
|
||
|
+#include "ras-aer-handler.h"
|
||
|
#include "ras-logger.h"
|
||
|
|
||
|
/* #define DEBUG_SQL 1 */
|
||
|
@@ -109,6 +110,56 @@ int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev)
|
||
|
return rc;
|
||
|
}
|
||
|
|
||
|
+/*
|
||
|
+ * Table and functions to handle ras:aer
|
||
|
+ */
|
||
|
+
|
||
|
+#ifdef HAVE_AER
|
||
|
+static const struct db_fields aer_event_fields[] = {
|
||
|
+ { .name="id", .type="INTEGER PRIMARY KEY" },
|
||
|
+ { .name="timestamp", .type="TEXT" },
|
||
|
+ { .name="err_type", .type="TEXT" },
|
||
|
+ { .name="err_msg", .type="TEXT" },
|
||
|
+};
|
||
|
+
|
||
|
+static const struct db_table_descriptor aer_event_tab = {
|
||
|
+ .name = "aer_event",
|
||
|
+ .fields = aer_event_fields,
|
||
|
+ .num_fields = ARRAY_SIZE(aer_event_fields),
|
||
|
+};
|
||
|
+
|
||
|
+int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev)
|
||
|
+{
|
||
|
+ int rc;
|
||
|
+ struct sqlite3_priv *priv = ras->db_priv;
|
||
|
+
|
||
|
+ if (!priv || !priv->stmt_aer_event)
|
||
|
+ return 0;
|
||
|
+ log(TERM, LOG_INFO, "mc_event store: %p\n", priv->stmt_aer_event);
|
||
|
+
|
||
|
+ sqlite3_bind_text(priv->stmt_aer_event, 1, ev->timestamp, -1, NULL);
|
||
|
+ sqlite3_bind_text(priv->stmt_aer_event, 3, ev->error_type, -1, NULL);
|
||
|
+ sqlite3_bind_text(priv->stmt_aer_event, 4, ev->msg, -1, NULL);
|
||
|
+
|
||
|
+ rc = sqlite3_step(priv->stmt_aer_event);
|
||
|
+ if (rc != SQLITE_OK && rc != SQLITE_DONE)
|
||
|
+ log(TERM, LOG_ERR,
|
||
|
+ "Failed to do aer_event step on sqlite: error = %d\n", rc);
|
||
|
+ rc = sqlite3_reset(priv->stmt_aer_event);
|
||
|
+ if (rc != SQLITE_OK && rc != SQLITE_DONE)
|
||
|
+ log(TERM, LOG_ERR,
|
||
|
+ "Failed reset aer_event on sqlite: error = %d\n",
|
||
|
+ rc);
|
||
|
+ log(TERM, LOG_INFO, "register inserted at db\n");
|
||
|
+
|
||
|
+ return rc;
|
||
|
+}
|
||
|
+#endif
|
||
|
+
|
||
|
+/*
|
||
|
+ * Generic code
|
||
|
+ */
|
||
|
+
|
||
|
static int ras_mc_prepare_stmt(struct sqlite3_priv *priv,
|
||
|
sqlite3_stmt **stmt,
|
||
|
const struct db_table_descriptor *db_tab)
|
||
|
@@ -230,8 +281,15 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras)
|
||
|
|
||
|
rc = ras_mc_create_table(priv, &mc_event_tab);
|
||
|
if (rc == SQLITE_OK)
|
||
|
- rc = ras_mc_prepare_stmt(priv, &priv->stmt_mc_event, &mc_event_tab);
|
||
|
+ rc = ras_mc_prepare_stmt(priv, &priv->stmt_mc_event,
|
||
|
+ &mc_event_tab);
|
||
|
|
||
|
+#ifdef HAVE_AER
|
||
|
+ rc = ras_mc_create_table(priv, &aer_event_tab);
|
||
|
+ if (rc == SQLITE_OK)
|
||
|
+ rc = ras_mc_prepare_stmt(priv, &priv->stmt_aer_event,
|
||
|
+ &aer_event_tab);
|
||
|
+#endif
|
||
|
|
||
|
ras->db_priv = priv;
|
||
|
return 0;
|
||
|
diff --git a/ras-record.h b/ras-record.h
|
||
|
index 9791185..5008906 100644
|
||
|
--- a/ras-record.h
|
||
|
+++ b/ras-record.h
|
||
|
@@ -47,14 +47,20 @@ struct ras_aer_event {
|
||
|
struct sqlite3_priv {
|
||
|
sqlite3 *db;
|
||
|
sqlite3_stmt *stmt_mc_event;
|
||
|
+#ifdef HAVE_AER
|
||
|
+ sqlite3_stmt *stmt_aer_event;
|
||
|
+#endif
|
||
|
};
|
||
|
|
||
|
int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras);
|
||
|
int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev);
|
||
|
+int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev);
|
||
|
|
||
|
#else
|
||
|
static inline int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) { return 0; };
|
||
|
static inline int ras_store_mc_event(struct ras_events *ras, struct ras_mc_event *ev) { return 0; };
|
||
|
+static inline int ras_store_aer_event(struct ras_events *ras, struct ras_aer_event *ev) { return 0; };
|
||
|
+
|
||
|
#endif
|
||
|
|
||
|
#endif
|
||
|
--
|
||
|
1.7.1
|
||
|
|