[PATCH RFC 2/2] netconsole: add configfs trigger to replay printk buffer
From: Sam Crossley
Date: Sat Oct 24 2026 - 19:08:16 EST
Netconsole only forwards records while an enabled target and its transport
are available, so enabling a target after startup, or recovering from an
outage, leaves a gap in the remote log.
Add a write-only replay attribute at /sys/kernel/config/netconsole.
Writing 1 rewinds the basic and extended netconsole consoles to the oldest
retained record and queues the records for transmission. Other registered
consoles are unaffected. Records keep their original printk timestamp and,
in extended format, their sequence number, so a receiver can deduplicate
what it already had.
Replay is best effort and asynchronous.
Note that "replay" is now an attribute in the netconsole configfs
directory, so it can no longer be used as a target name.
Signed-off-by: Sam Crossley <samuelcrossley@xxxxxxxxx>
---
Documentation/networking/netconsole.rst | 14 +++++++++++++-
drivers/net/netconsole.c | 25 +++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/Documentation/networking/netconsole.rst b/Documentation/networking/netconsole.rst
index 4ab5d7b05cf10..2e489dd64ba42 100644
--- a/Documentation/networking/netconsole.rst
+++ b/Documentation/networking/netconsole.rst
@@ -111,7 +111,8 @@ netconsole module (or kernel, if netconsole is built-in).
Some examples follow (where configfs is mounted at the /sys/kernel/config
mountpoint).
-To add a remote logging target (target names can be arbitrary)::
+To add a remote logging target (target names can be arbitrary, except
+"replay", which is used by the attribute below)::
cd /sys/kernel/config/netconsole/
mkdir target1
@@ -125,6 +126,17 @@ To remove a target::
rmdir /sys/kernel/config/netconsole/othertarget/
+To replay the records retained in the kernel printk ring buffer to the enabled
+netconsole targets::
+
+ echo 1 > /sys/kernel/config/netconsole/replay
+
+As during normal operation, records above the current console loglevel are not
+sent. The replay is best effort and asynchronous: the write returns once the
+consoles have been rewound, before the records have been transmitted, and a
+console whose lock cannot be acquired is skipped. Only netconsole output is
+replayed; other registered consoles are unaffected.
+
The interface exposes these parameters of a netconsole target to userspace:
=============== ================================= ============
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index b358e5c367351..f527a5ee45662 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1830,8 +1830,33 @@ static const struct configfs_group_operations netconsole_subsys_group_ops = {
.drop_item = drop_netconsole_target,
};
+static ssize_t replay_store(struct config_item *item, const char *buf,
+ size_t count)
+{
+ bool replay;
+ int ret;
+
+ ret = kstrtobool(buf, &replay);
+ if (ret)
+ return ret;
+ if (!replay)
+ return -EINVAL;
+
+ console_try_replay(&netconsole);
+ console_try_replay(&netconsole_ext);
+
+ return count;
+}
+CONFIGFS_ATTR_WO(, replay);
+
+static struct configfs_attribute *netconsole_subsys_attrs[] = {
+ &attr_replay,
+ NULL,
+};
+
static const struct config_item_type netconsole_subsys_type = {
.ct_group_ops = &netconsole_subsys_group_ops,
+ .ct_attrs = netconsole_subsys_attrs,
.ct_owner = THIS_MODULE,
};
--
2.53.0-Meta