mirror of
https://github.com/clearml/go-nvlib
synced 2025-06-26 18:28:08 +00:00
Refactor how mdev's are represented internally in nvmdev.
The 'mdev' string now represents the absolute path to an mdev device (/sys/bus/pci/devices/<addr>/<uuid>) instead of the mdev_type directory for the mdev device (/sys/bus/pci/devices/<addr>/mdev_supported_types/<mdev-type>). This is more intuitive and will make it easier to get more information about a particular mdev device - like the driver or iommu_group it belongs to - which can be found at /sys/bus/pci/devices/<addr>/<uuid>. Signed-off-by: Christopher Desiniotis <cdesiniotis@nvidia.com>
This commit is contained in:
@@ -153,27 +153,33 @@ func NewDevice(root string, uuid string) (*Device, error) {
|
||||
return &device, nil
|
||||
}
|
||||
|
||||
// mdev represents the path to an NVIDIA mdev (vGPU) device.
|
||||
type mdev string
|
||||
|
||||
func newMdev(devicePath string) (mdev, error) {
|
||||
mdevTypeDir, err := filepath.EvalSymlinks(path.Join(devicePath, "mdev_type"))
|
||||
mdevDir, err := filepath.EvalSymlinks(devicePath)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error resolving mdev_type link: %v", err)
|
||||
return "", fmt.Errorf("error resolving symlink for %s: %v", devicePath, err)
|
||||
}
|
||||
|
||||
return mdev(mdevTypeDir), nil
|
||||
return mdev(mdevDir), nil
|
||||
}
|
||||
|
||||
func (m mdev) String() string {
|
||||
return string(m)
|
||||
}
|
||||
func (m mdev) parentDevicePath() string {
|
||||
// /sys/bus/pci/devices/<addr>/mdev_supported_types/<mdev_type>
|
||||
return path.Dir(path.Dir(string(m)))
|
||||
// /sys/bus/pci/devices/<addr>/<uuid>
|
||||
return path.Dir(string(m))
|
||||
}
|
||||
|
||||
func (m mdev) Type() (string, error) {
|
||||
mdevType, err := os.ReadFile(path.Join(string(m), "name"))
|
||||
mdevTypeDir, err := filepath.EvalSymlinks(path.Join(string(m), "mdev_type"))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error resolving mdev_type link for mdev %s: %v", m, err)
|
||||
}
|
||||
|
||||
mdevType, err := os.ReadFile(path.Join(mdevTypeDir, "name"))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unable to read mdev_type name for mdev %s: %v", m, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user