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

On Tue, 4 Jul 2023 08:47:23 -0700 Breno Leitao wrote:
> This is the code that does it. How does it sound?

More or less :)

> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 4f4f79532c6c..d26bd3b785c4 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");
> @@ -772,8 +773,10 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
>  	const char *header, *body;
>  	int offset = 0;
>  	int header_len, body_len;
> +	int uname_len = 0;

I'd calculate the uname_len here if the option was set.

> -	if (msg_len <= MAX_PRINT_CHUNK) {
> +	if (msg_len <= MAX_PRINT_CHUNK &&
> +	    !IS_ENABLED(CONFIG_NETCONSOLE_UNAME)) {

And then try to fold the path with uname into this. So that we don't
have to separate exit points for the "message is short enough".

>  		netpoll_send_udp(&nt->np, msg, msg_len);
>  		return;
>  	}
> @@ -788,14 +791,31 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
>  	body_len = msg_len - header_len - 1;
>  	body++;
>  
> +	if (IS_ENABLED(CONFIG_NETCONSOLE_UNAME)) {
> +		/* Add uname at the beginning of buffer */
> +		char *uname = init_utsname()->release;

nit: const

> +		/* uname_len contains the length of uname + ',' */
> +		uname_len = strlen(uname) + 1;
> +
> +		if (uname_len + msg_len < MAX_PRINT_CHUNK) {
> +			/* No fragmentation needed */
> +			scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", uname, msg);
> +			netpoll_send_udp(&nt->np, buf, uname_len + msg_len);
> +			return;
> +		}
> +
> +		/* The data will be fragment, prepending uname */
> +		scnprintf(buf, MAX_PRINT_CHUNK, "%s,", uname);
> +	}
> +
>  	/*
>  	 * Transfer multiple chunks with the following extra header.
>  	 * "ncfrag=<byte-offset>/<total-bytes>"
>  	 */
> -	memcpy(buf, header, header_len);
> +	memcpy(buf + uname_len, header, header_len);

And once done prepping I'd add uname_len to header_len

>  	while (offset < body_len) {
> -		int this_header = header_len;
> +		int this_header = header_len + uname_len;

Last but not least, I do agree with Stephen that this can be
configurable with sysfs at runtime, no need to make it a Kconfig.

      reply	other threads:[~2023-07-05 15:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-03 15:41 [PATCH] netconsole: Append kernel version to message leitao
2023-07-03 16:46 ` 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 [this message]

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=20230705085640.46ad5c2e@kernel.org \
    --to=kuba@kernel.org \
    --cc=davej@codemonkey.org.uk \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=leitao@debian.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).