Skip to content

Commit

Permalink
Add switchdev-bind service
Browse files Browse the repository at this point in the history
Switchdev-bind service rebinds VF to its driver and executes
after NetworkManager service, this is required for features
such as VF LAG to take effect when bond or other network
configurtion are configured through NetworkManager service.

Signed-off-by: Zenghui Shi <[email protected]>
  • Loading branch information
zshi-redhat committed Nov 15, 2021
1 parent f4cc0f3 commit dcefeab
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
35 changes: 35 additions & 0 deletions bindata/manifests/switchdev-config/files/bind-switchdev.sh.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
mode: 0755
overwrite: true
path: "/usr/local/bin/bind-switchdev.sh"
contents:
inline: |
#!/bin/bash
set -eux
input="/etc/sriov_config.json"
if [ ! -f $input ]; then
echo "File /etc/sriov_config.json not exist."
exit
fi
# Required for NetworkManager configuration(e.g. bond) to settle down
sleep 3
jq -c '.interfaces[]' $input | while read iface;
do
eswitch_mode=$(echo $iface | jq '.eSwitchMode' -r)
if [[ "$eswitch_mode" == "switchdev" ]]; then
pci_addr=$(echo $iface | jq '.pciAddress' -r)
name=$(echo $iface | jq '.name' -r)
echo "load VF driver for $pci_addr"
VfDirs=$(ls /sys/bus/pci/devices/${pci_addr} | grep virtfn)
# load VF driver
for VfDir in $VfDirs
do
VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )")
echo $VfPciAddr > /sys/bus/pci/drivers_probe
done
fi
done
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,5 @@ contents:
# turn hw-tc-offload on
/usr/sbin/ethtool -K ${name} hw-tc-offload on
# load VF driver
for VfDir in $VfDirs
do
VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )")
echo $VfPciAddr > /sys/bus/pci/drivers_probe
done
fi
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
contents: |
[Unit]
Description=Binds SRIOV VFs into switchdev driver
# Removal of this file signals firstboot completion
ConditionPathExists=!/etc/ignition-machine-config-encapsulated.json
# This service is used to move a SRIOV NIC into switchdev mode
Wants=NetworkManager.service
After=NetworkManager.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/bind-switchdev.sh
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=network-online.target
enabled: true
name: switchdev-bind.service

0 comments on commit dcefeab

Please sign in to comment.