Commit 3dc352c0 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'driver-core-3.5-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core

Pull printk fixes from Greg Kroah-Hartman:
 "Here are some more printk fixes for 3.5-rc6.  They resolve all known
  outstanding issues with the printk changes that have been happening.
  They have been tested by the people reporting the problems.

  This hopefully should be it for the printk stuff for 3.5-final.

  Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>"

* tag 'driver-core-3.5-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core:
  kmsg: merge continuation records while printing
  kmsg: /proc/kmsg - support reading of partial log records
  kmsg: make sure all messages reach a newly registered boot console
  kmsg: properly handle concurrent non-blocking read() from /proc/kmsg
  kmsg: add the facility number to the syslog prefix
  kmsg: escape the backslash character while exporting data
  printk: replacing the raw_spin_lock/unlock with raw_spin_lock/unlock_irq
parents 1e032dc5 5becfb1d
...@@ -194,8 +194,10 @@ static int console_may_schedule; ...@@ -194,8 +194,10 @@ static int console_may_schedule;
*/ */
enum log_flags { enum log_flags {
LOG_DEFAULT = 0, LOG_NOCONS = 1, /* already flushed, do not print to console */
LOG_NOCONS = 1, /* already flushed, do not print to console */ LOG_NEWLINE = 2, /* text ended with a newline */
LOG_PREFIX = 4, /* text started with a prefix */
LOG_CONT = 8, /* text is a fragment of a continuation line */
}; };
struct log { struct log {
...@@ -217,6 +219,8 @@ static DEFINE_RAW_SPINLOCK(logbuf_lock); ...@@ -217,6 +219,8 @@ static DEFINE_RAW_SPINLOCK(logbuf_lock);
/* the next printk record to read by syslog(READ) or /proc/kmsg */ /* the next printk record to read by syslog(READ) or /proc/kmsg */
static u64 syslog_seq; static u64 syslog_seq;
static u32 syslog_idx; static u32 syslog_idx;
static enum log_flags syslog_prev;
static size_t syslog_partial;
/* index and sequence number of the first record stored in the buffer */ /* index and sequence number of the first record stored in the buffer */
static u64 log_first_seq; static u64 log_first_seq;
...@@ -430,20 +434,20 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, ...@@ -430,20 +434,20 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
ret = mutex_lock_interruptible(&user->lock); ret = mutex_lock_interruptible(&user->lock);
if (ret) if (ret)
return ret; return ret;
raw_spin_lock(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
while (user->seq == log_next_seq) { while (user->seq == log_next_seq) {
if (file->f_flags & O_NONBLOCK) { if (file->f_flags & O_NONBLOCK) {
ret = -EAGAIN; ret = -EAGAIN;
raw_spin_unlock(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
goto out; goto out;
} }
raw_spin_unlock(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
ret = wait_event_interruptible(log_wait, ret = wait_event_interruptible(log_wait,
user->seq != log_next_seq); user->seq != log_next_seq);
if (ret) if (ret)
goto out; goto out;
raw_spin_lock(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
} }
if (user->seq < log_first_seq) { if (user->seq < log_first_seq) {
...@@ -451,7 +455,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, ...@@ -451,7 +455,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
user->idx = log_first_idx; user->idx = log_first_idx;
user->seq = log_first_seq; user->seq = log_first_seq;
ret = -EPIPE; ret = -EPIPE;
raw_spin_unlock(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
goto out; goto out;
} }
...@@ -465,7 +469,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, ...@@ -465,7 +469,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
for (i = 0; i < msg->text_len; i++) { for (i = 0; i < msg->text_len; i++) {
unsigned char c = log_text(msg)[i]; unsigned char c = log_text(msg)[i];
if (c < ' ' || c >= 128) if (c < ' ' || c >= 127 || c == '\\')
len += sprintf(user->buf + len, "\\x%02x", c); len += sprintf(user->buf + len, "\\x%02x", c);
else else
user->buf[len++] = c; user->buf[len++] = c;
...@@ -489,7 +493,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, ...@@ -489,7 +493,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
continue; continue;
} }
if (c < ' ' || c >= 128) { if (c < ' ' || c >= 127 || c == '\\') {
len += sprintf(user->buf + len, "\\x%02x", c); len += sprintf(user->buf + len, "\\x%02x", c);
continue; continue;
} }
...@@ -501,7 +505,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, ...@@ -501,7 +505,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
user->idx = log_next(user->idx); user->idx = log_next(user->idx);
user->seq++; user->seq++;
raw_spin_unlock(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
if (len > count) { if (len > count) {
ret = -EINVAL; ret = -EINVAL;
...@@ -528,7 +532,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) ...@@ -528,7 +532,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
if (offset) if (offset)
return -ESPIPE; return -ESPIPE;
raw_spin_lock(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
/* the first record */ /* the first record */
...@@ -552,7 +556,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) ...@@ -552,7 +556,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
default: default:
ret = -EINVAL; ret = -EINVAL;
} }
raw_spin_unlock(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
return ret; return ret;
} }
...@@ -566,14 +570,14 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait) ...@@ -566,14 +570,14 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
poll_wait(file, &log_wait, wait); poll_wait(file, &log_wait, wait);
raw_spin_lock(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
if (user->seq < log_next_seq) { if (user->seq < log_next_seq) {
/* return error when data has vanished underneath us */ /* return error when data has vanished underneath us */
if (user->seq < log_first_seq) if (user->seq < log_first_seq)
ret = POLLIN|POLLRDNORM|POLLERR|POLLPRI; ret = POLLIN|POLLRDNORM|POLLERR|POLLPRI;
ret = POLLIN|POLLRDNORM; ret = POLLIN|POLLRDNORM;
} }
raw_spin_unlock(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
return ret; return ret;
} }
...@@ -597,10 +601,10 @@ static int devkmsg_open(struct inode *inode, struct file *file) ...@@ -597,10 +601,10 @@ static int devkmsg_open(struct inode *inode, struct file *file)
mutex_init(&user->lock); mutex_init(&user->lock);
raw_spin_lock(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
user->idx = log_first_idx; user->idx = log_first_idx;
user->seq = log_first_seq; user->seq = log_first_seq;
raw_spin_unlock(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
file->private_data = user; file->private_data = user;
return 0; return 0;
...@@ -818,15 +822,18 @@ static size_t print_time(u64 ts, char *buf) ...@@ -818,15 +822,18 @@ static size_t print_time(u64 ts, char *buf)
static size_t print_prefix(const struct log *msg, bool syslog, char *buf) static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
{ {
size_t len = 0; size_t len = 0;
unsigned int prefix = (msg->facility << 3) | msg->level;
if (syslog) { if (syslog) {
if (buf) { if (buf) {
len += sprintf(buf, "<%u>", msg->level); len += sprintf(buf, "<%u>", prefix);
} else { } else {
len += 3; len += 3;
if (msg->level > 9) if (prefix > 999)
len++; len += 3;
if (msg->level > 99) else if (prefix > 99)
len += 2;
else if (prefix > 9)
len++; len++;
} }
} }
...@@ -835,13 +842,26 @@ static size_t print_prefix(const struct log *msg, bool syslog, char *buf) ...@@ -835,13 +842,26 @@ static size_t print_prefix(const struct log *msg, bool syslog, char *buf)
return len; return len;
} }
static size_t msg_print_text(const struct log *msg, bool syslog, static size_t msg_print_text(const struct log *msg, enum log_flags prev,
char *buf, size_t size) bool syslog, char *buf, size_t size)
{ {
const char *text = log_text(msg); const char *text = log_text(msg);
size_t text_size = msg->text_len; size_t text_size = msg->text_len;
bool prefix = true;
bool newline = true;
size_t len = 0; size_t len = 0;
if ((prev & LOG_CONT) && !(msg->flags & LOG_PREFIX))
prefix = false;
if (msg->flags & LOG_CONT) {
if ((prev & LOG_CONT) && !(prev & LOG_NEWLINE))
prefix = false;
if (!(msg->flags & LOG_NEWLINE))
newline = false;
}
do { do {
const char *next = memchr(text, '\n', text_size); const char *next = memchr(text, '\n', text_size);
size_t text_len; size_t text_len;
...@@ -859,16 +879,22 @@ static size_t msg_print_text(const struct log *msg, bool syslog, ...@@ -859,16 +879,22 @@ static size_t msg_print_text(const struct log *msg, bool syslog,
text_len + 1>= size - len) text_len + 1>= size - len)
break; break;
len += print_prefix(msg, syslog, buf + len); if (prefix)
len += print_prefix(msg, syslog, buf + len);
memcpy(buf + len, text, text_len); memcpy(buf + len, text, text_len);
len += text_len; len += text_len;
buf[len++] = '\n'; if (next || newline)
buf[len++] = '\n';
} else { } else {
/* SYSLOG_ACTION_* buffer size only calculation */ /* SYSLOG_ACTION_* buffer size only calculation */
len += print_prefix(msg, syslog, NULL); if (prefix)
len += text_len + 1; len += print_prefix(msg, syslog, NULL);
len += text_len;
if (next || newline)
len++;
} }
prefix = true;
text = next; text = next;
} while (text); } while (text);
...@@ -887,22 +913,35 @@ static int syslog_print(char __user *buf, int size) ...@@ -887,22 +913,35 @@ static int syslog_print(char __user *buf, int size)
while (size > 0) { while (size > 0) {
size_t n; size_t n;
size_t skip;
raw_spin_lock_irq(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
if (syslog_seq < log_first_seq) { if (syslog_seq < log_first_seq) {
/* messages are gone, move to first one */ /* messages are gone, move to first one */
syslog_seq = log_first_seq; syslog_seq = log_first_seq;
syslog_idx = log_first_idx; syslog_idx = log_first_idx;
syslog_prev = 0;
syslog_partial = 0;
} }
if (syslog_seq == log_next_seq) { if (syslog_seq == log_next_seq) {
raw_spin_unlock_irq(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
break; break;
} }
skip = syslog_partial;
msg = log_from_idx(syslog_idx); msg = log_from_idx(syslog_idx);
n = msg_print_text(msg, true, text, LOG_LINE_MAX); n = msg_print_text(msg, syslog_prev, true, text, LOG_LINE_MAX);
if (n <= size) { if (n - syslog_partial <= size) {
/* message fits into buffer, move forward */
syslog_idx = log_next(syslog_idx); syslog_idx = log_next(syslog_idx);
syslog_seq++; syslog_seq++;
syslog_prev = msg->flags;
n -= syslog_partial;
syslog_partial = 0;
} else if (!len){
/* partial read(), remember position */
n = size;
syslog_partial += n;
} else } else
n = 0; n = 0;
raw_spin_unlock_irq(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
...@@ -910,17 +949,15 @@ static int syslog_print(char __user *buf, int size) ...@@ -910,17 +949,15 @@ static int syslog_print(char __user *buf, int size)
if (!n) if (!n)
break; break;
len += n; if (copy_to_user(buf, text + skip, n)) {
size -= n;
buf += n;
n = copy_to_user(buf - n, text, n);
if (n) {
len -= n;
if (!len) if (!len)
len = -EFAULT; len = -EFAULT;
break; break;
} }
len += n;
size -= n;
buf += n;
} }
kfree(text); kfree(text);
...@@ -941,6 +978,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear) ...@@ -941,6 +978,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
u64 next_seq; u64 next_seq;
u64 seq; u64 seq;
u32 idx; u32 idx;
enum log_flags prev;
if (clear_seq < log_first_seq) { if (clear_seq < log_first_seq) {
/* messages are gone, move to first available one */ /* messages are gone, move to first available one */
...@@ -954,10 +992,11 @@ static int syslog_print_all(char __user *buf, int size, bool clear) ...@@ -954,10 +992,11 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
*/ */
seq = clear_seq; seq = clear_seq;
idx = clear_idx; idx = clear_idx;
prev = 0;
while (seq < log_next_seq) { while (seq < log_next_seq) {
struct log *msg = log_from_idx(idx); struct log *msg = log_from_idx(idx);
len += msg_print_text(msg, true, NULL, 0); len += msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
} }
...@@ -965,10 +1004,11 @@ static int syslog_print_all(char __user *buf, int size, bool clear) ...@@ -965,10 +1004,11 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
/* move first record forward until length fits into the buffer */ /* move first record forward until length fits into the buffer */
seq = clear_seq; seq = clear_seq;
idx = clear_idx; idx = clear_idx;
prev = 0;
while (len > size && seq < log_next_seq) { while (len > size && seq < log_next_seq) {
struct log *msg = log_from_idx(idx); struct log *msg = log_from_idx(idx);
len -= msg_print_text(msg, true, NULL, 0); len -= msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
} }
...@@ -977,17 +1017,19 @@ static int syslog_print_all(char __user *buf, int size, bool clear) ...@@ -977,17 +1017,19 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
next_seq = log_next_seq; next_seq = log_next_seq;
len = 0; len = 0;
prev = 0;
while (len >= 0 && seq < next_seq) { while (len >= 0 && seq < next_seq) {
struct log *msg = log_from_idx(idx); struct log *msg = log_from_idx(idx);
int textlen; int textlen;
textlen = msg_print_text(msg, true, text, LOG_LINE_MAX); textlen = msg_print_text(msg, prev, true, text, LOG_LINE_MAX);
if (textlen < 0) { if (textlen < 0) {
len = textlen; len = textlen;
break; break;
} }
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
prev = msg->flags;
raw_spin_unlock_irq(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
if (copy_to_user(buf + len, text, textlen)) if (copy_to_user(buf + len, text, textlen))
...@@ -1000,6 +1042,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear) ...@@ -1000,6 +1042,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
/* messages are gone, move to next one */ /* messages are gone, move to next one */
seq = log_first_seq; seq = log_first_seq;
idx = log_first_idx; idx = log_first_idx;
prev = 0;
} }
} }
} }
...@@ -1018,7 +1061,6 @@ int do_syslog(int type, char __user *buf, int len, bool from_file) ...@@ -1018,7 +1061,6 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
{ {
bool clear = false; bool clear = false;
static int saved_console_loglevel = -1; static int saved_console_loglevel = -1;
static DEFINE_MUTEX(syslog_mutex);
int error; int error;
error = check_syslog_permissions(type, from_file); error = check_syslog_permissions(type, from_file);
...@@ -1045,17 +1087,11 @@ int do_syslog(int type, char __user *buf, int len, bool from_file) ...@@ -1045,17 +1087,11 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
error = -EFAULT; error = -EFAULT;
goto out; goto out;
} }
error = mutex_lock_interruptible(&syslog_mutex);
if (error)
goto out;
error = wait_event_interruptible(log_wait, error = wait_event_interruptible(log_wait,
syslog_seq != log_next_seq); syslog_seq != log_next_seq);
if (error) { if (error)
mutex_unlock(&syslog_mutex);
goto out; goto out;
}
error = syslog_print(buf, len); error = syslog_print(buf, len);
mutex_unlock(&syslog_mutex);
break; break;
/* Read/clear last kernel messages */ /* Read/clear last kernel messages */
case SYSLOG_ACTION_READ_CLEAR: case SYSLOG_ACTION_READ_CLEAR:
...@@ -1111,6 +1147,8 @@ int do_syslog(int type, char __user *buf, int len, bool from_file) ...@@ -1111,6 +1147,8 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
/* messages are gone, move to first one */ /* messages are gone, move to first one */
syslog_seq = log_first_seq; syslog_seq = log_first_seq;
syslog_idx = log_first_idx; syslog_idx = log_first_idx;
syslog_prev = 0;
syslog_partial = 0;
} }
if (from_file) { if (from_file) {
/* /*
...@@ -1120,19 +1158,20 @@ int do_syslog(int type, char __user *buf, int len, bool from_file) ...@@ -1120,19 +1158,20 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
*/ */
error = log_next_idx - syslog_idx; error = log_next_idx - syslog_idx;
} else { } else {
u64 seq; u64 seq = syslog_seq;
u32 idx; u32 idx = syslog_idx;
enum log_flags prev = syslog_prev;
error = 0; error = 0;
seq = syslog_seq;
idx = syslog_idx;
while (seq < log_next_seq) { while (seq < log_next_seq) {
struct log *msg = log_from_idx(idx); struct log *msg = log_from_idx(idx);
error += msg_print_text(msg, true, NULL, 0); error += msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
prev = msg->flags;
} }
error -= syslog_partial;
} }
raw_spin_unlock_irq(&logbuf_lock); raw_spin_unlock_irq(&logbuf_lock);
break; break;
...@@ -1400,10 +1439,9 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1400,10 +1439,9 @@ asmlinkage int vprintk_emit(int facility, int level,
static char textbuf[LOG_LINE_MAX]; static char textbuf[LOG_LINE_MAX];
char *text = textbuf; char *text = textbuf;
size_t text_len; size_t text_len;
enum log_flags lflags = 0;
unsigned long flags; unsigned long flags;
int this_cpu; int this_cpu;
bool newline = false;
bool prefix = false;
int printed_len = 0; int printed_len = 0;
boot_delay_msec(); boot_delay_msec();
...@@ -1442,7 +1480,7 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1442,7 +1480,7 @@ asmlinkage int vprintk_emit(int facility, int level,
recursion_bug = 0; recursion_bug = 0;
printed_len += strlen(recursion_msg); printed_len += strlen(recursion_msg);
/* emit KERN_CRIT message */ /* emit KERN_CRIT message */
log_store(0, 2, LOG_DEFAULT, 0, log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0,
NULL, 0, recursion_msg, printed_len); NULL, 0, recursion_msg, printed_len);
} }
...@@ -1455,7 +1493,7 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1455,7 +1493,7 @@ asmlinkage int vprintk_emit(int facility, int level,
/* mark and strip a trailing newline */ /* mark and strip a trailing newline */
if (text_len && text[text_len-1] == '\n') { if (text_len && text[text_len-1] == '\n') {
text_len--; text_len--;
newline = true; lflags |= LOG_NEWLINE;
} }
/* strip syslog prefix and extract log level or control flags */ /* strip syslog prefix and extract log level or control flags */
...@@ -1465,7 +1503,7 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1465,7 +1503,7 @@ asmlinkage int vprintk_emit(int facility, int level,
if (level == -1) if (level == -1)
level = text[1] - '0'; level = text[1] - '0';
case 'd': /* KERN_DEFAULT */ case 'd': /* KERN_DEFAULT */
prefix = true; lflags |= LOG_PREFIX;
case 'c': /* KERN_CONT */ case 'c': /* KERN_CONT */
text += 3; text += 3;
text_len -= 3; text_len -= 3;
...@@ -1475,22 +1513,20 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1475,22 +1513,20 @@ asmlinkage int vprintk_emit(int facility, int level,
if (level == -1) if (level == -1)
level = default_message_loglevel; level = default_message_loglevel;
if (dict) { if (dict)
prefix = true; lflags |= LOG_PREFIX|LOG_NEWLINE;
newline = true;
}
if (!newline) { if (!(lflags & LOG_NEWLINE)) {
/* /*
* Flush the conflicting buffer. An earlier newline was missing, * Flush the conflicting buffer. An earlier newline was missing,
* or another task also prints continuation lines. * or another task also prints continuation lines.
*/ */
if (cont.len && (prefix || cont.owner != current)) if (cont.len && (lflags & LOG_PREFIX || cont.owner != current))
cont_flush(); cont_flush();
/* buffer line if possible, otherwise store it right away */ /* buffer line if possible, otherwise store it right away */
if (!cont_add(facility, level, text, text_len)) if (!cont_add(facility, level, text, text_len))
log_store(facility, level, LOG_DEFAULT, 0, log_store(facility, level, lflags | LOG_CONT, 0,
dict, dictlen, text, text_len); dict, dictlen, text, text_len);
} else { } else {
bool stored = false; bool stored = false;
...@@ -1502,13 +1538,13 @@ asmlinkage int vprintk_emit(int facility, int level, ...@@ -1502,13 +1538,13 @@ asmlinkage int vprintk_emit(int facility, int level,
* flush it out and store this line separately. * flush it out and store this line separately.
*/ */
if (cont.len && cont.owner == current) { if (cont.len && cont.owner == current) {
if (!prefix) if (!(lflags & LOG_PREFIX))
stored = cont_add(facility, level, text, text_len); stored = cont_add(facility, level, text, text_len);
cont_flush(); cont_flush();
} }
if (!stored) if (!stored)
log_store(facility, level, LOG_DEFAULT, 0, log_store(facility, level, lflags, 0,
dict, dictlen, text, text_len); dict, dictlen, text, text_len);
} }
printed_len += text_len; printed_len += text_len;
...@@ -1607,8 +1643,8 @@ static struct cont { ...@@ -1607,8 +1643,8 @@ static struct cont {
static struct log *log_from_idx(u32 idx) { return NULL; } static struct log *log_from_idx(u32 idx) { return NULL; }
static u32 log_next(u32 idx) { return 0; } static u32 log_next(u32 idx) { return 0; }
static void call_console_drivers(int level, const char *text, size_t len) {} static void call_console_drivers(int level, const char *text, size_t len) {}
static size_t msg_print_text(const struct log *msg, bool syslog, static size_t msg_print_text(const struct log *msg, enum log_flags prev,
char *buf, size_t size) { return 0; } bool syslog, char *buf, size_t size) { return 0; }
static size_t cont_print_text(char *text, size_t size) { return 0; } static size_t cont_print_text(char *text, size_t size) { return 0; }
#endif /* CONFIG_PRINTK */ #endif /* CONFIG_PRINTK */
...@@ -1884,6 +1920,7 @@ void wake_up_klogd(void) ...@@ -1884,6 +1920,7 @@ void wake_up_klogd(void)
/* the next printk record to write to the console */ /* the next printk record to write to the console */
static u64 console_seq; static u64 console_seq;
static u32 console_idx; static u32 console_idx;
static enum log_flags console_prev;
/** /**
* console_unlock - unlock the console system * console_unlock - unlock the console system
...@@ -1944,6 +1981,7 @@ void console_unlock(void) ...@@ -1944,6 +1981,7 @@ void console_unlock(void)
/* messages are gone, move to first one */ /* messages are gone, move to first one */
console_seq = log_first_seq; console_seq = log_first_seq;
console_idx = log_first_idx; console_idx = log_first_idx;
console_prev = 0;
} }
skip: skip:
if (console_seq == log_next_seq) if (console_seq == log_next_seq)
...@@ -1957,14 +1995,21 @@ void console_unlock(void) ...@@ -1957,14 +1995,21 @@ void console_unlock(void)
*/ */
console_idx = log_next(console_idx); console_idx = log_next(console_idx);
console_seq++; console_seq++;
/*
* We will get here again when we register a new
* CON_PRINTBUFFER console. Clear the flag so we
* will properly dump everything later.
*/
msg->flags &= ~LOG_NOCONS;
goto skip; goto skip;
} }
level = msg->level; level = msg->level;
len = msg_print_text(msg, false, text, sizeof(text)); len = msg_print_text(msg, console_prev, false,
text, sizeof(text));
console_idx = log_next(console_idx); console_idx = log_next(console_idx);
console_seq++; console_seq++;
console_prev = msg->flags;
raw_spin_unlock(&logbuf_lock); raw_spin_unlock(&logbuf_lock);
stop_critical_timings(); /* don't trace print latency */ stop_critical_timings(); /* don't trace print latency */
...@@ -2227,6 +2272,7 @@ void register_console(struct console *newcon) ...@@ -2227,6 +2272,7 @@ void register_console(struct console *newcon)
raw_spin_lock_irqsave(&logbuf_lock, flags); raw_spin_lock_irqsave(&logbuf_lock, flags);
console_seq = syslog_seq; console_seq = syslog_seq;
console_idx = syslog_idx; console_idx = syslog_idx;
console_prev = syslog_prev;
raw_spin_unlock_irqrestore(&logbuf_lock, flags); raw_spin_unlock_irqrestore(&logbuf_lock, flags);
/* /*
* We're about to replay the log buffer. Only do this to the * We're about to replay the log buffer. Only do this to the
...@@ -2520,8 +2566,7 @@ bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog, ...@@ -2520,8 +2566,7 @@ bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
} }
msg = log_from_idx(dumper->cur_idx); msg = log_from_idx(dumper->cur_idx);
l = msg_print_text(msg, syslog, l = msg_print_text(msg, 0, syslog, line, size);
line, size);
dumper->cur_idx = log_next(dumper->cur_idx); dumper->cur_idx = log_next(dumper->cur_idx);
dumper->cur_seq++; dumper->cur_seq++;
...@@ -2561,6 +2606,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, ...@@ -2561,6 +2606,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
u32 idx; u32 idx;
u64 next_seq; u64 next_seq;
u32 next_idx; u32 next_idx;
enum log_flags prev;
size_t l = 0; size_t l = 0;
bool ret = false; bool ret = false;
...@@ -2583,23 +2629,27 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, ...@@ -2583,23 +2629,27 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
/* calculate length of entire buffer */ /* calculate length of entire buffer */
seq = dumper->cur_seq; seq = dumper->cur_seq;
idx = dumper->cur_idx; idx = dumper->cur_idx;
prev = 0;
while (seq < dumper->next_seq) { while (seq < dumper->next_seq) {
struct log *msg = log_from_idx(idx); struct log *msg = log_from_idx(idx);
l += msg_print_text(msg, true, NULL, 0); l += msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
prev = msg->flags;
} }
/* move first record forward until length fits into the buffer */ /* move first record forward until length fits into the buffer */
seq = dumper->cur_seq; seq = dumper->cur_seq;
idx = dumper->cur_idx; idx = dumper->cur_idx;
prev = 0;
while (l > size && seq < dumper->next_seq) { while (l > size && seq < dumper->next_seq) {
struct log *msg = log_from_idx(idx); struct log *msg = log_from_idx(idx);
l -= msg_print_text(msg, true, NULL, 0); l -= msg_print_text(msg, prev, true, NULL, 0);
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
prev = msg->flags;
} }
/* last message in next interation */ /* last message in next interation */
...@@ -2607,14 +2657,14 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, ...@@ -2607,14 +2657,14 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
next_idx = idx; next_idx = idx;
l = 0; l = 0;
prev = 0;
while (seq < dumper->next_seq) { while (seq < dumper->next_seq) {
struct log *msg = log_from_idx(idx); struct log *msg = log_from_idx(idx);
l += msg_print_text(msg, syslog, l += msg_print_text(msg, prev, syslog, buf + l, size - l);
buf + l, size - l);
idx = log_next(idx); idx = log_next(idx);
seq++; seq++;
prev = msg->flags;
} }
dumper->next_seq = next_seq; dumper->next_seq = next_seq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment