linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Breno Leitao <leitao@debian.org>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Jonathan Corbet <corbet@lwn.net>,
	sergey.senozhatsky@gmail.com, tj@kernel.org,
	stephen@networkplumber.org, Dave Jones <davej@codemonkey.org.uk>,
	"open list:NETWORKING [GENERAL]" <netdev@vger.kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	open list <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] netconsole: Append kernel version to message
Date: Fri, 14 Jul 2023 13:41:55 +0200	[thread overview]
Message-ID: <ZLE0g9NXYZvlGcyy@alley> (raw)
In-Reply-To: <20230707132911.2033870-1-leitao@debian.org>

On Fri 2023-07-07 06:29:11, Breno Leitao wrote:
> Create a new netconsole runtime 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 "<release>," is prepended before the
> netconsole message. This is an example of a netconsole output, with
> release 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.

Thanks a lot for solving this on the netconsole level. The extended
console format is used also for /dev/kmsg. Which is then used by
systemd journal, dmesg, and maybe other userspace tools. Any format
changes might break these tools.

I have glanced over the patch and have two comments.


> @@ -254,6 +267,11 @@ static ssize_t extended_show(struct config_item *item, char *buf)
>  	return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->extended);
>  }
>  
> +static ssize_t release_show(struct config_item *item, char *buf)
> +{
> +	return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->release);

I have learned recently that sysfs_emit() was preferred over snprintf() in the
_show() callbacks.

> +}
> +
>  static ssize_t dev_name_show(struct config_item *item, char *buf)
>  {
>  	return snprintf(buf, PAGE_SIZE, "%s\n", to_target(item)->np.dev_name);
> @@ -366,6 +389,38 @@ static ssize_t enabled_store(struct config_item *item,
>  	return err;
>  }
>  
> +static ssize_t release_store(struct config_item *item, const char *buf,
> +			     size_t count)
> +{
> +	struct netconsole_target *nt = to_target(item);
> +	int release;
> +	int err;
> +
> +	mutex_lock(&dynamic_netconsole_mutex);
> +	if (nt->enabled) {
> +		pr_err("target (%s) is enabled, disable to update parameters\n",
> +		       config_item_name(&nt->item));
> +		err = -EINVAL;
> +		goto out_unlock;
> +	}
> +
> +	err = kstrtoint(buf, 10, &release);
> +	if (err < 0)
> +		goto out_unlock;
> +	if (release < 0 || release > 1) {
> +		err = -EINVAL;
> +		goto out_unlock;
> +	}

You might consider using:

	bool enabled;

	err = kstrtobool(buf, &enabled);
	if (err)
		goto unlock;


It accepts more input values, for example, 1/0, y/n, Y/N, ...

Well, I see that kstrtoint() is used also in enabled_store().
It might be confusing when "/enabled" supports only "1/0"
and "/release" supports more variants.

> +
> +	nt->release = release;
> +
> +	mutex_unlock(&dynamic_netconsole_mutex);
> +	return strnlen(buf, count);
> +out_unlock:
> +	mutex_unlock(&dynamic_netconsole_mutex);
> +	return err;
> +}
> +

Best Regards,
Petr

  parent reply	other threads:[~2023-07-14 11:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 13:29 [PATCH v2] netconsole: Append kernel version to message Breno Leitao
2023-07-07 23:10 ` Jakub Kicinski
2023-07-10  8:49   ` Breno Leitao
2023-07-14 11:41 ` Petr Mladek [this message]
2023-07-14 13:49   ` Breno Leitao

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=ZLE0g9NXYZvlGcyy@alley \
    --to=pmladek@suse.com \
    --cc=corbet@lwn.net \
    --cc=davej@codemonkey.org.uk \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=stephen@networkplumber.org \
    --cc=tj@kernel.org \
    /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).