From a3ad663787973eed5e38b53972de0a0608899045 Mon Sep 17 00:00:00 2001 From: waleed mousa Date: Wed, 20 Feb 2019 03:15:29 -0500 Subject: [PATCH] Adding a udev rule to save sriov interface name before configuring switchdev After moving mlnx interfaces to switchdev mode in sriov, it will reset that interface and may change its name and also will need ifup in order to get back the previous configuration. So adding a udev rule and ifup command the save the interface name and its configuration Change-Id: Ib4f384da344344f9e2ec666b0d8dbae441f24568 Closes-Bug: 1816710 (cherry picked from commit cd31dd2da9a4da7d7ee1a4609fda1d2b506d1d8e) --- lib/puppet/provider/sriov_vf_config/numvfs.rb | 18 ++++++++++++++++++ ...ipleo_host_sriov_numvfs_persistence_spec.rb | 1 + templates/switchdev/switchdev.epp | 1 + 3 files changed, 20 insertions(+) diff --git a/lib/puppet/provider/sriov_vf_config/numvfs.rb b/lib/puppet/provider/sriov_vf_config/numvfs.rb index e985ce1a8..02da863ed 100644 --- a/lib/puppet/provider/sriov_vf_config/numvfs.rb +++ b/lib/puppet/provider/sriov_vf_config/numvfs.rb @@ -62,14 +62,32 @@ Puppet::Type.type(:sriov_vf_config).provide(:numvfs) do File.write("/sys/bus/pci/drivers/mlx5_core/unbind",vfs_pci) end end + + # Saving the name of sriov interface to udev rules + udev_file_path = "/etc/udev/rules.d/70-persistent-net.rules" + sriov_interface_mac = File.read(sriov_interface_mac_path).strip + udev_data_line = get_udev_data_line(sriov_interface_mac) + File.write(udev_file_path, udev_data_line, mode: 'a') + %x{/usr/sbin/udevadm control --reload-rules} + %x{/usr/sbin/udevadm trigger} + # Changing the mode of sriov interface to switchdev mode %x{/usr/sbin/devlink dev eswitch set pci/#{get_interface_pci} mode switchdev} + %x{/usr/sbin/ifup #{sriov_get_interface}} if get_interface_device == "0x1013" || get_interface_device == "0x1015" %x{/usr/sbin/devlink dev eswitch set pci/#{get_interface_pci} inline-mode transport} end %x{/usr/sbin/ethtool -K #{sriov_get_interface} hw-tc-offload on} end + def get_udev_data_line(mac) + 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="' + "#{mac}" + '", NAME="' + "#{sriov_get_interface}" + "\"\n" + end + + def sriov_interface_mac_path + "/sys/class/net/#{sriov_get_interface}/address" + end + def sriov_numvfs_path "/sys/class/net/#{sriov_get_interface}/device/sriov_numvfs" end diff --git a/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb b/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb index fb3192fba..75a76f0f8 100644 --- a/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb +++ b/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb @@ -91,6 +91,7 @@ then fi interface_pci=$(grep PCI_SLOT_NAME /sys/class/net/eth0/device/uevent | cut -d'=' -f2) /usr/sbin/devlink dev eswitch set pci/\"$interface_pci\" mode switchdev + /usr/sbin/ifup eth0 if [[ \"$(/usr/sbin/devlink dev eswitch show pci/\"$interface_pci\")\" =~ \"mode switchdev\" ]] then echo \"PCI device $interface_pci set to mode switchdev.\" diff --git a/templates/switchdev/switchdev.epp b/templates/switchdev/switchdev.epp index 1d3292564..af13764f2 100644 --- a/templates/switchdev/switchdev.epp +++ b/templates/switchdev/switchdev.epp @@ -22,6 +22,7 @@ then fi interface_pci=$(grep PCI_SLOT_NAME /sys/class/net/<%=$interface%>/device/uevent | cut -d'=' -f2) /usr/sbin/devlink dev eswitch set pci/"$interface_pci" mode switchdev + /usr/sbin/ifup <%=$interface%> if [[ "$(/usr/sbin/devlink dev eswitch show pci/"$interface_pci")" =~ "mode switchdev" ]] then echo "PCI device $interface_pci set to mode switchdev."