mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mike Frysinger" <vapier.adi@gmail.com>
To: "Andrew Morton" <akpm@linux-foundation.org>
Cc: "Robin Getz" <rgetz@blackfin.uclinux.org>,
	linux-kernel@vger.kernel.org, "Greg Ungerer" <gerg@snapgear.com>,
	"Russell King" <rmk@arm.linux.org.uk>,
	"Paul Mundt" <lethal@linux-sh.org>,
	"Tim Bird" <tim.bird@am.sony.com>,
	bryan.wu@analog.com
Subject: Re: early_printk accessing __log_buf
Date: Tue, 31 Jul 2007 03:47:59 -0400	[thread overview]
Message-ID: <8bd0f97a0707310047u51c6e46l7e57e8f7bfc4e858@mail.gmail.com> (raw)
In-Reply-To: <20070724143004.6325a511.akpm@linux-foundation.org>

[-- Attachment #1: Type: text/plain, Size: 688 bytes --]

On 7/24/07, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Tue, 24 Jul 2007 16:12:56 -0400 Robin Getz wrote:
> > On Tue 24 Jul 2007 14:12, Andrew Morton pondered:
> > > Oh well, it sounds like we need the super-duper fast version.  Keep it
> > > as simple as possible, please.
> >
> > What about:
> >
> > int log_buf_copy(void *dest, int idx, size_t n);
> >
> > starting at index idx - copy n bytes to dest, return the number of bytes
> > copied (in case there are not n bytes in the log_buf yet).
>
> Sounds sensible.  I'd make it return size_t and take a char* arg though.
> Or just use `int' - size_t is a bit of a pain and this is all kernel-internal
> anwyay.

attached
-mike

[-- Attachment #2: linux-log_buf_read.patch --]
[-- Type: application/octet-stream, Size: 2449 bytes --]

Add two new functions for reading the kernel log buffer.  Their intention
is to be used by recovery/dump/debug code so the kernel log can be easily
retrieved/parsed in a crash scenario, but they are generic enough for other
people to dream up other fun uses.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 4300bb4..8d5b6c7 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -156,6 +156,9 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 	__attribute__ ((format (printf, 1, 0)));
 asmlinkage int printk(const char * fmt, ...)
 	__attribute__ ((format (printf, 1, 2))) __cold;
+extern int log_buf_get_len(void);
+extern int log_buf_read(int idx);
+extern int log_buf_copy(char *dest, int idx, int len);
 #else
 static inline int vprintk(const char *s, va_list args)
 	__attribute__ ((format (printf, 1, 0)));
@@ -163,6 +166,9 @@ static inline int vprintk(const char *s, va_list args) { return 0; }
 static inline int printk(const char *s, ...)
 	__attribute__ ((format (printf, 1, 2)));
 static inline int __cold printk(const char *s, ...) { return 0; }
+static inline int log_buf_get_len(void) { return 0; }
+static inline int log_buf_read(int idx); { return 0; }
+static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
 #endif
 
 unsigned long int_sqrt(unsigned long);
diff --git a/kernel/printk.c b/kernel/printk.c
index 051d27e..35b231a 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -163,6 +163,55 @@ out:
 __setup("log_buf_len=", log_buf_len_setup);
 
 /*
+ * Return the number of unread characters in the log buffer.
+ */
+int log_buf_get_len(void)
+{
+	return log_end - log_start;
+}
+
+/*
+ * Copy a range of characters from the log buffer.
+ */
+int log_buf_copy(char *dest, int idx, int len)
+{
+	int ret, max;
+
+	if (!oops_in_progress)
+		spin_lock_irq(&logbuf_lock);
+
+	max = log_buf_get_len();
+	if (idx < 0 || idx >= max)
+		ret = -1;
+	else {
+		if (len > max)
+			len = max;
+		ret = len;
+		while (len-- > 0) {
+			*dest = LOG_BUF(idx++);
+			++dest;
+		}
+	}
+
+	if (!oops_in_progress)
+		spin_unlock_irq(&logbuf_lock);
+
+	return ret;
+}
+
+/*
+ * Extract a single character from the log buffer.
+ */
+int log_buf_read(int idx)
+{
+	char ret;
+	if (log_buf_copy(&ret, idx, 1) == 1)
+		return ret;
+	else
+		return -1;
+}
+
+/*
  * Commands to do_syslog:
  *
  * 	0 -- Close the log.  Currently a NOP.

  reply	other threads:[~2007-07-31  7:48 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-18 21:56 Robin Getz
2007-07-18 22:16 ` Andrew Morton
2007-07-18 23:39   ` Robin Getz
2007-07-18 23:53     ` Mike Frysinger
2007-07-19  3:37       ` Robin Getz
2007-07-19  3:47         ` Andrew Morton
2007-07-19  0:26     ` Andrew Morton
2007-07-19  2:26       ` Stephane Couture
2007-07-19  3:58       ` Robin Getz
2007-07-22 23:50         ` Mike Frysinger
2007-07-23  0:14           ` Paul Mundt
2007-07-23 18:19           ` Robin Getz
2007-07-23 20:15             ` Andrew Morton
2007-07-23 20:54               ` Mike Frysinger
2007-07-23 21:05                 ` Andrew Morton
2007-07-23 22:10                   ` Mike Frysinger
2007-07-23 22:15               ` Robin Getz
2007-07-23 22:34                 ` Andrew Morton
2007-07-24 17:50                   ` Robin Getz
2007-07-24 18:12                     ` Andrew Morton
2007-07-24 20:12                       ` Robin Getz
2007-07-24 21:30                         ` Andrew Morton
2007-07-31  7:47                           ` Mike Frysinger [this message]
2007-07-31  7:59                             ` Bryan Wu
2007-07-31  8:11                               ` Mike Frysinger
2007-07-31 18:36                             ` Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8bd0f97a0707310047u51c6e46l7e57e8f7bfc4e858@mail.gmail.com \
    --to=vapier.adi@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bryan.wu@analog.com \
    --cc=gerg@snapgear.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rgetz@blackfin.uclinux.org \
    --cc=rmk@arm.linux.org.uk \
    --cc=tim.bird@am.sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®