virsh network
To avoid hardcoding the PCI address of a VF into a guest’s configuration, a libvirt network with a device pool containing all of the VFs of an SR-IOV device is created. The guest then references this network, such that on guest startup, a VF is assigned from the pool:
[root@rhel-tiger-14-6 ~]# touch /var/lib/libvirt/network/ens4f0.xml [root@rhel-tiger-14-6 ~]# chown root:root /var/lib/libvirt/network/ens4f0.xml [root@rhel-tiger-14-6 ~]# chmod 644 /var/lib/libvirt/network/ens4f0.xml [root@rhel-tiger-14-6 ~]# cat /var/lib/libvirt/network/ens4f0.xml <network> <name>ens4f0-pool</name> <forward mode='hostdev' managed='yes'> <pf dev=ens4f0/> </forward> </network> [root@rhel-tiger-14-6 ~]# virsh net-define /var/lib/libvirt/network/ens4f0.xml Network ens4f0-pool defined from /var/lib/libvirt/network/ens4f0.xml [root@rhel-tiger-14-6 ~]# virsh net-autostart ens4f0-pool Network ens4f0-pool marked as autostarted [root@rhel-tiger-14-6 ~]# virsh net-start ens4f0-pool Network ens4f0-pool started [root@rhel-tiger-14-6 libvirt]# virsh net-list Name State Autostart Persistent ------------------------------------------------ default active yes yes ens4f0-pool active yes yes ens4f1-pool active yes yes ens4f2-pool active yes yes ens4f3-pool active yes yes ens5f0-pool active yes yes ens5f1-pool active yes yes ens5f2-pool active yes yes ens5f3-pool active yes yes [root@rhel-tiger-14-6 ~]# virsh net-dumpxml ens4f0-pool <network> <name>ens4f0-pool</name> <uuid>bcb39207-503f-4af8-824c-45bf3756facf</uuid> <forward mode='hostdev' managed='yes'> <pf dev='ens4f0'/> <address type='pci' domain='0x0000' bus='0xaf' slot='0x02' function='0x0'/> <address type='pci' domain='0x0000' bus='0xaf' slot='0x02' function='0x1'/> </forward> </network>
Because these networks are configured as autostart, you must ensure that the VFs have been created before the libvirtd service is started.