mirror of
https://github.com/clearml/go-nvlib
synced 2025-06-26 18:28:08 +00:00
feat: add additinal SRIOV info to NvidiaPciDevice
Signed-off-by: PiotrProkop <pprokop@nvidia.com>
This commit is contained in:
@@ -321,21 +321,16 @@ func (m *Device) Delete() error {
|
||||
}
|
||||
|
||||
// GetPhysicalFunction gets the physical PCI device backing a 'parent' device.
|
||||
func (p *ParentDevice) GetPhysicalFunction() (*nvpci.NvidiaPCIDevice, error) {
|
||||
if !p.IsVF {
|
||||
return p.NvidiaPCIDevice, nil
|
||||
func (p *ParentDevice) GetPhysicalFunction() *nvpci.NvidiaPCIDevice {
|
||||
if p.SriovInfo.IsVF() {
|
||||
return p.SriovInfo.VirtualFunction.PhysicalFunction
|
||||
}
|
||||
|
||||
physfnPath, err := filepath.EvalSymlinks(path.Join(p.Path, "physfn"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to resolve %s: %v", path.Join(p.Path, "physfn"), err)
|
||||
}
|
||||
|
||||
return newNvidiaPCIDeviceFromPath(physfnPath)
|
||||
// Either it is an SRIOV physical function or a non-SRIOV device, so return the device itself
|
||||
return p.NvidiaPCIDevice
|
||||
}
|
||||
|
||||
// GetPhysicalFunction gets the physical PCI device that a vGPU is created on.
|
||||
func (m *Device) GetPhysicalFunction() (*nvpci.NvidiaPCIDevice, error) {
|
||||
func (m *Device) GetPhysicalFunction() *nvpci.NvidiaPCIDevice {
|
||||
return m.Parent.GetPhysicalFunction()
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,7 @@ func TestNvmdev(t *testing.T) {
|
||||
|
||||
parentA100 := parentDevs[0]
|
||||
|
||||
pf, err := parentA100.GetPhysicalFunction()
|
||||
require.Nil(t, err, "Error getting physical function backing the Mock A100 parent device")
|
||||
pf := parentA100.GetPhysicalFunction()
|
||||
require.Equal(t, "0000:3b:04.1", pf.Address, "Wrong address for Mock A100 physical function")
|
||||
|
||||
supported := parentA100.IsMDEVTypeSupported("A100-4C")
|
||||
@@ -59,7 +58,6 @@ func TestNvmdev(t *testing.T) {
|
||||
require.Equal(t, "vfio_mdev", mdevA100.Driver, "Wrong driver detected for mdev device")
|
||||
require.Equal(t, 200, mdevA100.IommuGroup, "Wrong value for iommu_group")
|
||||
|
||||
pf, err = mdevA100.GetPhysicalFunction()
|
||||
require.Nil(t, err, "Error getting the physical function for Mock A100 mediated device")
|
||||
pf = mdevA100.GetPhysicalFunction()
|
||||
require.Equal(t, "0000:3b:04.1", pf.Address, "Wrong address for Mock A100 physical function")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user