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 cd31dd2da9)
This commit is contained in:
waleed mousa 2019-02-20 03:15:29 -05:00
parent 25c13e7078
commit a3ad663787
3 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -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.\"

View File

@ -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."