Skip to content

Commit 211ab3f

Browse files
committed
Add helper function for virtual environments to find vfs
Signed-off-by: Sebastian Sch <sebassch@gmail.com>
1 parent 4c5f5af commit 211ab3f

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

pkg/helper/mock/mock_helper.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/host/internal/sriov/sriov.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,63 @@ func (s *sriov) DiscoverSriovDevices(storeManager store.ManagerInterface) ([]sri
311311
return pfList, nil
312312
}
313313

314+
func (s *sriov) DiscoverSriovVirtualDevices() ([]sriovnetworkv1.InterfaceExt, error) {
315+
log.Log.V(2).Info("DiscoverSriovVirtualDevices()")
316+
pfList := []sriovnetworkv1.InterfaceExt{}
317+
318+
pci, err := s.ghwLib.PCI()
319+
if err != nil {
320+
return nil, fmt.Errorf("DiscoverSriovVirtualDevices(): error getting PCI info: %v", err)
321+
}
322+
323+
devices := pci.Devices
324+
if len(devices) == 0 {
325+
return nil, fmt.Errorf("DiscoverSriovVirtualDevices(): could not retrieve PCI devices")
326+
}
327+
328+
for _, device := range devices {
329+
devClass, err := strconv.ParseInt(device.Class.ID, 16, 64)
330+
if err != nil {
331+
log.Log.Error(err, "DiscoverSriovVirtualDevices(): unable to parse device class for device, skipping",
332+
"device", device)
333+
continue
334+
}
335+
if devClass != consts.NetClass {
336+
// Not network device
337+
continue
338+
}
339+
340+
driver, err := s.dputilsLib.GetDriverName(device.Address)
341+
if err != nil {
342+
log.Log.Error(err, "DiscoverSriovVirtualDevices(): unable to parse device driver for device, skipping",
343+
"device", device)
344+
continue
345+
}
346+
iface := sriovnetworkv1.InterfaceExt{
347+
PciAddress: device.Address,
348+
Driver: driver,
349+
Vendor: device.Vendor.ID,
350+
DeviceID: device.Product.ID,
351+
}
352+
353+
if mtu := s.networkHelper.GetNetdevMTU(device.Address); mtu > 0 {
354+
iface.Mtu = mtu
355+
}
356+
if name := s.networkHelper.TryToGetVirtualInterfaceName(device.Address); name != "" {
357+
iface.Name = name
358+
if macAddr := s.networkHelper.GetNetDevMac(name); macAddr != "" {
359+
iface.Mac = macAddr
360+
}
361+
iface.LinkSpeed = s.networkHelper.GetNetDevLinkSpeed(name)
362+
iface.LinkType = s.GetLinkType(name)
363+
}
364+
365+
pfList = append(pfList, iface)
366+
}
367+
368+
return pfList, nil
369+
}
370+
314371
func (s *sriov) configSriovPFDevice(iface *sriovnetworkv1.Interface) error {
315372
log.Log.V(2).Info("configSriovPFDevice(): configure PF sriov device",
316373
"device", iface.PciAddress)

pkg/host/mock/mock_host.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/host/types/interfaces.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ type SriovInterface interface {
136136
ResetSriovDevice(ifaceStatus sriovnetworkv1.InterfaceExt) error
137137
// DiscoverSriovDevices returns a list of all the available SR-IOV capable network interfaces on the system
138138
DiscoverSriovDevices(storeManager store.ManagerInterface) ([]sriovnetworkv1.InterfaceExt, error)
139+
// DiscoverSriovVirtualDevices returns a list of all the available SR-IOV VF network interfaces on the system.
140+
// Only supported on virtual environments where we don't have the physical function.
141+
DiscoverSriovVirtualDevices() ([]sriovnetworkv1.InterfaceExt, error)
139142
// ConfigSriovInterfaces configure multiple SR-IOV devices with the desired configuration
140143
// if skipVFConfiguration flag is set, the function will configure PF and create VFs on it, but will skip VFs configuration
141144
ConfigSriovInterfaces(storeManager store.ManagerInterface, interfaces []sriovnetworkv1.Interface,

0 commit comments

Comments
 (0)