Commit bfd8d3f2 authored by Linus Torvalds's avatar Linus Torvalds

printk: make reading the kernel log flush pending lines

That will mean that any possible subsequent continuation will now be
broken up onto a line of its own (since reading the log has finalized
the beginning og the line), but if user space has activated system
logging (or if there's a kernel message dump going on) that is the right
thing to do.

And now that we actually get the continuation flags _right_ for this
all, the user space logger that is reading the kernel messages can
actually see the continuation marker.  Not that anybody seems to really
bother with it (or care), but in theory user space can do its own
message stitching.
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5e467652
...@@ -783,6 +783,8 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from) ...@@ -783,6 +783,8 @@ static ssize_t devkmsg_write(struct kiocb *iocb, struct iov_iter *from)
return ret; return ret;
} }
static void cont_flush(void);
static ssize_t devkmsg_read(struct file *file, char __user *buf, static ssize_t devkmsg_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
...@@ -798,6 +800,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, ...@@ -798,6 +800,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
if (ret) if (ret)
return ret; return ret;
raw_spin_lock_irq(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
cont_flush();
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;
...@@ -860,6 +863,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence) ...@@ -860,6 +863,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
return -ESPIPE; return -ESPIPE;
raw_spin_lock_irq(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
cont_flush();
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
/* the first record */ /* the first record */
...@@ -898,6 +902,7 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait) ...@@ -898,6 +902,7 @@ 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_irq(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
cont_flush();
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)
...@@ -1284,6 +1289,7 @@ static int syslog_print(char __user *buf, int size) ...@@ -1284,6 +1289,7 @@ static int syslog_print(char __user *buf, int size)
size_t skip; size_t skip;
raw_spin_lock_irq(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
cont_flush();
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;
...@@ -1343,6 +1349,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear) ...@@ -1343,6 +1349,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
return -ENOMEM; return -ENOMEM;
raw_spin_lock_irq(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
cont_flush();
if (buf) { if (buf) {
u64 next_seq; u64 next_seq;
u64 seq; u64 seq;
...@@ -1504,6 +1511,7 @@ int do_syslog(int type, char __user *buf, int len, int source) ...@@ -1504,6 +1511,7 @@ int do_syslog(int type, char __user *buf, int len, int source)
/* Number of chars in the log buffer */ /* Number of chars in the log buffer */
case SYSLOG_ACTION_SIZE_UNREAD: case SYSLOG_ACTION_SIZE_UNREAD:
raw_spin_lock_irq(&logbuf_lock); raw_spin_lock_irq(&logbuf_lock);
cont_flush();
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;
...@@ -3016,6 +3024,7 @@ void kmsg_dump(enum kmsg_dump_reason reason) ...@@ -3016,6 +3024,7 @@ void kmsg_dump(enum kmsg_dump_reason reason)
dumper->active = true; dumper->active = true;
raw_spin_lock_irqsave(&logbuf_lock, flags); raw_spin_lock_irqsave(&logbuf_lock, flags);
cont_flush();
dumper->cur_seq = clear_seq; dumper->cur_seq = clear_seq;
dumper->cur_idx = clear_idx; dumper->cur_idx = clear_idx;
dumper->next_seq = log_next_seq; dumper->next_seq = log_next_seq;
...@@ -3106,6 +3115,7 @@ bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog, ...@@ -3106,6 +3115,7 @@ bool kmsg_dump_get_line(struct kmsg_dumper *dumper, bool syslog,
bool ret; bool ret;
raw_spin_lock_irqsave(&logbuf_lock, flags); raw_spin_lock_irqsave(&logbuf_lock, flags);
cont_flush();
ret = kmsg_dump_get_line_nolock(dumper, syslog, line, size, len); ret = kmsg_dump_get_line_nolock(dumper, syslog, line, size, len);
raw_spin_unlock_irqrestore(&logbuf_lock, flags); raw_spin_unlock_irqrestore(&logbuf_lock, flags);
...@@ -3148,6 +3158,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog, ...@@ -3148,6 +3158,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
goto out; goto out;
raw_spin_lock_irqsave(&logbuf_lock, flags); raw_spin_lock_irqsave(&logbuf_lock, flags);
cont_flush();
if (dumper->cur_seq < log_first_seq) { if (dumper->cur_seq < log_first_seq) {
/* messages are gone, move to first available one */ /* messages are gone, move to first available one */
dumper->cur_seq = log_first_seq; dumper->cur_seq = log_first_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