From 255181a5ff0b171a0eae191d4e31454030b98e09 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 20 Nov 2023 22:32:46 +0100 Subject: [PATCH] Rename NewGraphicsDiscoverer as NewDRMNodesDiscoverer This change renames NewGraphicsDiscoverer to NewDRMNodesDiscoverer and instead calls NewGraphicsMountsDiscoverer explicitly when constructing a graphics modifier. This avoids the import of config.Config into the discover package which leads to a transitive dependency on toml-specifics and requires that the vendor/github.com/pelletier/ package be vendored in to consumers. Signed-off-by: Evan Lezar --- internal/discover/graphics.go | 25 +++++++------------------ internal/modifier/graphics.go | 23 +++++++++++++++++++++-- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 53b9a343..73145c89 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -22,7 +22,6 @@ import ( "path/filepath" "strings" - "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" "github.com/NVIDIA/nvidia-container-toolkit/internal/info/drm" "github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc" @@ -31,18 +30,12 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda" ) -// NewGraphicsDiscoverer returns the discoverer for graphics tools such as Vulkan. -func NewGraphicsDiscoverer(logger logger.Interface, cfg *config.Config, devices image.VisibleDevices) (Discover, error) { - driverRoot := cfg.NVIDIAContainerCLIConfig.Root - // In standard usage, the devRoot is the same as the driverRoot. - devRoot := driverRoot - nvidiaCTKPath := cfg.NVIDIACTKConfig.Path - - mounts, err := NewGraphicsMountsDiscoverer(logger, driverRoot, nvidiaCTKPath) - if err != nil { - return nil, fmt.Errorf("failed to create mounts discoverer: %v", err) - } - +// NewDRMNodesDiscoverer returns a discoverrer for the DRM device nodes associated with the specified visible devices. +// +// TODO: The logic for creating DRM devices should be consolidated between this +// and the logic for generating CDI specs for a single device. This is only used +// when applying OCI spec modifications to an incoming spec in "legacy" mode. +func NewDRMNodesDiscoverer(logger logger.Interface, devices image.VisibleDevices, devRoot string, nvidiaCTKPath string) (Discover, error) { drmDeviceNodes, err := newDRMDeviceDiscoverer(logger, devices, devRoot) if err != nil { return nil, fmt.Errorf("failed to create DRM device discoverer: %v", err) @@ -50,11 +43,7 @@ func NewGraphicsDiscoverer(logger logger.Interface, cfg *config.Config, devices drmByPathSymlinks := newCreateDRMByPathSymlinks(logger, drmDeviceNodes, devRoot, nvidiaCTKPath) - discover := Merge( - Merge(drmDeviceNodes, drmByPathSymlinks), - mounts, - ) - + discover := Merge(drmDeviceNodes, drmByPathSymlinks) return discover, nil } diff --git a/internal/modifier/graphics.go b/internal/modifier/graphics.go index 2852ba2c..b4cbb1f6 100644 --- a/internal/modifier/graphics.go +++ b/internal/modifier/graphics.go @@ -34,15 +34,34 @@ func NewGraphicsModifier(logger logger.Interface, cfg *config.Config, image imag return nil, nil } - d, err := discover.NewGraphicsDiscoverer( + driverRoot := cfg.NVIDIAContainerCLIConfig.Root + nvidiaCTKPath := cfg.NVIDIACTKConfig.Path + + mounts, err := discover.NewGraphicsMountsDiscoverer( + logger, + driverRoot, + nvidiaCTKPath, + ) + if err != nil { + return nil, fmt.Errorf("failed to create mounts discoverer: %v", err) + } + + // In standard usage, the devRoot is the same as the driverRoot. + devRoot := driverRoot + drmNodes, err := discover.NewDRMNodesDiscoverer( logger, - cfg, image.DevicesFromEnvvars(visibleDevicesEnvvar), + devRoot, + nvidiaCTKPath, ) if err != nil { return nil, fmt.Errorf("failed to construct discoverer: %v", err) } + d := discover.Merge( + drmNodes, + mounts, + ) return NewModifierFromDiscoverer(logger, d) }