Blame SOURCES/0006-Add-support-to-record-AER-events.patch

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