netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: leitao@debian.org
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: sergey.senozhatsky@gmail.com, pmladek@suse.com, tj@kernel.or,
	Breno Leitao <leitao@debian.org>,
	Dave Jones <davej@codemonkey.org.uk>,
	netdev@vger.kernel.org (open list:NETWORKING DRIVERS),
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] netconsole: Append kernel version to message
Date: Mon,  3 Jul 2023 08:41:54 -0700	[thread overview]
Message-ID: <20230703154155.3460313-1-leitao@debian.org> (raw)

From: Breno Leitao <leitao@debian.org>

Create a new netconsole Kconfig option that prepends the kernel version in
the netconsole message. This is useful to map kernel messages to kernel
version in a simple way, i.e., without checking somewhere which kernel
version the host that sent the message is using.

If this option is selected, then the "<uname>;" is prepended before the
netconsole message. This is an example of a netcons output, with this
feature enabled:

	6.4.0-01762-ga1ba2ffe946e;12,426,112883998,-;this is a test

Calvin Owens send a RFC about this problem in 2016[1], but his
approach was a bit more intrusive, changing the printk subsystem. This
approach is lighter, and just append the information in the last mile,
just before netconsole push the message to netpoll.

[1] Link: https://lore.kernel.org/all/51047c0f6e86abcb9ee13f60653b6946f8fcfc99.1463172791.git.calvinowens@fb.com/

Signed-off-by: Breno Leitao <leitao@debian.org>
Cc: Dave Jones <davej@codemonkey.org.uk>
---
 drivers/net/Kconfig      | 10 ++++++++++
 drivers/net/netconsole.c | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index d0a1ed216d15..df50fdb6c794 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -332,6 +332,16 @@ config NETCONSOLE_DYNAMIC
 	  at runtime through a userspace interface exported using configfs.
 	  See <file:Documentation/networking/netconsole.rst> for details.
 
+config NETCONSOLE_UNAME
+	bool "Add the kernel version to netconsole lines"
+	depends on NETCONSOLE
+	default n
+	help
+	  This option causes extended netcons messages to be prepended with
+	  kernel uname version. This can be useful for monitoring a large
+	  deployment of servers, so, you can easily map outputs to kernel
+	  versions.
+
 config NETPOLL
 	def_bool NETCONSOLE
 
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 4f4f79532c6c..7edc5b033e14 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -36,6 +36,7 @@
 #include <linux/inet.h>
 #include <linux/configfs.h>
 #include <linux/etherdevice.h>
+#include <linux/utsname.h>
 
 MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
 MODULE_DESCRIPTION("Console driver for network interfaces");
@@ -815,6 +816,38 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
 	}
 }
 
+#ifdef CONFIG_NETCONSOLE_UNAME
+static void send_ext_msg_udp_uname(struct netconsole_target *nt,
+				   const char *msg, unsigned int len)
+{
+	unsigned int newlen;
+	char *newmsg;
+	char *uname;
+
+	uname = init_utsname()->release;
+
+	newmsg = kasprintf(GFP_KERNEL, "%s;%s", uname, msg);
+	if (!newmsg)
+		/* In case of ENOMEM, just ignore this entry */
+		return;
+	newlen = strlen(uname) + len + 1;
+
+	send_ext_msg_udp(nt, newmsg, newlen);
+
+	kfree(newmsg);
+}
+#endif
+
+static inline void send_msg_udp(struct netconsole_target *nt,
+				const char *msg, unsigned int len)
+{
+#ifdef CONFIG_NETCONSOLE_UNAME
+	send_ext_msg_udp_uname(nt, msg, len);
+#else
+	send_ext_msg_udp(nt, msg, len);
+#endif
+}
+
 static void write_ext_msg(struct console *con, const char *msg,
 			  unsigned int len)
 {
@@ -827,7 +860,7 @@ static void write_ext_msg(struct console *con, const char *msg,
 	spin_lock_irqsave(&target_list_lock, flags);
 	list_for_each_entry(nt, &target_list, list)
 		if (nt->extended && nt->enabled && netif_running(nt->np.dev))
-			send_ext_msg_udp(nt, msg, len);
+			send_msg_udp(nt, msg, len);
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }
 
-- 
2.34.1


             reply	other threads:[~2023-07-03 15:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-03 15:41 leitao [this message]
2023-07-03 16:46 ` [PATCH] netconsole: Append kernel version to message Andrew Lunn
2023-07-04 15:53   ` Breno Leitao
2023-07-03 18:34 ` Stephen Hemminger
2023-07-04 15:15   ` Breno Leitao
2023-07-04 15:58     ` Stephen Hemminger
2023-07-05  9:18       ` Breno Leitao
2023-07-05 15:26         ` Stephen Hemminger
2023-07-05 15:49           ` Jakub Kicinski
2023-07-03 19:44 ` Jakub Kicinski
2023-07-04 15:47   ` Breno Leitao
2023-07-05 15:56     ` Jakub Kicinski

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=20230703154155.3460313-1-leitao@debian.org \
    --to=leitao@debian.org \
    --cc=davej@codemonkey.org.uk \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tj@kernel.or \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).