Last active
August 18, 2017 16:30
-
-
Save dosaboy/909f3b2a282f43c04b8fd5fe630e0562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
# | |
# Sweep through all VFs and do an ip link set with their MAC so that PF is | |
# updated. | |
# | |
declare -A pfs=() | |
declare -A vf_info=() | |
declare -A vf_info2=() | |
declare -A vf_info3=() | |
out=() | |
for d in /sys/bus/pci/devices/*; do | |
if [ -e "$d/sriov_numvfs" ]; then | |
out+=(`ls $d/net`) | |
out+=( `basename $d` ) | |
fi | |
done | |
for ((i=0;i<${#out[@]};i+=2)); do | |
pf_name=${out[i]} | |
pf_pci=${out[$((i+1))]} | |
pfs[$pf_name]=$pf_pci | |
_vfs=() | |
if `ls /sys/bus/pci/devices/$pf_pci/virtfn* &>/dev/null`; then | |
for vf in /sys/bus/pci/devices/$pf_pci/virtfn*; do | |
vf=`echo $vf|sed -r 's/.+virtfn([0-9]*)$/\1/g'` | |
_vfs+=( "$vf\n" ) | |
done | |
read -a _vfs<<<`echo -e ${_vfs[@]}| sort -n` | |
echo PF $pf_name has pci address $pf_pci and ${#_vfs[@]} VFs | |
for vf in ${_vfs[@]}; do | |
vf_pci=$(basename `readlink -f /sys/bus/pci/devices/$pf_pci/virtfn$vf`) | |
vf_iface_path=/sys/bus/pci/devices/$vf_pci/net/ | |
[ -d "$vf_iface_path" ] || { echo "PF $pf_name VF $vf iface not found - is it in use?"; continue; } | |
vf_iface=`ls $vf_iface_path` | |
[ -n "$vf_iface" ] || { echo "Unable to get mac address for $vf_pci - is it in use?"; continue; } | |
vf_mac=`cat /sys/bus/pci/devices/$vf_pci/net/$vf_iface/address` | |
key=${vf_pci//:/_} | |
key=${key//./__} | |
vf_info["$key"]=$vf_mac | |
vf_info2["$key"]=$pf_name | |
vf_info3["$key"]=$vf | |
done | |
else | |
echo PF $pf_name has pci address $pf_pci and no VFs | |
fi | |
done | |
for key in ${!vf_info[@]}; do | |
vf_pci=${key//__/.} | |
vf_pci=${vf_pci//_/:} | |
current=${vf_info[$key]} | |
echo "Ensuring VF ${vf_info2[$key]}_virtfn${vf_info3[$key]} (mac=$current,pci=$vf_pci) with mac $current" | |
ip link set ${vf_info2[$key]} vf ${vf_info3[$key]} mac $current | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment