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

 使用如下脚本可以获取到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 ]; then
      echo " |_ `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}')";
    else
      echo "$i has bound by vm !"
    fi
  done
}
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) --> enp3s0f0
 VF:
 |_ 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) --> enp3s0f1
 VF:
 |_ 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) --> enp3s0f3
 VF:
 |_ 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 !

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值