From 643b89e53947293be675302074fb17eeb23c6239 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 22 Nov 2023 21:57:03 +0100 Subject: [PATCH 1/2] Add driver.Config Signed-off-by: Evan Lezar --- internal/discover/graphics.go | 12 ++---------- internal/lookup/root/root.go | 9 +++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 0a8ff8d2..35b51982 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -61,11 +61,7 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n jsonMounts := NewMounts( logger, - lookup.NewFileLocator( - lookup.WithLogger(logger), - lookup.WithRoot(driver.Root), - lookup.WithSearchPaths("/etc", "/usr/share"), - ), + driver.Configs(), driver.Root, []string{ "glvnd/egl_vendor.d/10_nvidia.json", @@ -292,11 +288,7 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa xorgConfig := NewMounts( logger, - lookup.NewFileLocator( - lookup.WithLogger(logger), - lookup.WithRoot(driver.Root), - lookup.WithSearchPaths("/usr/share"), - ), + driver.Configs(), driver.Root, []string{"X11/xorg.conf.d/10-nvidia.conf"}, ) diff --git a/internal/lookup/root/root.go b/internal/lookup/root/root.go index 82ea7cb5..89754618 100644 --- a/internal/lookup/root/root.go +++ b/internal/lookup/root/root.go @@ -53,6 +53,15 @@ func (r *Driver) Libraries() lookup.Locator { ) } +// Configs returns a locator for driver configs. +func (r *Driver) Configs() lookup.Locator { + return lookup.NewFileLocator( + lookup.WithLogger(r.logger), + lookup.WithRoot(r.Root), + lookup.WithSearchPaths("/etc", "/usr/share"), + ) +} + // normalizeSearchPaths takes a list of paths and normalized these. // Each of the elements in the list is expanded if it is a path list and the // resultant list is returned. From 2a9e3537ecb7ad10c86cd623fd3fa5a47a41a09f Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 24 Nov 2023 16:45:19 +0100 Subject: [PATCH 2/2] Add config search paths option to driver root. Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 7 +++++++ internal/lookup/root/options.go | 6 ++++++ internal/lookup/root/root.go | 15 +++++++++++++-- pkg/nvcdi/lib.go | 1 + pkg/nvcdi/options.go | 7 +++++++ 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index f3758176..5653b342 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -53,6 +53,7 @@ type options struct { vendor string class string + configSearchPaths cli.StringSlice librarySearchPaths cli.StringSlice csv struct { @@ -86,6 +87,11 @@ func (m command) build() *cli.Command { } c.Flags = []cli.Flag{ + &cli.StringSliceFlag{ + Name: "config-search-path", + Usage: "Specify the path to search for config files when discovering the entities that should be included in the CDI specification.", + Destination: &opts.configSearchPaths, + }, &cli.StringFlag{ Name: "output", Usage: "Specify the file to output the generated CDI specification to. If this is '' the specification is output to STDOUT", @@ -260,6 +266,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) { nvcdi.WithLdconfigPath(opts.ldconfigPath), nvcdi.WithDeviceNamers(deviceNamers...), nvcdi.WithMode(opts.mode), + nvcdi.WithConfigSearchPaths(opts.configSearchPaths.Value()), nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()), nvcdi.WithCSVFiles(opts.csv.files.Value()), nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()), diff --git a/internal/lookup/root/options.go b/internal/lookup/root/options.go index 5774544e..6bffe3d8 100644 --- a/internal/lookup/root/options.go +++ b/internal/lookup/root/options.go @@ -37,3 +37,9 @@ func WithLibrarySearchPaths(paths ...string) Option { d.librarySearchPaths = paths } } + +func WithConfigSearchPaths(paths ...string) Option { + return func(d *Driver) { + d.configSearchPaths = paths + } +} diff --git a/internal/lookup/root/root.go b/internal/lookup/root/root.go index 89754618..1d1abe01 100644 --- a/internal/lookup/root/root.go +++ b/internal/lookup/root/root.go @@ -30,6 +30,8 @@ type Driver struct { Root string // librarySearchPaths specifies explicit search paths for discovering libraries. librarySearchPaths []string + // configSearchPaths specified explicit search paths for discovering driver config files. + configSearchPaths []string } // New creates a new Driver root using the specified options. @@ -54,11 +56,20 @@ func (r *Driver) Libraries() lookup.Locator { } // Configs returns a locator for driver configs. +// If configSearchPaths is specified, these paths are used as absolute paths, +// otherwise, /etc and /usr/share are searched. func (r *Driver) Configs() lookup.Locator { + searchRoot := r.Root + searchPaths := []string{"/etc", "/usr/share"} + if len(r.configSearchPaths) > 0 { + searchRoot = "/" + searchPaths = normalizeSearchPaths(r.configSearchPaths...) + } + return lookup.NewFileLocator( lookup.WithLogger(r.logger), - lookup.WithRoot(r.Root), - lookup.WithSearchPaths("/etc", "/usr/share"), + lookup.WithRoot(searchRoot), + lookup.WithSearchPaths(searchPaths...), ) } diff --git a/pkg/nvcdi/lib.go b/pkg/nvcdi/lib.go index b450956f..ad75a239 100644 --- a/pkg/nvcdi/lib.go +++ b/pkg/nvcdi/lib.go @@ -50,6 +50,7 @@ type nvcdilib struct { devRoot string nvidiaCTKPath string ldconfigPath string + configSearchPaths []string librarySearchPaths []string csvFiles []string diff --git a/pkg/nvcdi/options.go b/pkg/nvcdi/options.go index 388bb0a2..a4e49b60 100644 --- a/pkg/nvcdi/options.go +++ b/pkg/nvcdi/options.go @@ -126,6 +126,13 @@ func WithCSVIgnorePatterns(csvIgnorePatterns []string) Option { } } +// WithConfigSearchPaths sets the search paths for config files. +func WithConfigSearchPaths(paths []string) Option { + return func(o *nvcdilib) { + o.configSearchPaths = paths + } +} + // WithLibrarySearchPaths sets the library search paths. // This is currently only used for CSV-mode. func WithLibrarySearchPaths(paths []string) Option {