[PATCH 3/3] netconsole: New console flag to dump full log buffer

From: Bruno PrÃmont
Date: Tue Dec 23 2014 - 16:37:32 EST


Be default only log messages not yet seen by userspace are output when
enabling netconsole via module parameter (none when enabling dynamic
targets).

When using netconsole to centrally log kernel messages it's of interest
to have the whole kernel log sent over the same medium, even if netconsole
setup happens rather late during system boot. The big advantage of netconsole
over syslog for this task is that it usually allow catching much more
messages when system crashes/panics.

This causes dynamic netconsoles to request full kernel log when first
enabled.

Signed-off-by: Bruno PrÃmont <bonbons@xxxxxxxxxxxxxxxxx>
---
Note, with this kernel is too quick at sending packets for some receiving
machines to catch all of them. Either packets get dropped by the receiving
NIC if can't buffer enough until OS has time to empty the buffers or they
get lost between kernel and userspace socket if backlog is too small.

My test environment was 4core AMD APU with Gbit NIC to Marvell Kirkwood
SheevaPlug with Gbit NIC. About first 100 lines get through, then lines
start getting lost.

drivers/net/netconsole.c | 3 ++-
include/linux/console.h | 1 +
kernel/printk/printk.c | 12 +++++++++---
3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index a96cd8e..241c70f 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -661,7 +661,8 @@ static struct config_item *make_netconsole_target(struct config_group *group,
mutex_init(&nt->mutex);
memset(nt->np.remote_mac, 0xff, ETH_ALEN);
snprintf(nt->console.name, sizeof(nt->console.name), "netcon-%s", name);
- nt->console.flags = CON_ENABLED;
+ /* Dump existing printks when we register */
+ nt->console.flags = CON_ENABLED | CON_PRINTBUFFER | CON_PRINTALL;
nt->console.write = write_msg;
nt->console.loglevel = 0;

diff --git a/include/linux/console.h b/include/linux/console.h
index f3a8996..6f53a54 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -116,6 +116,7 @@ static inline int con_debug_leave(void)
#define CON_ANYTIME (16) /* Safe to call when cpu is offline */
#define CON_BRL (32) /* Used for a braille device */
#define CON_LOGLEVEL (64) /* Per-console log-level filtering */
+#define CON_PRINTALL (128) /* Extends CON_PRINTBUFFER */

struct console {
char name[16];
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 8f09f30..193665d 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2554,9 +2554,15 @@ void register_console(struct console *newcon)
* for us.
*/
raw_spin_lock_irqsave(&logbuf_lock, flags);
- console_seq = syslog_seq;
- console_idx = syslog_idx;
- console_prev = syslog_prev;
+ if (newcon->flags & CON_PRINTALL) {
+ console_seq = log_first_seq;
+ console_idx = log_first_idx;
+ console_prev = LOG_NEWLINE;
+ } else {
+ console_seq = syslog_seq;
+ console_idx = syslog_idx;
+ console_prev = syslog_prev;
+ }
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
/*
* We're about to replay the log buffer. Only do this to the
--
2.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/