Add GetGPUByPciBusID to nvpci.Interface

This change adds a GetGPUByPciBusID method to the nvpci Interface.
The exising NewDevice function is moved to nvmdev where it is used.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2022-11-15 14:29:32 +01:00
parent 0e8a479bd5
commit e96d9c58f1
2 changed files with 18 additions and 9 deletions

View File

@@ -18,13 +18,14 @@ package nvmdev
import (
"fmt"
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvpci"
"os"
"path"
"path/filepath"
"sort"
"strconv"
"strings"
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvpci"
)
const (
@@ -241,7 +242,7 @@ func (m mdev) iommuGroup() (int, error) {
// NewParentDevice constructs a ParentDevice
func NewParentDevice(devicePath string) (*ParentDevice, error) {
nvdevice, err := nvpci.NewDevice(devicePath)
nvdevice, err := newNvidiaPCIDeviceFromPath(devicePath)
if err != nil {
return nil, fmt.Errorf("failed to construct NVIDIA PCI device: %v", err)
}
@@ -330,7 +331,7 @@ func (p *ParentDevice) GetPhysicalFunction() (*nvpci.NvidiaPCIDevice, error) {
return nil, fmt.Errorf("unable to resolve %s: %v", path.Join(p.Path, "physfn"), err)
}
return nvpci.NewDevice(physfnPath)
return newNvidiaPCIDeviceFromPath(physfnPath)
}
// GetPhysicalFunction gets the physical PCI device that a vGPU is created on
@@ -374,3 +375,10 @@ 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.NewFrom(root).GetGPUByPciBusID(address)
}