Last active
July 5, 2022 13:38
-
-
Save thaihust/f55e72e61d6123caab6549a32c51643f to your computer and use it in GitHub Desktop.
Revisions
-
thaihust revised this gist
Jul 5, 2022 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,6 +8,7 @@ confirmed_nic_list=() numvfs_list=() res="n" phy_driver=ixgbe base_mac=0a:bb:cc:dd echo echo @@ -93,9 +94,9 @@ do # set mac mac="" if [ "$k" -lt "10" ]; then mac="$base_mac:0$index:0$k" else mac="$base_mac:0$index:$k" fi k=$((k+1)) ip link set dev ${nic} vf ${j} mac $mac -
thaihust renamed this gist
Jun 22, 2022 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
thaihust created this gist
Jun 22, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,114 @@ #! /bin/bash MAX_VFS=63 ixgbe_nic_list=() pci_nic_list=() confirmed_nic_list=() numvfs_list=() res="n" phy_driver=ixgbe echo echo echo "!!! IMPORTANT !!!" echo "BIND ALL CURRENT VFs TO IXGBEVF BEFORE PROCEEDING" echo "!!! IMPORTANT !!!" echo echo # get all ixgbe-driven interfaces interfaces=`ip -o -a link show | awk -F': ' '{print $2}' | grep -v '^lo' | sort` read -d '' -r -a iface_array <<< "$interfaces" for iface in "${iface_array[@]}" do driver=`ethtool -i "${iface}" | grep "driver:" | awk '{print $2}'` if [ "$driver" = "$phy_driver" ]; then ixgbe_nic_list+=("$iface") fi done echo "Detected devices:" echo " ${ixgbe_nic_list[@]}" echo "-------" # confirm change for each interface for index in "${!ixgbe_nic_list[@]}" do echo -n "Confirm changing number of VFs for ${ixgbe_nic_list[index]} (y/n)? " read res if [ "$res" = "y" ]; then confirmed_nic_list+=("${index}") fi done echo "-------" # get number of VFs for each confirmed interface for index in "${confirmed_nic_list[@]}" do echo -n "Enter no. of VFs for ${ixgbe_nic_list[index]}: " read numvfs_list[index] while [[ "${numvfs_list[index]}" -gt "${MAX_VFS}" || "${numvfs_list[index]}" -lt 1 ]] do echo -n "Number of VFs must be between 1 and ${MAX_VFS}. Try again: " read numvfs_list[index] done done # confirm again cause why not echo "-------" echo "Summary" for index in "${confirmed_nic_list[@]}" do echo "NIC ${ixgbe_nic_list[index]}: ${numvfs_list[index]} VFs" done echo -n "confirm (y/n)? " read res if [ "${res}" != "y" ]; then echo "exiting..." exit fi echo "-------" # setup VFs echo "Setting up VFs" for index in "${confirmed_nic_list[@]}" do nic="${ixgbe_nic_list[index]}" numvfs="${numvfs_list[index]}" echo echo "NIC: ${nic}" echo " Changing number of VFs to ${numvfs}" echo 0 > /sys/class/net/${nic}/device/sriov_numvfs echo ${numvfs} > /sys/class/net/${nic}/device/sriov_numvfs echo " Setting mac address and spoofchk off for VFs" k=0 for j in `seq 0 $((numvfs-1))` do # set mac mac="" if [ "$k" -lt "10" ]; then mac="aa:bb:cc:dd:0$index:0$k" else mac="aa:bb:cc:dd:0$index:$k" fi k=$((k+1)) ip link set dev ${nic} vf ${j} mac $mac # turn off spoof checking ip link set dev ${nic} vf ${j} spoofchk off done # reload nic echo " Reloading" ip link set dev ${nic} down ip link set dev ${nic} up done echo "done"