当前位置: 代码迷 >> 综合 >> shell脚本:获取SR-IOV中PF和VF之间的关系
  详细解决方案

shell脚本:获取SR-IOV中PF和VF之间的关系

热度:19   发布时间:2024-02-07 07:28:59.0

 使用如下脚本可以获取到SR-IOV中,Physical Functions和Virtual Functions之间,清晰的关系。

 包括接口名称,domain、bus、slot、function的编号信息,接口mac地址信息,以及给VF是否被绑给了vm。

#!/bin/bash
function pf_vf(){echo "<=============>PF:$1<=============="echo "`lspci|grep $(ls -l /sys/class/net/$1/ |grep device |cut -d '/' -f 4|sed 's/0000://g')` --> $1"echo " VF:"eth_dev=`ls /sys/class/net/$1/device/virtfn* -l | cut -d ">" -f 2 |cut -d "/" -f 2`for i in $eth_dev; do vf_name=`ls /sys/bus/pci/devices/$i/net 2>&1`;if  [ $? -eq 0 ]; thenecho " |_ `lspci|grep $(echo $i|sed 's/0000://g')` --> $vf_name"; echo "   |_ _ $(ip link show |grep -w $vf_name -A1 |grep -v $vf_name|awk '{print $2}')";elseecho "$i has bound by vm !"fidone
}
for i in $(ip link show |grep mq|cut -d ':' -f 2);do pf_vf $i;done

 脚本执行效果如下:

<=============>PF:enp3s0f0<==============
03:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01) --> enp3s0f0VF:|_ 03:10.0 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s16|_ _ ba:b1:86:82:3d:1f|_ 03:10.4 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s16f4|_ _ 9a:d2:01:3e:b9:67|_ 03:11.0 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s17|_ _ 5a:18:b5:7f:99:bf|_ 03:11.4 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s17f4|_ _ 72:d1:4a:c0:94:29
<=============>PF:enp3s0f1<==============
03:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01) --> enp3s0f1VF:|_ 03:10.1 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s16f1|_ _ 2e:ec:95:fe:07:92|_ 03:10.5 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s16f5|_ _ 22:61:05:95:80:5c|_ 03:11.1 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s17f1|_ _ a6:b8:1f:27:c2:74|_ 03:11.5 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s17f5|_ _ 32:3c:8e:80:68:ff
<=============>PF:enp3s0f3<==============
03:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01) --> enp3s0f3VF:|_ 03:10.3 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s16f3|_ _ 5e:2d:3b:ea:8b:71|_ 03:10.7 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s16f7|_ _ 76:df:b5:48:84:e1|_ 03:11.3 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01) --> enp3s17f3|_ _ 3a:0b:2f:62:ea:3c
0000:03:11.7 has bound by vm !

 

  相关解决方案