From 10237e999d5d2b3fab5be95d940a758edbf67a63 Mon Sep 17 00:00:00 2001 From: waleed mousa Date: Mon, 29 Jan 2018 04:15:12 -0500 Subject: [PATCH] hw ovs offload - On some machines representor ports not created after reboot On some machines it's failing to run the devlink and ethtool commands without the full path of these commands Closes-Bug: #1745821 Change-Id: If2f7c7a46fb1b52cce9ffbfa31a3161fc07f1334 --- lib/puppet/provider/sriov_vf_config/numvfs.rb | 6 +-- ...pleo_host_sriov_numvfs_persistence_spec.rb | 45 +++++++++++++------ templates/switchdev/switchdev.epp | 45 +++++++++++++------ 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/lib/puppet/provider/sriov_vf_config/numvfs.rb b/lib/puppet/provider/sriov_vf_config/numvfs.rb index fd3899737..963311b11 100644 --- a/lib/puppet/provider/sriov_vf_config/numvfs.rb +++ b/lib/puppet/provider/sriov_vf_config/numvfs.rb @@ -55,11 +55,11 @@ Puppet::Type.type(:sriov_vf_config).provide(:numvfs) do end end # Changing the mode of sriov interface to switchdev mode - %x{devlink dev eswitch set pci/#{get_interface_pci} mode switchdev} - %x{ethtool -K #{sriov_get_interface} hw-tc-offload on} + %x{/usr/sbin/devlink dev eswitch set pci/#{get_interface_pci} mode switchdev} if get_interface_device == "0x1013" || get_interface_device == "0x1015" - %x{devlink dev eswitch set pci/#{get_interface_pci} inline-mode transport} + %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} if cur_value == "0x15b3" # Binding virtual functions vfs_pcis.each do|vfs_pci| diff --git a/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb b/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb index 876c4084c..455e09639 100644 --- a/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb +++ b/spec/defines/tripleo_host_sriov_numvfs_persistence_spec.rb @@ -68,29 +68,46 @@ describe 'tripleo::host::sriov::numvfs_persistence' do it 'configures persistence' do is_expected.to contain_file('/etc/sysconfig/allocate_vfs').with( :ensure => 'file', - :content => "Hashbang\nif [ \"eth0\" == \"$1\" ] + :content => "Hashbang\nset -eux +set -o pipefail + +if [ \"eth0\" == \"$1\" ] then - echo 10 > /sys/class/net/eth0/device/sriov_numvfs - if [ `cat /sys/class/net/eth0/device/vendor` == \"0x15b3\" ] + exec 1> >(logger -s -t $(basename $0)) 2>&1 + if [ \"$(cat /sys/class/net/eth0/device/sriov_numvfs)\" == \"0\" ] then - for pci in `cat /sys/class/net/eth0/device/virtfn*/uevent | grep PCI_SLOT_NAME | cut -d'=' -f2` + echo 10 > /sys/class/net/eth0/device/sriov_numvfs + else + exit 0 + fi + if [ \"$(cat /sys/class/net/eth0/device/vendor)\" == \"0x15b3\" ] + then + vfs_pci_list=$(grep PCI_SLOT_NAME /sys/class/net/eth0/device/virtfn*/uevent | cut -d'=' -f2) + for pci in $vfs_pci_list do - echo \$pci > /sys/bus/pci/drivers/mlx5_core/unbind + echo \"$pci\" > /sys/bus/pci/drivers/mlx5_core/unbind done fi - interface_pci=`ethtool -i eth0 | grep bus-info | awk {'print\$2'}` - devlink dev eswitch set pci/\$interface_pci mode switchdev - interface_device=`cat /sys/class/net/eth0/device/device` - if [ $interface_device == \"0x1013\" ] || [ $interface_device == \"0x1015\" ] + 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 + if [[ \"$(/usr/sbin/devlink dev eswitch show pci/\"$interface_pci\")\" =~ \"mode switchdev\" ]] then - devlink dev eswitch set pci/$interface_pci inline-mode transport + echo \"PCI device $interface_pci set to mode switchdev.\" + else + echo \"Failed to set PCI device $interface_pci to mode switchdev.\" + exit 1 fi - ethtool -K eth0 hw-tc-offload on - if [ `cat /sys/class/net/eth0/device/vendor` == \"0x15b3\" ] + interface_device=$(cat /sys/class/net/eth0/device/device) + if [ \"$interface_device\" == \"0x1013\" ] || [ \"$interface_device\" == \"0x1015\" ] then - for pci in `cat /sys/class/net/eth0/device/virtfn*/uevent | grep PCI_SLOT_NAME | cut -d'=' -f2` + /usr/sbin/devlink dev eswitch set pci/\"$interface_pci\" inline-mode transport + fi + /usr/sbin/ethtool -K eth0 hw-tc-offload on + if [ \"$(cat /sys/class/net/eth0/device/vendor)\" == \"0x15b3\" ] + then + for pci in $vfs_pci_list do - echo \$pci > /sys/bus/pci/drivers/mlx5_core/bind; + echo \"$pci\" > /sys/bus/pci/drivers/mlx5_core/bind done fi fi\n[ \"eth1\" == \"\$1\" ] && echo 8 > /sys/class/net/eth1/device/sriov_numvfs\n", diff --git a/templates/switchdev/switchdev.epp b/templates/switchdev/switchdev.epp index 7ada47db5..5eb1b7689 100644 --- a/templates/switchdev/switchdev.epp +++ b/templates/switchdev/switchdev.epp @@ -1,27 +1,44 @@ <%- | String $content_string = '', String $interface = '', String $count = '' | -%> -<%=$content_string%>if [ "<%=$interface%>" == "$1" ] +<%=$content_string%>set -eux +set -o pipefail + +if [ "<%=$interface%>" == "$1" ] then - echo <%=$count%> > /sys/class/net/<%=$interface%>/device/sriov_numvfs - if [ `cat /sys/class/net/<%=$interface%>/device/vendor` == "0x15b3" ] + exec 1> >(logger -s -t $(basename $0)) 2>&1 + if [ "$(cat /sys/class/net/<%=$interface%>/device/sriov_numvfs)" == "0" ] then - for pci in `cat /sys/class/net/<%=$interface%>/device/virtfn*/uevent | grep PCI_SLOT_NAME | cut -d'=' -f2` + echo <%=$count%> > /sys/class/net/<%=$interface%>/device/sriov_numvfs + else + exit 0 + fi + if [ "$(cat /sys/class/net/<%=$interface%>/device/vendor)" == "0x15b3" ] + then + vfs_pci_list=$(grep PCI_SLOT_NAME /sys/class/net/<%=$interface%>/device/virtfn*/uevent | cut -d'=' -f2) + for pci in $vfs_pci_list do - echo $pci > /sys/bus/pci/drivers/mlx5_core/unbind + echo "$pci" > /sys/bus/pci/drivers/mlx5_core/unbind done fi - interface_pci=`ethtool -i <%=$interface%> | grep bus-info | awk {'print$2'}` - devlink dev eswitch set pci/$interface_pci mode switchdev - interface_device=`cat /sys/class/net/<%=$interface%>/device/device` - if [ $interface_device == "0x1013" ] || [ $interface_device == "0x1015" ] + 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 + if [[ "$(/usr/sbin/devlink dev eswitch show pci/"$interface_pci")" =~ "mode switchdev" ]] then - devlink dev eswitch set pci/$interface_pci inline-mode transport + echo "PCI device $interface_pci set to mode switchdev." + else + echo "Failed to set PCI device $interface_pci to mode switchdev." + exit 1 fi - ethtool -K <%=$interface%> hw-tc-offload on - if [ `cat /sys/class/net/<%=$interface%>/device/vendor` == "0x15b3" ] + interface_device=$(cat /sys/class/net/<%=$interface%>/device/device) + if [ "$interface_device" == "0x1013" ] || [ "$interface_device" == "0x1015" ] then - for pci in `cat /sys/class/net/<%=$interface%>/device/virtfn*/uevent | grep PCI_SLOT_NAME | cut -d'=' -f2` + /usr/sbin/devlink dev eswitch set pci/"$interface_pci" inline-mode transport + fi + /usr/sbin/ethtool -K <%=$interface%> hw-tc-offload on + if [ "$(cat /sys/class/net/<%=$interface%>/device/vendor)" == "0x15b3" ] + then + for pci in $vfs_pci_list do - echo $pci > /sys/bus/pci/drivers/mlx5_core/bind; + echo "$pci" > /sys/bus/pci/drivers/mlx5_core/bind done fi fi