SR-IOV是比较好的虚拟化硬件性能解决方案,使用需要特定的硬件支持。
查看是否启动SR-IOV,如果没有igbvf行,说明以内核模块的形式安装了igb网卡驱动,但是没有启动对SR-IOV的支持。
# lsmod |grep igb
igbvf 46485 0
igb 215727 0
启动对SR-IOV支持(对于千兆网卡,max_vfs可以设置的值应该是0 < vfs <= 7)
modprobe igb max_vfs=4
验证是否生效,通过上面命令可以,也可以通过(我宿主机网卡刚好是Intel I350)。每个物理网卡都有4个VF(除了被Passthrough给guest机的物理网卡之外)
# ip link show
enp3s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master ovs-system state UP mode DEFAULT group default qlen 1000
link/ether 0c:c4:7a:80:52:08 brd ff:ff:ff:ff:ff:ff
vf 0 MAC ba:b1:86:82:3d:1f, spoof checking on, link-state auto, trust off
vf 1 MAC 9a:d2:01:3e:b9:67, spoof checking on, link-state auto, trust off
vf 2 MAC 5a:18:b5:7f:99:bf, spoof checking on, link-state auto, trust off
vf 3 MAC 72:d1:4a:c0:94:29, spoof checking on, link-state auto, trust off
或
# lspci |grep -i i350
……
03:00.3 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
03:10.0 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01)
03:10.1 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01)
……
03:11.7 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01)
虚拟机绑定vf子网卡
# virsh nodedev-list|grep 03_11
pci_0000_03_11_0
pci_0000_03_11_1
pci_0000_03_11_3
pci_0000_03_11_4
pci_0000_03_11_5
pci_0000_03_11_7
# virsh nodedev-dumpxml pci_0000_03_11_7
<device>
……
<domain>0</domain>
<bus>3</bus>
<slot>17</slot>
<function>7</function>
……
定义domain xml
<interface type='hostdev' managed='yes'>
<source>
<address type='pci' domain='0x0000' bus='0x03' slot='0x11' function='0x7'/>
<!-- 或(上面是16进制数值,下面的是10进制数值)-->
<address type='pci' domain='0' bus='3' slot='17' function='7'/>
</source>
</interface>
重启虚机,验证
# lspci |grep Ethernet
00:03.0 Ethernet controller: Red Hat, Inc. Virtio network device
00:08.0 Ethernet controller: Intel Corporation I350 Ethernet Controller Virtual Function (rev 01)