Merge pull request #327 from elezar/add-driver-config

Add config search path option to driver root
This commit is contained in:
Evan Lezar 2024-04-11 16:58:33 +02:00 committed by GitHub
commit 29c0f82ed2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 43 additions and 10 deletions

View File

@ -53,6 +53,7 @@ type options struct {
vendor string vendor string
class string class string
configSearchPaths cli.StringSlice
librarySearchPaths cli.StringSlice librarySearchPaths cli.StringSlice
csv struct { csv struct {
@ -86,6 +87,11 @@ func (m command) build() *cli.Command {
} }
c.Flags = []cli.Flag{ 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{ &cli.StringFlag{
Name: "output", Name: "output",
Usage: "Specify the file to output the generated CDI specification to. If this is '' the specification is output to STDOUT", 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.WithLdconfigPath(opts.ldconfigPath),
nvcdi.WithDeviceNamers(deviceNamers...), nvcdi.WithDeviceNamers(deviceNamers...),
nvcdi.WithMode(opts.mode), nvcdi.WithMode(opts.mode),
nvcdi.WithConfigSearchPaths(opts.configSearchPaths.Value()),
nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()), nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()),
nvcdi.WithCSVFiles(opts.csv.files.Value()), nvcdi.WithCSVFiles(opts.csv.files.Value()),
nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()), nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()),

View File

@ -61,11 +61,7 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n
jsonMounts := NewMounts( jsonMounts := NewMounts(
logger, logger,
lookup.NewFileLocator( driver.Configs(),
lookup.WithLogger(logger),
lookup.WithRoot(driver.Root),
lookup.WithSearchPaths("/etc", "/usr/share"),
),
driver.Root, driver.Root,
[]string{ []string{
"glvnd/egl_vendor.d/10_nvidia.json", "glvnd/egl_vendor.d/10_nvidia.json",
@ -292,11 +288,7 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa
xorgConfig := NewMounts( xorgConfig := NewMounts(
logger, logger,
lookup.NewFileLocator( driver.Configs(),
lookup.WithLogger(logger),
lookup.WithRoot(driver.Root),
lookup.WithSearchPaths("/usr/share"),
),
driver.Root, driver.Root,
[]string{"X11/xorg.conf.d/10-nvidia.conf"}, []string{"X11/xorg.conf.d/10-nvidia.conf"},
) )

View File

@ -37,3 +37,9 @@ func WithLibrarySearchPaths(paths ...string) Option {
d.librarySearchPaths = paths d.librarySearchPaths = paths
} }
} }
func WithConfigSearchPaths(paths ...string) Option {
return func(d *Driver) {
d.configSearchPaths = paths
}
}

View File

@ -30,6 +30,8 @@ type Driver struct {
Root string Root string
// librarySearchPaths specifies explicit search paths for discovering libraries. // librarySearchPaths specifies explicit search paths for discovering libraries.
librarySearchPaths []string librarySearchPaths []string
// configSearchPaths specified explicit search paths for discovering driver config files.
configSearchPaths []string
} }
// New creates a new Driver root using the specified options. // New creates a new Driver root using the specified options.
@ -53,6 +55,24 @@ 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(searchRoot),
lookup.WithSearchPaths(searchPaths...),
)
}
// normalizeSearchPaths takes a list of paths and normalized these. // 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 // Each of the elements in the list is expanded if it is a path list and the
// resultant list is returned. // resultant list is returned.

View File

@ -50,6 +50,7 @@ type nvcdilib struct {
devRoot string devRoot string
nvidiaCTKPath string nvidiaCTKPath string
ldconfigPath string ldconfigPath string
configSearchPaths []string
librarySearchPaths []string librarySearchPaths []string
csvFiles []string csvFiles []string

View File

@ -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. // WithLibrarySearchPaths sets the library search paths.
// This is currently only used for CSV-mode. // This is currently only used for CSV-mode.
func WithLibrarySearchPaths(paths []string) Option { func WithLibrarySearchPaths(paths []string) Option {