Simplify meta device discovery

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-11-20 15:03:36 +01:00
parent 00a712d018
commit 3a96a00362
10 changed files with 18 additions and 35 deletions

View File

@ -27,20 +27,13 @@ type charDevices mounts
var _ Discover = (*charDevices)(nil) var _ Discover = (*charDevices)(nil)
// NewCharDeviceDiscoverer creates a discoverer which locates the specified set of device nodes. // NewCharDeviceDiscoverer creates a discoverer which locates the specified set of device nodes.
func NewCharDeviceDiscoverer(logger logger.Interface, devices []string, root string) Discover { func NewCharDeviceDiscoverer(logger logger.Interface, devRoot string, devices []string) Discover {
locator := lookup.NewCharDeviceLocator( locator := lookup.NewCharDeviceLocator(
lookup.WithLogger(logger), lookup.WithLogger(logger),
lookup.WithRoot(root), lookup.WithRoot(devRoot),
) )
return NewDeviceDiscoverer(logger, locator, root, devices) return (*charDevices)(newMounts(logger, locator, devRoot, devices))
}
// NewDeviceDiscoverer creates a discoverer which locates the specified set of device nodes using the specified locator.
func NewDeviceDiscoverer(logger logger.Interface, locator lookup.Locator, root string, devices []string) Discover {
m := NewMounts(logger, locator, root, devices).(*mounts)
return (*charDevices)(m)
} }
// Mounts returns the discovered mounts for the charDevices. // Mounts returns the discovered mounts for the charDevices.

View File

@ -29,17 +29,17 @@ type gdsDeviceDiscoverer struct {
} }
// NewGDSDiscoverer creates a discoverer for GPUDirect Storage devices and mounts. // NewGDSDiscoverer creates a discoverer for GPUDirect Storage devices and mounts.
func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) { func NewGDSDiscoverer(logger logger.Interface, driverRoot string, devRoot string) (Discover, error) {
devices := NewCharDeviceDiscoverer( devices := NewCharDeviceDiscoverer(
logger, logger,
devRoot,
[]string{"/dev/nvidia-fs*"}, []string{"/dev/nvidia-fs*"},
root,
) )
udev := NewMounts( udev := NewMounts(
logger, logger,
lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(root)), lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)),
root, driverRoot,
[]string{"/run/udev"}, []string{"/run/udev"},
) )
@ -47,9 +47,9 @@ func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) {
logger, logger,
lookup.NewFileLocator( lookup.NewFileLocator(
lookup.WithLogger(logger), lookup.WithLogger(logger),
lookup.WithRoot(root), lookup.WithRoot(driverRoot),
), ),
root, driverRoot,
[]string{"/etc/cufile.json"}, []string{"/etc/cufile.json"},
) )

View File

