From 3a96a003628b734d7b2439971899b0de5d00882e Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 20 Nov 2023 15:03:36 +0100 Subject: [PATCH] Simplify meta device discovery Signed-off-by: Evan Lezar --- internal/discover/char_devices.go | 13 +++---------- internal/discover/gds.go | 12 ++++++------ internal/discover/graphics.go | 6 +----- internal/discover/mofed.go | 4 ++-- internal/platform-support/tegra/csv.go | 3 +-- pkg/nvcdi/common-nvml.go | 7 +------ pkg/nvcdi/device-wsl.go | 2 +- pkg/nvcdi/full-gpu-nvml.go | 2 +- pkg/nvcdi/management.go | 2 +- pkg/nvcdi/mig-device-nvml.go | 2 +- 10 files changed, 18 insertions(+), 35 deletions(-) diff --git a/internal/discover/char_devices.go b/internal/discover/char_devices.go index 715d979a..8d59430d 100644 --- a/internal/discover/char_devices.go +++ b/internal/discover/char_devices.go @@ -27,20 +27,13 @@ type charDevices mounts var _ Discover = (*charDevices)(nil) // 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( lookup.WithLogger(logger), - lookup.WithRoot(root), + lookup.WithRoot(devRoot), ) - return NewDeviceDiscoverer(logger, locator, root, 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) + return (*charDevices)(newMounts(logger, locator, devRoot, devices)) } // Mounts returns the discovered mounts for the charDevices. diff --git a/internal/discover/gds.go b/internal/discover/gds.go index c0307f26..cf762cd8 100644 --- a/internal/discover/gds.go +++ b/internal/discover/gds.go @@ -29,17 +29,17 @@ type gdsDeviceDiscoverer struct { } // 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( logger, + devRoot, []string{"/dev/nvidia-fs*"}, - root, ) udev := NewMounts( logger, - lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(root)), - root, + lookup.NewDirectoryLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)), + driverRoot, []string{"/run/udev"}, ) @@ -47,9 +47,9 @@ func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) { logger, lookup.NewFileLocator( lookup.WithLogger(logger), - lookup.WithRoot(root), + lookup.WithRoot(driverRoot), ), - root, + driverRoot, []string{"/etc/cufile.json"}, ) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index d70d4738..53b9a343 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -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. func newDRMDeviceDiscoverer(logger logger.Interface, devices image.VisibleDevices, devRoot string) (Discover, error) { - allDevices := NewDeviceDiscoverer( + allDevices := NewCharDeviceDiscoverer( logger, - lookup.NewCharDeviceLocator( - lookup.WithLogger(logger), - lookup.WithRoot(devRoot), - ), devRoot, []string{ "/dev/dri/card*", diff --git a/internal/discover/mofed.go b/internal/discover/mofed.go index c893db3b..b9ff4153 100644 --- a/internal/discover/mofed.go +++ b/internal/discover/mofed.go @@ -19,14 +19,14 @@ package discover import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" // 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( logger, + devRoot, []string{ "/dev/infiniband/uverbs*", "/dev/infiniband/rdma_cm", }, - root, ) return devices, nil diff --git a/internal/platform-support/tegra/csv.go b/internal/platform-support/tegra/csv.go index ff2f4932..161e6a7a 100644 --- a/internal/platform-support/tegra/csv.go +++ b/internal/platform-support/tegra/csv.go @@ -36,9 +36,8 @@ func (o tegraOptions) newDiscovererFromCSVFiles() (discover.Discover, error) { targetsByType := getTargetsFromCSVFiles(o.logger, o.csvFiles) - devices := discover.NewDeviceDiscoverer( + devices := discover.NewCharDeviceDiscoverer( o.logger, - lookup.NewCharDeviceLocator(lookup.WithLogger(o.logger), lookup.WithRoot(o.driverRoot)), o.driverRoot, targetsByType[csv.MountSpecDev], ) diff --git a/pkg/nvcdi/common-nvml.go b/pkg/nvcdi/common-nvml.go index f7a22c8a..a33cfc61 100644 --- a/pkg/nvcdi/common-nvml.go +++ b/pkg/nvcdi/common-nvml.go @@ -20,18 +20,13 @@ import ( "fmt" "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. // This includes driver libraries and meta devices, for example. func (l *nvmllib) newCommonNVMLDiscoverer() (discover.Discover, error) { - metaDevices := discover.NewDeviceDiscoverer( + metaDevices := discover.NewCharDeviceDiscoverer( l.logger, - lookup.NewCharDeviceLocator( - lookup.WithLogger(l.logger), - lookup.WithRoot(l.devRoot), - ), l.devRoot, []string{ "/dev/nvidia-modeset", diff --git a/pkg/nvcdi/device-wsl.go b/pkg/nvcdi/device-wsl.go index b1d93468..0f9e1ffd 100644 --- a/pkg/nvcdi/device-wsl.go +++ b/pkg/nvcdi/device-wsl.go @@ -29,8 +29,8 @@ const ( func newDXGDeviceDiscoverer(logger logger.Interface, devRoot string) discover.Discover { deviceNodes := discover.NewCharDeviceDiscoverer( logger, - []string{dxgDeviceNode}, devRoot, + []string{dxgDeviceNode}, ) return deviceNodes diff --git a/pkg/nvcdi/full-gpu-nvml.go b/pkg/nvcdi/full-gpu-nvml.go index f22e449c..d47c802d 100644 --- a/pkg/nvcdi/full-gpu-nvml.go +++ b/pkg/nvcdi/full-gpu-nvml.go @@ -103,8 +103,8 @@ func newFullGPUDiscoverer(logger logger.Interface, devRoot string, nvidiaCTKPath deviceNodes := discover.NewCharDeviceDiscoverer( logger, - deviceNodePaths, devRoot, + deviceNodePaths, ) byPathHooks := &byPathHookDiscoverer{ diff --git a/pkg/nvcdi/management.go b/pkg/nvcdi/management.go index 8050a5b6..9352e110 100644 --- a/pkg/nvcdi/management.go +++ b/pkg/nvcdi/management.go @@ -109,6 +109,7 @@ type managementDiscoverer struct { func (m *managementlib) newManagementDeviceDiscoverer() (discover.Discover, error) { deviceNodes := discover.NewCharDeviceDiscoverer( m.logger, + m.devRoot, []string{ "/dev/nvidia*", "/dev/nvidia-caps/nvidia-cap*", @@ -117,7 +118,6 @@ func (m *managementlib) newManagementDeviceDiscoverer() (discover.Discover, erro "/dev/nvidia-uvm", "/dev/nvidiactl", }, - m.devRoot, ) deviceFolderPermissionHooks := newDeviceFolderPermissionHookDiscoverer( diff --git a/pkg/nvcdi/mig-device-nvml.go b/pkg/nvcdi/mig-device-nvml.go index a442a738..db8601d9 100644 --- a/pkg/nvcdi/mig-device-nvml.go +++ b/pkg/nvcdi/mig-device-nvml.go @@ -112,12 +112,12 @@ func newComputeInstanceDiscoverer(logger logger.Interface, driverRoot string, gp deviceNodes := discover.NewCharDeviceDiscoverer( logger, + driverRoot, []string{ parentPath, giCapDevicePath, ciCapDevicePath, }, - driverRoot, ) return deviceNodes, nil