Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1400972

[RFC][PATCH] printk: Add option to append kernel version to the dict

From Calvin Owens <calvinowens@fb.com>
Newsgroups linux.kernel
Subject [RFC][PATCH] printk: Add option to append kernel version to the dict
Date 2016-05-13 23:00 +0200
Message-ID <ryslH-2vK-3@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


We use netconsole to collect kernel logs from all the servers at
Facebook. We use this patch internally so each logline has a record of
which kernel version emitted it.

At first glance, this might seem lazy: as you would expect, we have a
database which records which kernel version a host is currently running.
But there are a lot of situations where that database cannot be current:
early-ish boot crashes are probably the best example, but even beyond
that there are lots of varieties of kernel brokenness that can prevent
the database from being updated. Doing it explicitly this way ensures
that we always know exactly what version emitted a given message.

Doing it in printk() itself rather than extended netconsole ends up
being much simpler, and has the advantage that future extended console
implementations will be able to benefit from this as well.

Signed-off-by: Calvin Owens <calvinowens@fb.com>
---
 init/Kconfig           |  8 ++++++++
 kernel/printk/printk.c | 14 ++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/init/Kconfig b/init/Kconfig
index 0dfd09d..f800256 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -1454,6 +1454,14 @@ config PRINTK
 	  very difficult to diagnose system problems, saying N here is
 	  strongly discouraged.
 
+config PRINTK_APPEND_UNAME
+	default n
+	bool "Append the kernel version to the printk() dict" if EXPERT
+	help
+	  This option causes the printk() implementation to append the kernel
+	  version for extended console messages. This can be very useful for
+	  monitoring a large deployment of servers with extended netconsole.
+
 config BUG
 	bool "BUG() support" if EXPERT
 	default y
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index bfbf284..3f8debd 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -608,6 +608,18 @@ static ssize_t msg_print_ext_body(char *buf, size_t size,
 	return p - buf;
 }
 
+#if defined(CONFIG_PRINTK_APPEND_UNAME)
+static ssize_t msg_print_ext_uname(char *buf, size_t size)
+{
+	return scnprintf(buf, size, " UNAME=%s\n", init_utsname()->release);
+}
+#else
+static ssize_t msg_print_ext_uname(char *buf, size_t size)
+{
+	return 0;
+}
+#endif
+
 /* /dev/kmsg - userspace message inject/listen interface */
 struct devkmsg_user {
 	u64 seq;
@@ -2305,6 +2317,8 @@ skip:
 						sizeof(ext_text) - ext_len,
 						log_dict(msg), msg->dict_len,
 						log_text(msg), msg->text_len);
+			ext_len += msg_print_ext_uname(ext_text + ext_len,
+						sizeof(ext_text) - ext_len);
 		}
 		console_idx = log_next(console_idx);
 		console_seq++;
-- 
2.8.0.rc2

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[RFC][PATCH] printk: Add option to append kernel version to the dict Calvin Owens <calvinowens@fb.com> - 2016-05-13 23:00 +0200
  Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-05-16 04:10 +0200
    Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Calvin Owens <calvinowens@fb.com> - 2016-05-17 00:10 +0200
      Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-05-17 15:50 +0200
        Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Tejun Heo <tj@kernel.org> - 2016-05-17 16:00 +0200
          Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-05-17 16:50 +0200
            Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Tejun Heo <tj@kernel.org> - 2016-05-17 18:10 +0200
  Re: [RFC][PATCH] printk: Add option to append kernel version to the dict Richard Weinberger <richard.weinberger@gmail.com> - 2016-05-16 04:10 +0200
    Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Calvin Owens <calvinowens@fb.com> - 2016-05-16 23:50 +0200
  Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Petr Mladek <pmladek@suse.com> - 2016-05-17 11:30 +0200
    Re: [RFC][PATCH] printk: Add option to append kernel version to the  dict Tejun Heo <tj@kernel.org> - 2016-05-17 12:10 +0200

csiph-web