@ -188,12 +188,8 @@ func (d drmDevicesByPath) getSpecificLinkArgs(devices []Device) ([]string, error
// newDRMDeviceDiscoverer creates a discoverer for the DRM devices associated with the requested devices. // newDRMDeviceDiscoverer creates a discoverer for the DRM devices associated with the requested devices.
func newDRMDeviceDiscoverer(logger logger.Interface, devices image.VisibleDevices, devRoot string) (Discover, error) { func newDRMDeviceDiscoverer(logger logger.Interface, devices image.VisibleDevices, devRoot string) (Discover, error) {
allDevices := NewDeviceDiscoverer( allDevices := NewCharDeviceDiscoverer(
logger, logger,
lookup.NewCharDeviceLocator(
lookup.WithLogger(logger),
lookup.WithRoot(devRoot),
),
devRoot, devRoot,
[]string{ []string{
"/dev/dri/card*", "/dev/dri/card*",

View File

@ -19,14 +19,14 @@ package discover
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
// NewMOFEDDiscoverer creates a discoverer for MOFED devices. // NewMOFEDDiscoverer creates a discoverer for MOFED devices.
func NewMOFEDDiscoverer(logger logger.Interface, root string) (Discover, error) { func NewMOFEDDiscoverer(logger logger.Interface, devRoot string) (Discover, error) {
devices := NewCharDeviceDiscoverer( devices := NewCharDeviceDiscoverer(
logger, logger,
devRoot,
[]string{ []string{
"/dev/infiniband/uverbs*", "/dev/infiniband/uverbs*",
"/dev/infiniband/rdma_cm", "/dev/infiniband/rdma_cm",
}, },
root,
) )
return devices, nil return devices, nil

View File

@ -36,9 +36,8 @@ func (o tegraOptions) newDiscovererFromCSVFiles() (discover.Discover, error) {
targetsByType := getTargetsFromCSVFiles(o.logger, o.csvFiles) targetsByType := getTargetsFromCSVFiles(o.logger, o.csvFiles)
devices := discover.NewDeviceDiscoverer( devices := discover.NewCharDeviceDiscoverer(
o.logger, o.logger,
lookup.NewCharDeviceLocator(lookup.WithLogger(o.logger), lookup.WithRoot(o.driverRoot)),
o.driverRoot, o.driverRoot,
targetsByType[csv.MountSpecDev], targetsByType[csv.MountSpecDev],
) )

View File

@ -20,18 +20,13 @@ import (
"fmt" "fmt"
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
) )
// newCommonNVMLDiscoverer returns a discoverer for entities that are not associated with a specific CDI device. // newCommonNVMLDiscoverer returns a discoverer for entities that are not associated with a specific CDI device.
// This includes driver libraries and meta devices, for example. // This includes driver libraries and meta devices, for example.
func (l *nvmllib) newCommonNVMLDiscoverer() (discover.Discover, error) { func (l *nvmllib) newCommonNVMLDiscoverer() (discover.Discover, error) {
metaDevices := discover.NewDeviceDiscoverer( metaDevices := discover.NewCharDeviceDiscoverer(
l.logger, l.logger,
lookup.NewCharDeviceLocator(
lookup.WithLogger(l.logger),
lookup.WithRoot(l.devRoot),
),
l.devRoot, l.devRoot,
[]string{ []string{
"/dev/nvidia-modeset", "/dev/nvidia-modeset",

View File

@ -29,8 +29,8 @@ const (
func newDXGDeviceDiscoverer(logger logger.Interface, devRoot string) discover.Discover { func newDXGDeviceDiscoverer(logger logger.Interface, devRoot string) discover.Discover {
deviceNodes := discover.NewCharDeviceDiscoverer( deviceNodes := discover.NewCharDeviceDiscoverer(
logger, logger,
[]string{dxgDeviceNode},
devRoot, devRoot,
[]string{dxgDeviceNode},
) )
return deviceNodes return deviceNodes

View File

@ -103,8 +103,8 @@ func newFullGPUDiscoverer(logger logger.Interface, devRoot string, nvidiaCTKPath
deviceNodes := discover.NewCharDeviceDiscoverer( deviceNodes := discover.NewCharDeviceDiscoverer(
logger, logger,
deviceNodePaths,
devRoot, devRoot,
deviceNodePaths,
) )
byPathHooks := &byPathHookDiscoverer{ byPathHooks := &byPathHookDiscoverer{

View File

@ -109,6 +109,7 @@ type managementDiscoverer struct {
func (m *managementlib) newManagementDeviceDiscoverer() (discover.Discover, error) { func (m *managementlib) newManagementDeviceDiscoverer() (discover.Discover, error) {
deviceNodes := discover.NewCharDeviceDiscoverer( deviceNodes := discover.NewCharDeviceDiscoverer(
m.logger, m.logger,
m.devRoot,
[]string{ []string{
"/dev/nvidia*", "/dev/nvidia*",
"/dev/nvidia-caps/nvidia-cap*", "/dev/nvidia-caps/nvidia-cap*",
@ -117,7 +118,6 @@ func (m *managementlib) newManagementDeviceDiscoverer() (discover.Discover, erro
"/dev/nvidia-uvm", "/dev/nvidia-uvm",
"/dev/nvidiactl", "/dev/nvidiactl",
}, },
m.devRoot,
) )
deviceFolderPermissionHooks := newDeviceFolderPermissionHookDiscoverer( deviceFolderPermissionHooks := newDeviceFolderPermissionHookDiscoverer(

View File

@ -112,12 +112,12 @@ func newComputeInstanceDiscoverer(logger logger.Interface, driverRoot string, gp
deviceNodes := discover.NewCharDeviceDiscoverer( deviceNodes := discover.NewCharDeviceDiscoverer(
logger, logger,
driverRoot,
[]string{ []string{
parentPath, parentPath,
giCapDevicePath, giCapDevicePath,
ciCapDevicePath, ciCapDevicePath,
}, },
driverRoot,
) )
return deviceNodes, nil return deviceNodes, nil