From bf6142ca664acba5e716d1c7cc56e83c36884763 Mon Sep 17 00:00:00 2001 From: OnkelClaude Date: Tue, 11 Aug 2026 20:08:13 +0200 Subject: [PATCH 1/3] mxnetctl: Add wait command for a network device to appear MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `network.service` runs `mxnetctl start` followed by `ip addr add … dev ${MX_NETDEV}` as soon as sysinit.target is reached. If the NIC driver is still probing at that point, the device is not yet in /sys/class/net, so `mxnetctl start` cannot rename it and the ip commands fail. A kexec reboot regularly loses this race, because it skips firmware POST and reaches userspace before, for example, the roughly one second ixgbe probe has finished (issue #556 [1]). Add `mxnetctl wait DEVICE`, which polls every 100 ms until the device exists under its target name, or until hardware with the MAC address configured for that name in /etc/local/mxnet shows up (the device may still carry its kernel name before `mxnetctl start` renames it). Exit non-zero after --timeout seconds (default 30) so a genuinely missing device still fails visibly. [1]: https://github.molgen.mpg.de/mariux64/mxtools/issues/556 This change was written by an AI (Claude, operated by Boris) on behalf of Paul Menzel. --- mxnetctl/mxnetctl | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/mxnetctl/mxnetctl b/mxnetctl/mxnetctl index 3f41d553..dcaed5d3 100755 --- a/mxnetctl/mxnetctl +++ b/mxnetctl/mxnetctl @@ -4,10 +4,11 @@ use warnings; use Getopt::Long; -our ($opt_quiet,$opt_noop,$opt_ignore_hw); +our ($opt_quiet,$opt_noop,$opt_ignore_hw,$opt_timeout); use constant OPTIONS => ( 'quiet' => \$opt_quiet, 'noop' => \$opt_noop, + 'timeout=i' => \$opt_timeout, ); sub USAGE { @@ -15,10 +16,12 @@ sub USAGE { usage: $0 start [options] stop [options] # (ignored) + wait [options] DEVICE options: --quiet : do not log actions --noop : dry run + --timeout=S : seconds to wait for DEVICE (wait only, default 30) __EOF__ } @@ -175,6 +178,24 @@ sub start { } } +sub wait_for_device { # 'net04' -> 1 if device (or its configured hardware) is present, 0 on timeout + my ($dev)=@_; + read_mxnet(); + my $hw=$DEV_TO_HW{$dev}; + my $deadline=time+($opt_timeout // 30); + while (1) { + -d "/sys/class/net/$dev" and return 1; + if (defined $hw) { + for my $d (network_hardware_devices()) { + my $addr=eval { get_hw_address($d) } // next; + lc($addr) eq lc($hw) and return 1; + } + } + time>=$deadline and return 0; + select undef,undef,undef,0.1; + } +} + GetOptions(OPTIONS) or die USAGE; @ARGV>=1 or die USAGE; @@ -185,6 +206,13 @@ if ($cmd eq 'start') { start(); } elsif ($cmd eq 'stop') { ; +} elsif ($cmd eq 'wait') { + @ARGV>=2 or die USAGE; + my $dev=$ARGV[1]; + unless (wait_for_device($dev)) { + warn "timeout waiting for network device $dev\n"; + exit 1; + } } else { die USAGE; } From 19d1dcc2ca32684c09019a4fc4ceb76f001f955a Mon Sep 17 00:00:00 2001 From: OnkelClaude Date: Tue, 11 Aug 2026 20:08:13 +0200 Subject: [PATCH 2/3] network.service: Wait for the network device before configuring it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ip addr add … dev ${MX_NETDEV}` fails if the NIC driver has not finished probing, which regularly happens after a kexec reboot (issue #556 [1]): userspace starts within about two seconds, while for example the ixgbe SFP+/PHY probe needs about one second of wall-clock time, so on fluffybutt net04 did not exist yet when the unit ran. Wait for the device (by target name or by its MAC address from /etc/local/mxnet) before renaming and configuring it. [1]: https://github.molgen.mpg.de/mariux64/mxtools/issues/556 This change was written by an AI (Claude, operated by Boris) on behalf of Paul Menzel. --- etc/systemd/system/network.service | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/etc/systemd/system/network.service b/etc/systemd/system/network.service index 6eba6542..e4a81677 100644 --- a/etc/systemd/system/network.service +++ b/etc/systemd/system/network.service @@ -8,6 +8,10 @@ Wants=network.target EnvironmentFile=/etc/local/mxhost.conf Type=oneshot RemainAfterExit=yes +# The NIC driver may still be probing when we get here (short userspace +# startup after kexec outruns e.g. the ~1 s ixgbe probe, issue #556), so +# wait for the device before renaming and configuring it. +ExecStartPre=/usr/sbin/mxnetctl wait ${MX_NETDEV} ExecStart=/usr/sbin/mxnetctl start ExecStart=/sbin/ip addr add ${MX_IPADDR}/20 broadcast 141.14.31.255 dev ${MX_NETDEV} ExecStart=/sbin/ip link set up dev ${MX_NETDEV} From cd076da7a4618fe28af39f1faa3f3e2a7134e92d Mon Sep 17 00:00:00 2001 From: OnkelClaude Date: Wed, 12 Aug 2026 10:17:49 +0200 Subject: [PATCH 3/3] mxnetctl: Mention the timeout in the wait timeout message Say how long we actually waited, so the journal entry can be judged without looking up the default. The default (30 s) now lives in one place, applied right after option parsing. Requested by Paul in PR #2 review. Written by OnkelClaude (AI) on behalf of Boris Bergenroth. Co-authored-by: OnkelClaude (AI) --- mxnetctl/mxnetctl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mxnetctl/mxnetctl b/mxnetctl/mxnetctl index dcaed5d3..981bc189 100755 --- a/mxnetctl/mxnetctl +++ b/mxnetctl/mxnetctl @@ -182,7 +182,7 @@ sub wait_for_device { # 'net04' -> 1 if device (or its configured hardware) is p my ($dev)=@_; read_mxnet(); my $hw=$DEV_TO_HW{$dev}; - my $deadline=time+($opt_timeout // 30); + my $deadline=time+$opt_timeout; while (1) { -d "/sys/class/net/$dev" and return 1; if (defined $hw) { @@ -197,6 +197,7 @@ sub wait_for_device { # 'net04' -> 1 if device (or its configured hardware) is p } GetOptions(OPTIONS) or die USAGE; +$opt_timeout //= 30; # default documented in USAGE @ARGV>=1 or die USAGE; @@ -210,7 +211,7 @@ if ($cmd eq 'start') { @ARGV>=2 or die USAGE; my $dev=$ARGV[1]; unless (wait_for_device($dev)) { - warn "timeout waiting for network device $dev\n"; + warn "timeout waiting for network device $dev after ${opt_timeout}s\n"; exit 1; } } else {