LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Tejun Heo <htejun@gmail.com>
To: jeff@garzik.org, linux-ide@vger.kernel.org,
	jengelh@computergmbh.de, matthew@wil.cx, randy.dunlap@oracle.com,
	daniel.ritz-ml@swissonline.ch, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 1/5] printk: keep log level on multiline messages
Date: Wed, 13 Feb 2008 18:09:29 +0900	[thread overview]
Message-ID: <12028937733464-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <12028937731333-git-send-email-htejun@gmail.com>

When printing multiline messages, printk() resets log level to
default_message_loglevel after the first line.  This changes log level
unexpectedly when printing multiline messages.

For example, libata error messages are printed like the following.

<3>ata8.00: cmd 60/01:00:e0:71:02/00:00:00:00:00/40 tag 0 ncq 512 in
<4>         res 40/00:34:de:71:02/00:00:00:00:00/40 Emask 0x10 (ATA bus error)

This patch makes printk use the log level of the last line if the
current line doesn't specify log level explicitly.

While at it, separate out is_loglevel() test.  This will be used by
later changes.

Signed-off-by: Tejun Heo <htejun@gmail.com>
---
 kernel/printk.c |   50 +++++++++++++++++++++++---------------------------
 1 files changed, 23 insertions(+), 27 deletions(-)

diff --git a/kernel/printk.c b/kernel/printk.c
index 419cd47..2317ec8 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -614,6 +614,11 @@ asmlinkage int printk(const char *fmt, ...)
 	return r;
 }
 
+static int is_loglevel(const char *p)
+{
+	return p[0] == '<' && p[1] >= '0' && p[1] <= '7' && p[2] == '>';
+}
+
 asmlinkage int vprintk(const char *fmt, va_list args)
 {
 	/* cpu currently holding logbuf_lock */
@@ -625,10 +630,11 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 	static int log_level_unknown = 1;
 	static char printk_buf[PRINTK_BUF_LEN + sizeof(overflow_tag) - 1];
 
+	int last_lv = default_message_loglevel;
 	unsigned long flags;
 	int printed_len = 0;
 	int this_cpu;
-	char *p;
+	const char *p;
 
 	boot_delay_msec();
 
@@ -682,47 +688,37 @@ asmlinkage int vprintk(const char *fmt, va_list args)
 	for (p = printk_buf; *p; p++) {
 		if (log_level_unknown) {
                         /* log_level_unknown signals the start of a new line */
+			int lv = last_lv;
+
+			if (is_loglevel(p)) {
+				lv = p[1] - '0';
+				p += 3;
+				printed_len -= 3;
+			}
+
+			emit_log_char('<');
+			emit_log_char(lv + '0');
+			emit_log_char('>');
+			printed_len += 3;
+
 			if (printk_time) {
-				int loglev_char;
 				char tbuf[50], *tp;
 				unsigned tlen;
 				unsigned long long t;
 				unsigned long nanosec_rem;
 
-				/*
-				 * force the log level token to be
-				 * before the time output.
-				 */
-				if (p[0] == '<' && p[1] >='0' &&
-				   p[1] <= '7' && p[2] == '>') {
-					loglev_char = p[1];
-					p += 3;
-					printed_len -= 3;
-				} else {
-					loglev_char = default_message_loglevel
-						+ '0';
-				}
 				t = cpu_clock(printk_cpu);
 				nanosec_rem = do_div(t, 1000000000);
-				tlen = sprintf(tbuf,
-						"<%c>[%5lu.%06lu] ",
-						loglev_char,
+				tlen = sprintf(tbuf, "[%5lu.%06lu] ",
 						(unsigned long)t,
 						nanosec_rem/1000);
 
 				for (tp = tbuf; tp < tbuf + tlen; tp++)
 					emit_log_char(*tp);
 				printed_len += tlen;
-			} else {
-				if (p[0] != '<' || p[1] < '0' ||
-				   p[1] > '7' || p[2] != '>') {
-					emit_log_char('<');
-					emit_log_char(default_message_loglevel
-						+ '0');
-					emit_log_char('>');
-					printed_len += 3;
-				}
 			}
+
+			last_lv = lv;
 			log_level_unknown = 0;
 			if (!*p)
 				break;
-- 
1.5.2.4


  reply	other threads:[~2008-02-13  9:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-13  9:09 [PATCHSET] printk: implement printk_header() and merging printk, take #3 Tejun Heo
2008-02-13  9:09 ` Tejun Heo [this message]
2008-02-13  9:09 ` [PATCH 2/5] printk: implement [v]printk_header() Tejun Heo
2008-02-13  9:09 ` [PATCH 3/5] printk: implement merging printk Tejun Heo
2008-02-13  9:09 ` [PATCH 4/5] printk: add Documentation/printk.txt Tejun Heo
2008-02-13  9:09 ` [PATCH 5/5] libata: make libata use printk_header() and mprintk Tejun Heo
2008-02-13 23:57 ` [PATCHSET] printk: implement printk_header() and merging printk, take #3 Andrew Morton
2008-02-14  0:40   ` Tejun Heo
2008-02-14  1:09     ` Andrew Morton
2008-02-14  1:26       ` Tejun Heo
2008-02-15  1:49         ` Tejun Heo
2008-02-15  2:27           ` Andrew Morton
2008-02-15  2:36             ` Tejun Heo
2008-02-15  2:50               ` Andrew Morton
2008-02-15  3:16                 ` Tejun Heo
2008-02-16 14:13                   ` Mark Lord
2008-02-14 16:29     ` Mark Lord
  -- strict thread matches above, loose matches on Subject: below --
2008-01-21  5:13 [PATCHSET] printk: implement printk_header() and merging printk, take #2 Tejun Heo
2008-01-21  5:13 ` [PATCH 1/5] printk: keep log level on multiline messages Tejun Heo

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=12028937733464-git-send-email-htejun@gmail.com \
    --to=htejun@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=daniel.ritz-ml@swissonline.ch \
    --cc=jeff@garzik.org \
    --cc=jengelh@computergmbh.de \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=randy.dunlap@oracle.com \
    --subject='Re: [PATCH 1/5] printk: keep log level on multiline messages' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).