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:
Christopher Desiniotis
2022-07-08 11:53:03 -07:00
parent d65cf69086
commit 805db5afa8
3 changed files with 23 additions and 13 deletions

View File

@@ -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)
}