From 44a5440a0abe8cd17f7d00d7a52d1b80e6f0667c Mon Sep 17 00:00:00 2001 From: Christopher Desiniotis Date: Mon, 15 Jul 2024 12:06:52 -0700 Subject: [PATCH] [nvmdev] fix bug in construction of parent PCI device When constructing NvidiaPCIDevice objects for each 'parent' device in the '/sys/class/mdev_bus' directory, use the default PCI devices root '/sys/bus/pci/devices'. All devices in '/sys/class/mdev_bus' will have a corresponding directory at '/sys/bus/pci/devices'. Starting with https://github.com/NVIDIA/go-nvlib/commit/bf3f431fc86e4ab07c782e2a0d1e2855f8352c3e0 the construction of the NvidiaPCIDevice object will fail when attempting to detect the physfn. When SRIOV is used, all the VFs will show up under '/sys/class/mdev_bus', but the physfn will only show up under '/sys/bus/pci/devices'. Signed-off-by: Christopher Desiniotis --- pkg/nvmdev/nvmdev.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pkg/nvmdev/nvmdev.go b/pkg/nvmdev/nvmdev.go index 33f2d5a..0cc2101 100644 --- a/pkg/nvmdev/nvmdev.go +++ b/pkg/nvmdev/nvmdev.go @@ -242,7 +242,8 @@ func (m mdev) iommuGroup() (int, error) { // NewParentDevice constructs a ParentDevice. func NewParentDevice(devicePath string) (*ParentDevice, error) { - nvdevice, err := newNvidiaPCIDeviceFromPath(devicePath) + address := filepath.Base(devicePath) + nvdevice, err := nvpci.New().GetGPUByPciBusID(address) if err != nil { return nil, fmt.Errorf("failed to construct NVIDIA PCI device: %v", err) } @@ -370,12 +371,3 @@ func (p *ParentDevice) GetAvailableMDEVInstances(mdevType string) (int, error) { return availableInstances, nil } - -// newNvidiaPCIDeviceFromPath constructs an NvidiaPCIDevice for the specified device path. -func newNvidiaPCIDeviceFromPath(devicePath string) (*nvpci.NvidiaPCIDevice, error) { - root := filepath.Dir(devicePath) - address := filepath.Base(devicePath) - return nvpci.New( - nvpci.WithPCIDevicesRoot(root), - ).GetGPUByPciBusID(address) -}