* [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target
@ 2023-10-12 11:13 Breno Leitao
2023-10-12 11:13 ` [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower Breno Leitao
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Breno Leitao @ 2023-10-12 11:13 UTC (permalink / raw)
To: jlbec, kuba, davem, pabeni; +Cc: hch, netdev, linux-kernel, horms
There is a limitation in netconsole, where it is impossible to
disable or modify the target created from the command line parameter.
(netconsole=...).
"netconsole" cmdline parameter sets the remote IP, and if the remote IP
changes, the machine needs to be rebooted (with the new remote IP set in
the command line parameter).
This allows the user to modify a target without the need to restart the
machine.
This functionality sits on top of the dynamic target reconfiguration that is
already implemented in netconsole.
The way to modify a boot time target is creating special named configfs
directories, that will be associated with the targets coming from
`netconsole=...`.
Example:
Let's suppose you have two netconsole targets defined at boot time::
netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc;4444@10.0.0.1/eth1,9353@10.0.0.3/12:34:56:78:9a:bc
You can modify these targets in runtime by creating the following targets::
$ mkdir cmdline1
$ cat cmdline1/remote_ip
10.0.0.3
$ echo 0 > cmdline1/enabled
$ echo 10.0.0.4 > cmdline1/remote_ip
$ echo 1 > cmdline1/enabled
==
Changelog:
* Version 4:
* Rename NETCONSOLE_PARAM_TARGET_NAME to NETCONSOLE_PARAM_TARGET_PREFIX
* Version 3:
* Move some functions around to avoid forward declaration
* Version 2:
* Replaced the name of the NETCONSOLE_PARAM_TARGET_NAME macro
* Improved the code documentation
* Improved the user documentation
Breno Leitao (4):
netconsole: move init/cleanup functions lower
netconsole: Initialize configfs_item for default targets
netconsole: Attach cmdline target to dynamic target
Documentation: netconsole: add support for cmdline targets
Documentation/networking/netconsole.rst | 22 +++-
drivers/net/netconsole.c | 155 ++++++++++++++++--------
2 files changed, 121 insertions(+), 56 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower
2023-10-12 11:13 [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target Breno Leitao
@ 2023-10-12 11:13 ` Breno Leitao
2023-10-15 0:54 ` Joel Becker
2023-10-12 11:13 ` [PATCH net-next v4 2/4] netconsole: Initialize configfs_item for default targets Breno Leitao
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Breno Leitao @ 2023-10-12 11:13 UTC (permalink / raw)
To: jlbec, kuba, davem, pabeni, Eric Dumazet; +Cc: hch, netdev, linux-kernel, horms
Move alloc_param_target() and its counterpart (free_param_target())
to the bottom of the file. These functions are called mostly at
initialization/cleanup of the module, and they should be just above the
callers, at the bottom of the file.
From a practical perspective, having alloc_param_target() at the bottom
of the file will avoid forward declaration later (in the following
patch).
Nothing changed other than the functions location.
Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
drivers/net/netconsole.c | 104 +++++++++++++++++++--------------------
1 file changed, 52 insertions(+), 52 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 3111e1648592..d609fb59cf99 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -192,58 +192,6 @@ static struct netconsole_target *alloc_and_init(void)
return nt;
}
-/* Allocate new target (from boot/module param) and setup netpoll for it */
-static struct netconsole_target *alloc_param_target(char *target_config)
-{
- struct netconsole_target *nt;
- int err;
-
- nt = alloc_and_init();
- if (!nt) {
- err = -ENOMEM;
- goto fail;
- }
-
- if (*target_config == '+') {
- nt->extended = true;
- target_config++;
- }
-
- if (*target_config == 'r') {
- if (!nt->extended) {
- pr_err("Netconsole configuration error. Release feature requires extended log message");
- err = -EINVAL;
- goto fail;
- }
- nt->release = true;
- target_config++;
- }
-
- /* Parse parameters and setup netpoll */
- err = netpoll_parse_options(&nt->np, target_config);
- if (err)
- goto fail;
-
- err = netpoll_setup(&nt->np);
- if (err)
- goto fail;
-
- nt->enabled = true;
-
- return nt;
-
-fail:
- kfree(nt);
- return ERR_PTR(err);
-}
-
-/* Cleanup netpoll for given target (from boot/module param) and free it */
-static void free_param_target(struct netconsole_target *nt)
-{
- netpoll_cleanup(&nt->np);
- kfree(nt);
-}
-
#ifdef CONFIG_NETCONSOLE_DYNAMIC
/*
@@ -938,6 +886,58 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
spin_unlock_irqrestore(&target_list_lock, flags);
}
+/* Allocate new target (from boot/module param) and setup netpoll for it */
+static struct netconsole_target *alloc_param_target(char *target_config)
+{
+ struct netconsole_target *nt;
+ int err;
+
+ nt = alloc_and_init();
+ if (!nt) {
+ err = -ENOMEM;
+ goto fail;
+ }
+
+ if (*target_config == '+') {
+ nt->extended = true;
+ target_config++;
+ }
+
+ if (*target_config == 'r') {
+ if (!nt->extended) {
+ pr_err("Netconsole configuration error. Release feature requires extended log message");
+ err = -EINVAL;
+ goto fail;
+ }
+ nt->release = true;
+ target_config++;
+ }
+
+ /* Parse parameters and setup netpoll */
+ err = netpoll_parse_options(&nt->np, target_config);
+ if (err)
+ goto fail;
+
+ err = netpoll_setup(&nt->np);
+ if (err)
+ goto fail;
+
+ nt->enabled = true;
+
+ return nt;
+
+fail:
+ kfree(nt);
+ return ERR_PTR(err);
+}
+
+/* Cleanup netpoll for given target (from boot/module param) and free it */
+static void free_param_target(struct netconsole_target *nt)
+{
+ netpoll_cleanup(&nt->np);
+ kfree(nt);
+}
+
static struct console netconsole_ext = {
.name = "netcon_ext",
.flags = CON_ENABLED | CON_EXTENDED,
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v4 2/4] netconsole: Initialize configfs_item for default targets
2023-10-12 11:13 [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target Breno Leitao
2023-10-12 11:13 ` [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower Breno Leitao
@ 2023-10-12 11:13 ` Breno Leitao
2023-10-15 0:53 ` Joel Becker
2023-10-12 11:14 ` [PATCH net-next v4 3/4] netconsole: Attach cmdline target to dynamic target Breno Leitao
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Breno Leitao @ 2023-10-12 11:13 UTC (permalink / raw)
To: jlbec, kuba, davem, pabeni, Eric Dumazet; +Cc: hch, netdev, linux-kernel, horms
For netconsole targets allocated during the boot time (passing
netconsole=... argument), netconsole_target->item is not initialized.
That is not a problem because it is not used inside configfs.
An upcoming patch will be using it, thus, initialize the targets with
the name 'cmdline' plus a counter starting from 0. This name will match
entries in the configfs later.
Suggested-by: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
drivers/net/netconsole.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index d609fb59cf99..e153bce4dee4 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -53,6 +53,8 @@ static bool oops_only = false;
module_param(oops_only, bool, 0600);
MODULE_PARM_DESC(oops_only, "Only log oops messages");
+#define NETCONSOLE_PARAM_TARGET_PREFIX "cmdline"
+
#ifndef MODULE
static int __init option_setup(char *opt)
{
@@ -165,6 +167,10 @@ static void netconsole_target_put(struct netconsole_target *nt)
{
}
+static void populate_configfs_item(struct netconsole_target *nt,
+ int cmdline_count)
+{
+}
#endif /* CONFIG_NETCONSOLE_DYNAMIC */
/* Allocate and initialize with defaults.
@@ -688,6 +694,17 @@ static struct configfs_subsystem netconsole_subsys = {
},
};
+static void populate_configfs_item(struct netconsole_target *nt,
+ int cmdline_count)
+{
+ char target_name[16];
+
+ snprintf(target_name, sizeof(target_name), "%s%d",
+ NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count);
+ config_item_init_type_name(&nt->item, target_name,
+ &netconsole_target_type);
+}
+
#endif /* CONFIG_NETCONSOLE_DYNAMIC */
/* Handle network interface device notifications */
@@ -887,7 +904,8 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
}
/* Allocate new target (from boot/module param) and setup netpoll for it */
-static struct netconsole_target *alloc_param_target(char *target_config)
+static struct netconsole_target *alloc_param_target(char *target_config,
+ int cmdline_count)
{
struct netconsole_target *nt;
int err;
@@ -922,6 +940,7 @@ static struct netconsole_target *alloc_param_target(char *target_config)
if (err)
goto fail;
+ populate_configfs_item(nt, cmdline_count);
nt->enabled = true;
return nt;
@@ -954,6 +973,7 @@ static int __init init_netconsole(void)
{
int err;
struct netconsole_target *nt, *tmp;
+ unsigned int count = 0;
bool extended = false;
unsigned long flags;
char *target_config;
@@ -961,7 +981,7 @@ static int __init init_netconsole(void)
if (strnlen(input, MAX_PARAM_LENGTH)) {
while ((target_config = strsep(&input, ";"))) {
- nt = alloc_param_target(target_config);
+ nt = alloc_param_target(target_config, count);
if (IS_ERR(nt)) {
err = PTR_ERR(nt);
goto fail;
@@ -977,6 +997,7 @@ static int __init init_netconsole(void)
spin_lock_irqsave(&target_list_lock, flags);
list_add(&nt->list, &target_list);
spin_unlock_irqrestore(&target_list_lock, flags);
+ count++;
}
}
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v4 3/4] netconsole: Attach cmdline target to dynamic target
2023-10-12 11:13 [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target Breno Leitao
2023-10-12 11:13 ` [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower Breno Leitao
2023-10-12 11:13 ` [PATCH net-next v4 2/4] netconsole: Initialize configfs_item for default targets Breno Leitao
@ 2023-10-12 11:14 ` Breno Leitao
2023-10-15 0:55 ` Joel Becker
2023-10-12 11:14 ` [PATCH net-next v4 4/4] Documentation: netconsole: add support for cmdline targets Breno Leitao
2023-10-14 0:30 ` [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target patchwork-bot+netdevbpf
4 siblings, 1 reply; 10+ messages in thread
From: Breno Leitao @ 2023-10-12 11:14 UTC (permalink / raw)
To: jlbec, kuba, davem, pabeni, Eric Dumazet; +Cc: hch, netdev, linux-kernel, horms
Enable the attachment of a dynamic target to the target created during
boot time. The boot-time targets are named as "cmdline\d", where "\d" is
a number starting at 0.
If the user creates a dynamic target named "cmdline0", it will attach to
the first target created at boot time (as defined in the
`netconsole=...` command line argument). `cmdline1` will attach to the
second target and so forth.
If there is no netconsole target created at boot time, then, the target
name could be reused.
Relevant design discussion:
https://lore.kernel.org/all/ZRWRal5bW93px4km@gmail.com/
Suggested-by: Joel Becker <jlbec@evilplan.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
drivers/net/netconsole.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index e153bce4dee4..6e14ba5e06c8 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -629,6 +629,23 @@ static const struct config_item_type netconsole_target_type = {
.ct_owner = THIS_MODULE,
};
+static struct netconsole_target *find_cmdline_target(const char *name)
+{
+ struct netconsole_target *nt, *ret = NULL;
+ unsigned long flags;
+
+ spin_lock_irqsave(&target_list_lock, flags);
+ list_for_each_entry(nt, &target_list, list) {
+ if (!strcmp(nt->item.ci_name, name)) {
+ ret = nt;
+ break;
+ }
+ }
+ spin_unlock_irqrestore(&target_list_lock, flags);
+
+ return ret;
+}
+
/*
* Group operations and type for netconsole_subsys.
*/
@@ -639,6 +656,17 @@ static struct config_item *make_netconsole_target(struct config_group *group,
struct netconsole_target *nt;
unsigned long flags;
+ /* Checking if a target by this name was created at boot time. If so,
+ * attach a configfs entry to that target. This enables dynamic
+ * control.
+ */
+ if (!strncmp(name, NETCONSOLE_PARAM_TARGET_PREFIX,
+ strlen(NETCONSOLE_PARAM_TARGET_PREFIX))) {
+ nt = find_cmdline_target(name);
+ if (nt)
+ return &nt->item;
+ }
+
nt = alloc_and_init();
if (!nt)
return ERR_PTR(-ENOMEM);
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH net-next v4 4/4] Documentation: netconsole: add support for cmdline targets
2023-10-12 11:13 [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target Breno Leitao
` (2 preceding siblings ...)
2023-10-12 11:14 ` [PATCH net-next v4 3/4] netconsole: Attach cmdline target to dynamic target Breno Leitao
@ 2023-10-12 11:14 ` Breno Leitao
2023-10-15 0:55 ` Joel Becker
2023-10-14 0:30 ` [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target patchwork-bot+netdevbpf
4 siblings, 1 reply; 10+ messages in thread
From: Breno Leitao @ 2023-10-12 11:14 UTC (permalink / raw)
To: jlbec, kuba, davem, pabeni, Eric Dumazet, Jonathan Corbet
Cc: hch, netdev, linux-kernel, horms, open list:DOCUMENTATION
With the previous patches, there is no more limitation at modifying the
targets created at boot time (or module load time).
Document the way on how to create the configfs directories to be able to
modify these netconsole targets.
The design discussion about this topic could be found at:
https://lore.kernel.org/all/ZRWRal5bW93px4km@gmail.com/
Signed-off-by: Breno Leitao <leitao@debian.org>
---
Documentation/networking/netconsole.rst | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/Documentation/networking/netconsole.rst b/Documentation/networking/netconsole.rst
index 7a9de0568e84..390730a74332 100644
--- a/Documentation/networking/netconsole.rst
+++ b/Documentation/networking/netconsole.rst
@@ -99,9 +99,6 @@ Dynamic reconfiguration:
Dynamic reconfigurability is a useful addition to netconsole that enables
remote logging targets to be dynamically added, removed, or have their
parameters reconfigured at runtime from a configfs-based userspace interface.
-[ Note that the parameters of netconsole targets that were specified/created
-from the boot/module option are not exposed via this interface, and hence
-cannot be modified dynamically. ]
To include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
netconsole module (or kernel, if netconsole is built-in).
@@ -155,6 +152,25 @@ You can also update the local interface dynamically. This is especially
useful if you want to use interfaces that have newly come up (and may not
have existed when netconsole was loaded / initialized).
+Netconsole targets defined at boot time (or module load time) with the
+`netconsole=` param are assigned the name `cmdline<index>`. For example, the
+first target in the parameter is named `cmdline0`. You can control and modify
+these targets by creating configfs directories with the matching name.
+
+Let's suppose you have two netconsole targets defined at boot time::
+
+ netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc;4444@10.0.0.1/eth1,9353@10.0.0.3/12:34:56:78:9a:bc
+
+You can modify these targets in runtime by creating the following targets::
+
+ mkdir cmdline0
+ cat cmdline0/remote_ip
+ 10.0.0.2
+
+ mkdir cmdline1
+ cat cmdline1/remote_ip
+ 10.0.0.3
+
Extended console:
=================
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target
2023-10-12 11:13 [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target Breno Leitao
` (3 preceding siblings ...)
2023-10-12 11:14 ` [PATCH net-next v4 4/4] Documentation: netconsole: add support for cmdline targets Breno Leitao
@ 2023-10-14 0:30 ` patchwork-bot+netdevbpf
4 siblings, 0 replies; 10+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-14 0:30 UTC (permalink / raw)
To: Breno Leitao; +Cc: jlbec, kuba, davem, pabeni, hch, netdev, linux-kernel, horms
Hello:
This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 12 Oct 2023 04:13:57 -0700 you wrote:
> There is a limitation in netconsole, where it is impossible to
> disable or modify the target created from the command line parameter.
> (netconsole=...).
>
> "netconsole" cmdline parameter sets the remote IP, and if the remote IP
> changes, the machine needs to be rebooted (with the new remote IP set in
> the command line parameter).
>
> [...]
Here is the summary with links:
- [net-next,v4,1/4] netconsole: move init/cleanup functions lower
https://git.kernel.org/netdev/net-next/c/28856ab2c0b5
- [net-next,v4,2/4] netconsole: Initialize configfs_item for default targets
https://git.kernel.org/netdev/net-next/c/131eeb45b961
- [net-next,v4,3/4] netconsole: Attach cmdline target to dynamic target
https://git.kernel.org/netdev/net-next/c/5fbd6cdbe304
- [net-next,v4,4/4] Documentation: netconsole: add support for cmdline targets
https://git.kernel.org/netdev/net-next/c/7eeb84d89f2e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v4 2/4] netconsole: Initialize configfs_item for default targets
2023-10-12 11:13 ` [PATCH net-next v4 2/4] netconsole: Initialize configfs_item for default targets Breno Leitao
@ 2023-10-15 0:53 ` Joel Becker
0 siblings, 0 replies; 10+ messages in thread
From: Joel Becker @ 2023-10-15 0:53 UTC (permalink / raw)
To: Breno Leitao
Cc: kuba, davem, pabeni, Eric Dumazet, hch, netdev, linux-kernel,
horms
On Thu, Oct 12, 2023 at 04:13:59AM -0700, Breno Leitao wrote:
> For netconsole targets allocated during the boot time (passing
> netconsole=... argument), netconsole_target->item is not initialized.
> That is not a problem because it is not used inside configfs.
>
> An upcoming patch will be using it, thus, initialize the targets with
> the name 'cmdline' plus a counter starting from 0. This name will match
> entries in the configfs later.
>
> Suggested-by: Joel Becker <jlbec@evilplan.org>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Joel Becker <jlbec@evilplan.org>
> ---
> drivers/net/netconsole.c | 25 +++++++++++++++++++++++--
> 1 file changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index d609fb59cf99..e153bce4dee4 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -53,6 +53,8 @@ static bool oops_only = false;
> module_param(oops_only, bool, 0600);
> MODULE_PARM_DESC(oops_only, "Only log oops messages");
>
> +#define NETCONSOLE_PARAM_TARGET_PREFIX "cmdline"
> +
> #ifndef MODULE
> static int __init option_setup(char *opt)
> {
> @@ -165,6 +167,10 @@ static void netconsole_target_put(struct netconsole_target *nt)
> {
> }
>
> +static void populate_configfs_item(struct netconsole_target *nt,
> + int cmdline_count)
> +{
> +}
> #endif /* CONFIG_NETCONSOLE_DYNAMIC */
>
> /* Allocate and initialize with defaults.
> @@ -688,6 +694,17 @@ static struct configfs_subsystem netconsole_subsys = {
> },
> };
>
> +static void populate_configfs_item(struct netconsole_target *nt,
> + int cmdline_count)
> +{
> + char target_name[16];
> +
> + snprintf(target_name, sizeof(target_name), "%s%d",
> + NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count);
> + config_item_init_type_name(&nt->item, target_name,
> + &netconsole_target_type);
> +}
> +
> #endif /* CONFIG_NETCONSOLE_DYNAMIC */
>
> /* Handle network interface device notifications */
> @@ -887,7 +904,8 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
> }
>
> /* Allocate new target (from boot/module param) and setup netpoll for it */
> -static struct netconsole_target *alloc_param_target(char *target_config)
> +static struct netconsole_target *alloc_param_target(char *target_config,
> + int cmdline_count)
> {
> struct netconsole_target *nt;
> int err;
> @@ -922,6 +940,7 @@ static struct netconsole_target *alloc_param_target(char *target_config)
> if (err)
> goto fail;
>
> + populate_configfs_item(nt, cmdline_count);
> nt->enabled = true;
>
> return nt;
> @@ -954,6 +973,7 @@ static int __init init_netconsole(void)
> {
> int err;
> struct netconsole_target *nt, *tmp;
> + unsigned int count = 0;
> bool extended = false;
> unsigned long flags;
> char *target_config;
> @@ -961,7 +981,7 @@ static int __init init_netconsole(void)
>
> if (strnlen(input, MAX_PARAM_LENGTH)) {
> while ((target_config = strsep(&input, ";"))) {
> - nt = alloc_param_target(target_config);
> + nt = alloc_param_target(target_config, count);
> if (IS_ERR(nt)) {
> err = PTR_ERR(nt);
> goto fail;
> @@ -977,6 +997,7 @@ static int __init init_netconsole(void)
> spin_lock_irqsave(&target_list_lock, flags);
> list_add(&nt->list, &target_list);
> spin_unlock_irqrestore(&target_list_lock, flags);
> + count++;
> }
> }
>
> --
> 2.34.1
>
--
"I don't want to achieve immortality through my work; I want to
achieve immortality through not dying."
- Woody Allen
http://www.jlbec.org/
jlbec@evilplan.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower
2023-10-12 11:13 ` [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower Breno Leitao
@ 2023-10-15 0:54 ` Joel Becker
0 siblings, 0 replies; 10+ messages in thread
From: Joel Becker @ 2023-10-15 0:54 UTC (permalink / raw)
To: Breno Leitao
Cc: kuba, davem, pabeni, Eric Dumazet, hch, netdev, linux-kernel,
horms
On Thu, Oct 12, 2023 at 04:13:58AM -0700, Breno Leitao wrote:
> Move alloc_param_target() and its counterpart (free_param_target())
> to the bottom of the file. These functions are called mostly at
> initialization/cleanup of the module, and they should be just above the
> callers, at the bottom of the file.
>
> >From a practical perspective, having alloc_param_target() at the bottom
> of the file will avoid forward declaration later (in the following
> patch).
>
> Nothing changed other than the functions location.
>
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Joel Becker <jlbec@evilplan.org>
> ---
> drivers/net/netconsole.c | 104 +++++++++++++++++++--------------------
> 1 file changed, 52 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index 3111e1648592..d609fb59cf99 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -192,58 +192,6 @@ static struct netconsole_target *alloc_and_init(void)
> return nt;
> }
>
> -/* Allocate new target (from boot/module param) and setup netpoll for it */
> -static struct netconsole_target *alloc_param_target(char *target_config)
> -{
> - struct netconsole_target *nt;
> - int err;
> -
> - nt = alloc_and_init();
> - if (!nt) {
> - err = -ENOMEM;
> - goto fail;
> - }
> -
> - if (*target_config == '+') {
> - nt->extended = true;
> - target_config++;
> - }
> -
> - if (*target_config == 'r') {
> - if (!nt->extended) {
> - pr_err("Netconsole configuration error. Release feature requires extended log message");
> - err = -EINVAL;
> - goto fail;
> - }
> - nt->release = true;
> - target_config++;
> - }
> -
> - /* Parse parameters and setup netpoll */
> - err = netpoll_parse_options(&nt->np, target_config);
> - if (err)
> - goto fail;
> -
> - err = netpoll_setup(&nt->np);
> - if (err)
> - goto fail;
> -
> - nt->enabled = true;
> -
> - return nt;
> -
> -fail:
> - kfree(nt);
> - return ERR_PTR(err);
> -}
> -
> -/* Cleanup netpoll for given target (from boot/module param) and free it */
> -static void free_param_target(struct netconsole_target *nt)
> -{
> - netpoll_cleanup(&nt->np);
> - kfree(nt);
> -}
> -
> #ifdef CONFIG_NETCONSOLE_DYNAMIC
>
> /*
> @@ -938,6 +886,58 @@ static void write_msg(struct console *con, const char *msg, unsigned int len)
> spin_unlock_irqrestore(&target_list_lock, flags);
> }
>
> +/* Allocate new target (from boot/module param) and setup netpoll for it */
> +static struct netconsole_target *alloc_param_target(char *target_config)
> +{
> + struct netconsole_target *nt;
> + int err;
> +
> + nt = alloc_and_init();
> + if (!nt) {
> + err = -ENOMEM;
> + goto fail;
> + }
> +
> + if (*target_config == '+') {
> + nt->extended = true;
> + target_config++;
> + }
> +
> + if (*target_config == 'r') {
> + if (!nt->extended) {
> + pr_err("Netconsole configuration error. Release feature requires extended log message");
> + err = -EINVAL;
> + goto fail;
> + }
> + nt->release = true;
> + target_config++;
> + }
> +
> + /* Parse parameters and setup netpoll */
> + err = netpoll_parse_options(&nt->np, target_config);
> + if (err)
> + goto fail;
> +
> + err = netpoll_setup(&nt->np);
> + if (err)
> + goto fail;
> +
> + nt->enabled = true;
> +
> + return nt;
> +
> +fail:
> + kfree(nt);
> + return ERR_PTR(err);
> +}
> +
> +/* Cleanup netpoll for given target (from boot/module param) and free it */
> +static void free_param_target(struct netconsole_target *nt)
> +{
> + netpoll_cleanup(&nt->np);
> + kfree(nt);
> +}
> +
> static struct console netconsole_ext = {
> .name = "netcon_ext",
> .flags = CON_ENABLED | CON_EXTENDED,
> --
> 2.34.1
>
--
"There is shadow under this red rock.
(Come in under the shadow of this red rock)
And I will show you something different from either
Your shadow at morning striding behind you
Or your shadow at evening rising to meet you.
I will show you fear in a handful of dust."
http://www.jlbec.org/
jlbec@evilplan.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v4 3/4] netconsole: Attach cmdline target to dynamic target
2023-10-12 11:14 ` [PATCH net-next v4 3/4] netconsole: Attach cmdline target to dynamic target Breno Leitao
@ 2023-10-15 0:55 ` Joel Becker
0 siblings, 0 replies; 10+ messages in thread
From: Joel Becker @ 2023-10-15 0:55 UTC (permalink / raw)
To: Breno Leitao
Cc: kuba, davem, pabeni, Eric Dumazet, hch, netdev, linux-kernel,
horms
On Thu, Oct 12, 2023 at 04:14:00AM -0700, Breno Leitao wrote:
> Enable the attachment of a dynamic target to the target created during
> boot time. The boot-time targets are named as "cmdline\d", where "\d" is
> a number starting at 0.
>
> If the user creates a dynamic target named "cmdline0", it will attach to
> the first target created at boot time (as defined in the
> `netconsole=...` command line argument). `cmdline1` will attach to the
> second target and so forth.
>
> If there is no netconsole target created at boot time, then, the target
> name could be reused.
>
> Relevant design discussion:
> https://lore.kernel.org/all/ZRWRal5bW93px4km@gmail.com/
>
> Suggested-by: Joel Becker <jlbec@evilplan.org>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Joel Becker <jlbec@evilplan.org>
> ---
> drivers/net/netconsole.c | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
> index e153bce4dee4..6e14ba5e06c8 100644
> --- a/drivers/net/netconsole.c
> +++ b/drivers/net/netconsole.c
> @@ -629,6 +629,23 @@ static const struct config_item_type netconsole_target_type = {
> .ct_owner = THIS_MODULE,
> };
>
> +static struct netconsole_target *find_cmdline_target(const char *name)
> +{
> + struct netconsole_target *nt, *ret = NULL;
> + unsigned long flags;
> +
> + spin_lock_irqsave(&target_list_lock, flags);
> + list_for_each_entry(nt, &target_list, list) {
> + if (!strcmp(nt->item.ci_name, name)) {
> + ret = nt;
> + break;
> + }
> + }
> + spin_unlock_irqrestore(&target_list_lock, flags);
> +
> + return ret;
> +}
> +
> /*
> * Group operations and type for netconsole_subsys.
> */
> @@ -639,6 +656,17 @@ static struct config_item *make_netconsole_target(struct config_group *group,
> struct netconsole_target *nt;
> unsigned long flags;
>
> + /* Checking if a target by this name was created at boot time. If so,
> + * attach a configfs entry to that target. This enables dynamic
> + * control.
> + */
> + if (!strncmp(name, NETCONSOLE_PARAM_TARGET_PREFIX,
> + strlen(NETCONSOLE_PARAM_TARGET_PREFIX))) {
> + nt = find_cmdline_target(name);
> + if (nt)
> + return &nt->item;
> + }
> +
> nt = alloc_and_init();
> if (!nt)
> return ERR_PTR(-ENOMEM);
> --
> 2.34.1
>
--
"Nobody loves me,
Nobody seems to care.
Troubles and worries, people,
You know I've had my share."
http://www.jlbec.org/
jlbec@evilplan.org
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next v4 4/4] Documentation: netconsole: add support for cmdline targets
2023-10-12 11:14 ` [PATCH net-next v4 4/4] Documentation: netconsole: add support for cmdline targets Breno Leitao
@ 2023-10-15 0:55 ` Joel Becker
0 siblings, 0 replies; 10+ messages in thread
From: Joel Becker @ 2023-10-15 0:55 UTC (permalink / raw)
To: Breno Leitao
Cc: kuba, davem, pabeni, Eric Dumazet, Jonathan Corbet, hch, netdev,
linux-kernel, horms, open list:DOCUMENTATION
On Thu, Oct 12, 2023 at 04:14:01AM -0700, Breno Leitao wrote:
> With the previous patches, there is no more limitation at modifying the
> targets created at boot time (or module load time).
>
> Document the way on how to create the configfs directories to be able to
> modify these netconsole targets.
>
> The design discussion about this topic could be found at:
> https://lore.kernel.org/all/ZRWRal5bW93px4km@gmail.com/
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
Reviewed-by: Joel Becker <jlbec@evilplan.org>
> ---
> Documentation/networking/netconsole.rst | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/Documentation/networking/netconsole.rst b/Documentation/networking/netconsole.rst
> index 7a9de0568e84..390730a74332 100644
> --- a/Documentation/networking/netconsole.rst
> +++ b/Documentation/networking/netconsole.rst
> @@ -99,9 +99,6 @@ Dynamic reconfiguration:
> Dynamic reconfigurability is a useful addition to netconsole that enables
> remote logging targets to be dynamically added, removed, or have their
> parameters reconfigured at runtime from a configfs-based userspace interface.
> -[ Note that the parameters of netconsole targets that were specified/created
> -from the boot/module option are not exposed via this interface, and hence
> -cannot be modified dynamically. ]
>
> To include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
> netconsole module (or kernel, if netconsole is built-in).
> @@ -155,6 +152,25 @@ You can also update the local interface dynamically. This is especially
> useful if you want to use interfaces that have newly come up (and may not
> have existed when netconsole was loaded / initialized).
>
> +Netconsole targets defined at boot time (or module load time) with the
> +`netconsole=` param are assigned the name `cmdline<index>`. For example, the
> +first target in the parameter is named `cmdline0`. You can control and modify
> +these targets by creating configfs directories with the matching name.
> +
> +Let's suppose you have two netconsole targets defined at boot time::
> +
> + netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc;4444@10.0.0.1/eth1,9353@10.0.0.3/12:34:56:78:9a:bc
> +
> +You can modify these targets in runtime by creating the following targets::
> +
> + mkdir cmdline0
> + cat cmdline0/remote_ip
> + 10.0.0.2
> +
> + mkdir cmdline1
> + cat cmdline1/remote_ip
> + 10.0.0.3
> +
> Extended console:
> =================
>
> --
> 2.34.1
>
--
f/8 and be there.
http://www.jlbec.org/
jlbec@evilplan.org
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-10-15 0:55 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-12 11:13 [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target Breno Leitao
2023-10-12 11:13 ` [PATCH net-next v4 1/4] netconsole: move init/cleanup functions lower Breno Leitao
2023-10-15 0:54 ` Joel Becker
2023-10-12 11:13 ` [PATCH net-next v4 2/4] netconsole: Initialize configfs_item for default targets Breno Leitao
2023-10-15 0:53 ` Joel Becker
2023-10-12 11:14 ` [PATCH net-next v4 3/4] netconsole: Attach cmdline target to dynamic target Breno Leitao
2023-10-15 0:55 ` Joel Becker
2023-10-12 11:14 ` [PATCH net-next v4 4/4] Documentation: netconsole: add support for cmdline targets Breno Leitao
2023-10-15 0:55 ` Joel Becker
2023-10-14 0:30 ` [PATCH net-next v4 0/4] net: netconsole: configfs entries for boot target patchwork-bot+netdevbpf
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).