mirror of
https://github.com/clearml/go-nvlib
synced 2025-06-26 18:28:08 +00:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user