mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] pstore: Only capture log messages
@ 2019-07-09  9:11 Sascha Hauer
  2019-07-09  9:11 ` [PATCH 2/2] pstore: remove unused code Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2019-07-09  9:11 UTC (permalink / raw)
  To: Barebox List

With this pstore only captures barebox log messages printed with pr_*
and dev_*, but no longer anything printed with printf and friends.

When capturing the barebox output with pstore only the log messages are
of interest, but not the ones printed with printf and certainly not
the things typed interactively on the command line. These are logged
currently because we register pstore as a barebox console. Instead, hook
into pr_puts which only outputs the barebox log messages.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console_common.c |  4 ++
 fs/pstore/platform.c    | 85 ++++++++++++-----------------------------
 include/linux/pstore.h  |  4 ++
 3 files changed, 33 insertions(+), 60 deletions(-)

diff --git a/common/console_common.c b/common/console_common.c
index a4d2636753..6916f651e5 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -29,6 +29,7 @@
 #include <password.h>
 #include <clock.h>
 #include <malloc.h>
+#include <linux/pstore.h>
 #include <asm-generic/div64.h>
 
 #ifndef CONFIG_CONSOLE_NONE
@@ -116,7 +117,10 @@ static void pr_puts(int level, const char *str)
 			barebox_logbuf_num_messages++;
 		}
 	}
+
+	pstore_log(str);
 nolog:
+
 	if (level > barebox_loglevel)
 		return;
 
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index 755363c309..aafa5559dc 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -44,76 +44,40 @@ void pstore_set_kmsg_bytes(int bytes)
 	kmsg_bytes = bytes;
 }
 
-#ifdef CONFIG_FS_PSTORE_CONSOLE
-static void pstore_console_write(const char *s, unsigned c)
-{
-	const char *e = s + c;
-
-	while (s < e) {
-		struct pstore_record record = {
-			.type = PSTORE_TYPE_CONSOLE,
-			.psi = psinfo,
-		};
-
-		if (c > psinfo->bufsize)
-			c = psinfo->bufsize;
-
-		record.buf = (char *)s;
-		record.size = c;
-		psinfo->write_buf(PSTORE_TYPE_CONSOLE, 0, &record.id, 0,
-				  record.buf, 0, record.size, psinfo);
-		s += c;
-		c = e - s;
-	}
-}
-
-static int pstore_console_puts(struct console_device *cdev, const char *s)
-{
-	pstore_console_write(s, strlen(s));
-	return strlen(s);
-}
+static int pstore_ready;
 
-static void pstore_console_putc(struct console_device *cdev, char c)
-{
-	const char s[1] = { c };
-
-	pstore_console_write(s, 1);
-}
-
-static void pstore_console_capture_log(void)
+void pstore_log(const char *str)
 {
-	struct log_entry *log;
+	uint64_t id;
+	static int in_pstore;
 
-	list_for_each_entry(log, &barebox_logbuf, list)
-		pstore_console_write(log->msg, strlen(log->msg));
-}
+	if (!IS_ENABLED(CONFIG_FS_PSTORE_CONSOLE))
+		return;
 
-static struct console_device *pstore_cdev;
+	if (!pstore_ready)
+		return;
 
-static void pstore_register_console(void)
-{
-	struct console_device *cdev;
-	int ret;
+	if (in_pstore)
+		return;
 
-	cdev = xzalloc(sizeof(struct console_device));
-	pstore_cdev = cdev;
+	in_pstore = 1;
 
-	cdev->puts = pstore_console_puts;
-	cdev->putc = pstore_console_putc;
-	cdev->devname = "pstore";
-	cdev->devid = DEVICE_ID_SINGLE;
+	psinfo->write_buf(PSTORE_TYPE_CONSOLE, 0, &id, 0,
+			  str, 0, strlen(str), psinfo);
 
-        ret = console_register(cdev);
-        if (ret)
-                pr_err("registering failed with %s\n", strerror(-ret));
+	in_pstore = 0;
+}
 
-	pstore_console_capture_log();
+static void pstore_console_capture_log(void)
+{
+	uint64_t id;
+	struct log_entry *log, *tmp;
 
-	console_set_active(pstore_cdev, CONSOLE_STDOUT);
+	list_for_each_entry_safe(log, tmp, &barebox_logbuf, list) {
+		psinfo->write_buf(PSTORE_TYPE_CONSOLE, 0, &id, 0,
+				  log->msg, 0, strlen(log->msg), psinfo);
+	}
 }
-#else
-static void pstore_register_console(void) {}
-#endif
 
 static int pstore_write_compat(struct pstore_record *record)
 {
@@ -151,7 +115,8 @@ int pstore_register(struct pstore_info *psi)
 
 	pstore_get_records(0);
 
-	pstore_register_console();
+	pstore_console_capture_log();
+	pstore_ready = 1;
 
 	pr_info("Registered %s as persistent store backend\n", psi->name);
 
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index 15e1e3d6fa..dabb639111 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -85,6 +85,7 @@ struct pstore_info {
 #ifdef CONFIG_FS_PSTORE
 extern int pstore_register(struct pstore_info *);
 extern bool pstore_cannot_block_path(enum kmsg_dump_reason reason);
+extern void pstore_log(const char *msg);
 #else
 static inline int
 pstore_register(struct pstore_info *psi)
@@ -96,6 +97,9 @@ pstore_cannot_block_path(enum kmsg_dump_reason reason)
 {
 	return false;
 }
+static inline void pstore_log(const char *msg)
+{
+}
 #endif
 
 #endif /*_LINUX_PSTORE_H*/
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] pstore: remove unused code
  2019-07-09  9:11 [PATCH 1/2] pstore: Only capture log messages Sascha Hauer
@ 2019-07-09  9:11 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-07-09  9:11 UTC (permalink / raw)
  To: Barebox List

pstore_info->write() is unused, remove the code implementing it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/pstore/platform.c   | 10 ----------
 fs/pstore/ram.c        | 17 -----------------
 include/linux/pstore.h |  2 --
 3 files changed, 29 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index aafa5559dc..0a6fa38edc 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -79,14 +79,6 @@ static void pstore_console_capture_log(void)
 	}
 }
 
-static int pstore_write_compat(struct pstore_record *record)
-{
-	return record->psi->write_buf(record->type, record->reason,
-				      &record->id, record->part,
-				      psinfo->buf, record->compressed,
-				      record->size, record->psi);
-}
-
 /*
  * platform specific persistent storage driver registers with
  * us here. If pstore is already mounted, call the platform
@@ -107,8 +99,6 @@ int pstore_register(struct pstore_info *psi)
 		return -EBUSY;
 	}
 
-	if (!psi->write)
-		psi->write = pstore_write_compat;
 	psinfo = psi;
 	mutex_init(&psinfo->read_mutex);
 	spin_unlock(&pstore_lock);
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 734d0c3c1d..86049f989e 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -609,22 +609,7 @@ static int ramoops_probe(struct device_d *dev)
 		goto fail_init_mprz;
 
 	cxt->pstore.data = cxt;
-	/*
-	 * Console can handle any buffer size, so prefer LOG_LINE_MAX. If we
-	 * have to handle dumps, we must have at least record_size buffer. And
-	 * for ftrace, bufsize is irrelevant (if bufsize is 0, buf will be
-	 * ZERO_SIZE_PTR).
-	 */
-	if (cxt->console_size)
-		cxt->pstore.bufsize = 1024; /* LOG_LINE_MAX */
-	cxt->pstore.bufsize = max(cxt->record_size, cxt->pstore.bufsize);
-	cxt->pstore.buf = kmalloc(cxt->pstore.bufsize, GFP_KERNEL);
 	spin_lock_init(&cxt->pstore.buf_lock);
-	if (!cxt->pstore.buf) {
-		pr_err("cannot allocate pstore buffer\n");
-		err = -ENOMEM;
-		goto fail_clear;
-	}
 
 	err = pstore_register(&cxt->pstore);
 	if (err) {
@@ -661,9 +646,7 @@ static int ramoops_probe(struct device_d *dev)
 	return 0;
 
 fail_buf:
-	kfree(cxt->pstore.buf);
 fail_clear:
-	cxt->pstore.bufsize = 0;
 	kfree(cxt->mprz);
 fail_init_mprz:
 	kfree(cxt->fprz);
diff --git a/include/linux/pstore.h b/include/linux/pstore.h
index dabb639111..f598f31a54 100644
--- a/include/linux/pstore.h
+++ b/include/linux/pstore.h
@@ -64,8 +64,6 @@ struct pstore_record {
 struct pstore_info {
 	struct module	*owner;
 	char		*name;
-	char		*buf;
-	size_t		bufsize;
 	int		flags;
 	int		(*open)(struct pstore_info *psi);
 	int		(*close)(struct pstore_info *psi);
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-09  9:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-09  9:11 [PATCH 1/2] pstore: Only capture log messages Sascha Hauer
2019-07-09  9:11 ` [PATCH 2/2] pstore: remove unused code Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox