From 1d553a924463a6e25eabb10e70b90b367346987e Mon Sep 17 00:00:00 2001 From: Carl Roth <79488471+rothcar@users.noreply.github.com> Date: Tue, 9 Mar 2021 10:16:54 -0800 Subject: [PATCH] Add switchdev-online service to hold off on network init (#56) * Add switchdev-online service to hold off on network init The addresses a race condition between the switchdev driver, udev and ifupdown2. In some cases, ifupdown2 attempts to configure switchdev interfaces (1) before they are ready, or (2) before any udev rules have had a chance to rename them per udev configuration. When this happens, not all interfaces are configured correctly. The solution is to 1. create a dummy systemd service for each switchdev interface (platform specific) that depends on the well-known systemd device path for that netdev (currently 'sys-subsystem-net-devices-FOO.device'. 2. Make the system-wide network-pre.service depend on *all* switchdev devices coming online 3. make ifupdown2 (via networking.service) depend on network-pre.service See https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ Signed-off-by: Carl Roth * update line ending per review Signed-off-by: Carl Roth * Add switchdev-online support for Delta tn48m-dn platforms - based on fixes for non-DN systems - please check my work, I don't have physical access to these systems to verify port count Signed-off-by: Carl Roth * spray for spelling, per review Signed-off-by: Carl Roth --- .../switchdev-online.conf | 2 ++ .../systemd/system/switchdev-online@.service | 20 +++++++++++++++++++ .../arm64_accton_as4224_52p_r0/__init__.py | 5 +++++ .../arm64_accton_as4224_52t_r0/__init__.py | 5 +++++ .../arm64_accton_as5114_48x_r0/__init__.py | 4 ++++ .../arm64_delta_tn4810m_dn_r0/__init__.py | 5 +++++ .../arm64_delta_tn48m_dn_r0/__init__.py | 5 +++++ .../arm64_delta_tn48m_poe_dn_r0/__init__.py | 5 +++++ .../python/arm64_delta_tn4810m_r0/__init__.py | 5 +++++ .../arm64_delta_tn48m_poe_r0/__init__.py | 5 +++++ .../python/arm64_delta_tn48m_r0/__init__.py | 5 +++++ .../python/arm64_delta_tn48m2_r0/__init__.py | 5 +++++ 12 files changed, 71 insertions(+) create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/systemd/system/networking.service.d/switchdev-online.conf create mode 100644 builds/any/rootfs/stretch/common/overlay/etc/systemd/system/switchdev-online@.service diff --git a/builds/any/rootfs/stretch/common/overlay/etc/systemd/system/networking.service.d/switchdev-online.conf b/builds/any/rootfs/stretch/common/overlay/etc/systemd/system/networking.service.d/switchdev-online.conf new file mode 100644 index 000000000..4e9b7d40d --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/systemd/system/networking.service.d/switchdev-online.conf @@ -0,0 +1,2 @@ +[Unit] +After=network-pre.target diff --git a/builds/any/rootfs/stretch/common/overlay/etc/systemd/system/switchdev-online@.service b/builds/any/rootfs/stretch/common/overlay/etc/systemd/system/switchdev-online@.service new file mode 100644 index 000000000..1b786ffe0 --- /dev/null +++ b/builds/any/rootfs/stretch/common/overlay/etc/systemd/system/switchdev-online@.service @@ -0,0 +1,20 @@ +[Unit] +Description=Online state for switchdev device %i + +# See e.g. +# https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ +Wants=network-pre.target +Before=network-pre.target + +# this is the naming scheme currently used for network devices +Wants=sys-subsystem-net-devices-%i.device +After=sys-subsystem-net-devices-%i.device + +[Service] +Type=simple +RemainAfterExit=yes +ExecStart=/bin/true +TimeoutStartSec=30 + +[Install] +WantedBy=network.target diff --git a/packages/platforms/accton/arm64/as4224/as4224-52p/platform-config/r0/src/python/arm64_accton_as4224_52p_r0/__init__.py b/packages/platforms/accton/arm64/as4224/as4224-52p/platform-config/r0/src/python/arm64_accton_as4224_52p_r0/__init__.py index 66e56f07c..edb1aaab9 100644 --- a/packages/platforms/accton/arm64/as4224/as4224-52p/platform-config/r0/src/python/arm64_accton_as4224_52p_r0/__init__.py +++ b/packages/platforms/accton/arm64/as4224/as4224-52p/platform-config/r0/src/python/arm64_accton_as4224_52p_r0/__init__.py @@ -52,4 +52,9 @@ def baseconfig(self): self.insmod("prestera_sw.ko") self.insmod("prestera_pci.ko") + # set up systemctl rules + for swp in range(1, 53): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/accton/arm64/as4224/as4224-52t/platform-config/r0/src/python/arm64_accton_as4224_52t_r0/__init__.py b/packages/platforms/accton/arm64/as4224/as4224-52t/platform-config/r0/src/python/arm64_accton_as4224_52t_r0/__init__.py index ac18b3cf7..cb3a11317 100644 --- a/packages/platforms/accton/arm64/as4224/as4224-52t/platform-config/r0/src/python/arm64_accton_as4224_52t_r0/__init__.py +++ b/packages/platforms/accton/arm64/as4224/as4224-52t/platform-config/r0/src/python/arm64_accton_as4224_52t_r0/__init__.py @@ -52,4 +52,9 @@ def baseconfig(self): self.insmod("prestera_sw.ko") self.insmod("prestera_pci.ko") + # set up systemctl rules + for swp in range(1, 53): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/accton/arm64/as4224/as5114-48x/platform-config/r0/src/python/arm64_accton_as5114_48x_r0/__init__.py b/packages/platforms/accton/arm64/as4224/as5114-48x/platform-config/r0/src/python/arm64_accton_as5114_48x_r0/__init__.py index 86d03be73..98767ff21 100644 --- a/packages/platforms/accton/arm64/as4224/as5114-48x/platform-config/r0/src/python/arm64_accton_as5114_48x_r0/__init__.py +++ b/packages/platforms/accton/arm64/as4224/as5114-48x/platform-config/r0/src/python/arm64_accton_as5114_48x_r0/__init__.py @@ -52,5 +52,9 @@ def baseconfig(self): self.insmod("prestera_sw.ko") self.insmod("prestera_pci.ko") + # set up systemctl rules + for swp in range(1, 49): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) return True diff --git a/packages/platforms/delta/arm64/tn48m-dn/tn4810m-dn/platform-config/r0/src/python/arm64_delta_tn4810m_dn_r0/__init__.py b/packages/platforms/delta/arm64/tn48m-dn/tn4810m-dn/platform-config/r0/src/python/arm64_delta_tn4810m_dn_r0/__init__.py index 76438aaae..6d5999fd8 100755 --- a/packages/platforms/delta/arm64/tn48m-dn/tn4810m-dn/platform-config/r0/src/python/arm64_delta_tn4810m_dn_r0/__init__.py +++ b/packages/platforms/delta/arm64/tn48m-dn/tn4810m-dn/platform-config/r0/src/python/arm64_delta_tn4810m_dn_r0/__init__.py @@ -41,4 +41,9 @@ def baseconfig(self): # Suggested by Taras Chornyi self.modprobe('prestera_pci') + # set up systemctl rules + for swp in range(1, 49): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/delta/arm64/tn48m-dn/tn48m-dn/platform-config/r0/src/python/arm64_delta_tn48m_dn_r0/__init__.py b/packages/platforms/delta/arm64/tn48m-dn/tn48m-dn/platform-config/r0/src/python/arm64_delta_tn48m_dn_r0/__init__.py index 77fb9dbec..def6f2e10 100755 --- a/packages/platforms/delta/arm64/tn48m-dn/tn48m-dn/platform-config/r0/src/python/arm64_delta_tn48m_dn_r0/__init__.py +++ b/packages/platforms/delta/arm64/tn48m-dn/tn48m-dn/platform-config/r0/src/python/arm64_delta_tn48m_dn_r0/__init__.py @@ -30,5 +30,10 @@ def baseconfig(self): # Suggested by Taras Chornyi self.modprobe('prestera_pci') + # set up systemctl rules + for swp in range(1, 53): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/delta/arm64/tn48m-dn/tn48m-poe-dn/platform-config/r0/src/python/arm64_delta_tn48m_poe_dn_r0/__init__.py b/packages/platforms/delta/arm64/tn48m-dn/tn48m-poe-dn/platform-config/r0/src/python/arm64_delta_tn48m_poe_dn_r0/__init__.py index 7caff4327..dc4241265 100755 --- a/packages/platforms/delta/arm64/tn48m-dn/tn48m-poe-dn/platform-config/r0/src/python/arm64_delta_tn48m_poe_dn_r0/__init__.py +++ b/packages/platforms/delta/arm64/tn48m-dn/tn48m-poe-dn/platform-config/r0/src/python/arm64_delta_tn48m_poe_dn_r0/__init__.py @@ -39,4 +39,9 @@ def baseconfig(self): # Suggested by Taras Chornyi self.modprobe('prestera_pci') + # set up systemctl rules + for swp in range(1, 53): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/delta/arm64/tn48m/tn4810m/platform-config/r0/src/python/arm64_delta_tn4810m_r0/__init__.py b/packages/platforms/delta/arm64/tn48m/tn4810m/platform-config/r0/src/python/arm64_delta_tn4810m_r0/__init__.py index 72573130c..708a557ed 100755 --- a/packages/platforms/delta/arm64/tn48m/tn4810m/platform-config/r0/src/python/arm64_delta_tn4810m_r0/__init__.py +++ b/packages/platforms/delta/arm64/tn48m/tn4810m/platform-config/r0/src/python/arm64_delta_tn4810m_r0/__init__.py @@ -45,4 +45,9 @@ def baseconfig(self): # Suggested by Taras Chornyi self.modprobe('prestera_pci') + # set up systemctl rules + for swp in range(1, 49): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/delta/arm64/tn48m/tn48m-poe/platform-config/r0/src/python/arm64_delta_tn48m_poe_r0/__init__.py b/packages/platforms/delta/arm64/tn48m/tn48m-poe/platform-config/r0/src/python/arm64_delta_tn48m_poe_r0/__init__.py index db5704d03..4632d51e6 100755 --- a/packages/platforms/delta/arm64/tn48m/tn48m-poe/platform-config/r0/src/python/arm64_delta_tn48m_poe_r0/__init__.py +++ b/packages/platforms/delta/arm64/tn48m/tn48m-poe/platform-config/r0/src/python/arm64_delta_tn48m_poe_r0/__init__.py @@ -39,4 +39,9 @@ def baseconfig(self): # Suggested by Taras Chornyi self.modprobe('prestera_pci') + # set up systemctl rules + for swp in range(1, 53): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/delta/arm64/tn48m/tn48m/platform-config/r0/src/python/arm64_delta_tn48m_r0/__init__.py b/packages/platforms/delta/arm64/tn48m/tn48m/platform-config/r0/src/python/arm64_delta_tn48m_r0/__init__.py index a52c4d619..338272f4f 100755 --- a/packages/platforms/delta/arm64/tn48m/tn48m/platform-config/r0/src/python/arm64_delta_tn48m_r0/__init__.py +++ b/packages/platforms/delta/arm64/tn48m/tn48m/platform-config/r0/src/python/arm64_delta_tn48m_r0/__init__.py @@ -30,5 +30,10 @@ def baseconfig(self): # Suggested by Taras Chornyi self.modprobe('prestera_pci') + # set up systemctl rules + for swp in range(1, 53): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True diff --git a/packages/platforms/delta/arm64/tn48m/tn48m2/platform-config/r0/src/python/arm64_delta_tn48m2_r0/__init__.py b/packages/platforms/delta/arm64/tn48m/tn48m2/platform-config/r0/src/python/arm64_delta_tn48m2_r0/__init__.py index 332ad9660..20d829e6c 100755 --- a/packages/platforms/delta/arm64/tn48m/tn48m2/platform-config/r0/src/python/arm64_delta_tn48m2_r0/__init__.py +++ b/packages/platforms/delta/arm64/tn48m/tn48m2/platform-config/r0/src/python/arm64_delta_tn48m2_r0/__init__.py @@ -30,4 +30,9 @@ def baseconfig(self): # Suggested by Taras Chornyi self.modprobe('prestera_pci') + # set up systemctl rules + for swp in range(1, 53): + cmd = "systemctl enable switchdev-online@swp%d" % swp + subprocess.check_call(cmd, shell=True) + return True