Specify library search paths for CSV CDI spec generation

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-07-18 12:02:37 +02:00
parent 03a4e2f8a9
commit 8553fce68a
6 changed files with 45 additions and 15 deletions

View File

@ -51,7 +51,8 @@ type options struct {
class string class string
csv struct { csv struct {
files cli.StringSlice files cli.StringSlice
librarySearchPaths cli.StringSlice
} }
} }
@ -134,6 +135,11 @@ func (m command) build() *cli.Command {
Value: cli.NewStringSlice(csv.DefaultFileList()...), Value: cli.NewStringSlice(csv.DefaultFileList()...),
Destination: &opts.csv.files, Destination: &opts.csv.files,
}, },
&cli.StringSliceFlag{
Name: "csv.library-search-path",
Usage: "Specify the path to search for libraries when discovering the entities that should be included in the CDI specification. This currently only affects CDI mode",
Destination: &opts.csv.librarySearchPaths,
},
} }
return &c return &c
@ -227,6 +233,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
nvcdi.WithDeviceNamer(deviceNamer), nvcdi.WithDeviceNamer(deviceNamer),
nvcdi.WithMode(string(opts.mode)), nvcdi.WithMode(string(opts.mode)),
nvcdi.WithCSVFiles(opts.csv.files.Value()), nvcdi.WithCSVFiles(opts.csv.files.Value()),
nvcdi.WithLibrarySearchPaths(opts.csv.librarySearchPaths.Value()),
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create CDI library: %v", err) return nil, fmt.Errorf("failed to create CDI library: %v", err)

View File

@ -28,7 +28,7 @@ import (
// newDiscovererFromCSVFiles creates a discoverer for the specified CSV files. A logger is also supplied. // newDiscovererFromCSVFiles creates a discoverer for the specified CSV files. A logger is also supplied.
// The constructed discoverer is comprised of a list, with each element in the list being associated with a // The constructed discoverer is comprised of a list, with each element in the list being associated with a
// single CSV files. // single CSV files.
func newDiscovererFromCSVFiles(logger logger.Interface, files []string, driverRoot string, nvidiaCTKPath string) (discover.Discover, error) { func newDiscovererFromCSVFiles(logger logger.Interface, files []string, driverRoot string, nvidiaCTKPath string, librarySearchPaths []string) (discover.Discover, error) {
if len(files) == 0 { if len(files) == 0 {
logger.Warningf("No CSV files specified") logger.Warningf("No CSV files specified")
return discover.None{}, nil return discover.None{}, nil
@ -51,7 +51,12 @@ func newDiscovererFromCSVFiles(logger logger.Interface, files []string, driverRo
) )
// Libraries and symlinks use the same locator. // Libraries and symlinks use the same locator.
symlinkLocator := lookup.NewSymlinkLocator(lookup.WithLogger(logger), lookup.WithRoot(driverRoot)) searchPaths := append(librarySearchPaths, "/")
symlinkLocator := lookup.NewSymlinkLocator(
lookup.WithLogger(logger),
lookup.WithRoot(driverRoot),
lookup.WithSearchPaths(searchPaths...),
)
libraries := discover.NewMounts( libraries := discover.NewMounts(
logger, logger,
symlinkLocator, symlinkLocator,

View File

@ -25,10 +25,11 @@ import (
) )
type tegraOptions struct { type tegraOptions struct {
logger logger.Interface logger logger.Interface
csvFiles []string csvFiles []string
driverRoot string driverRoot string
nvidiaCTKPath string nvidiaCTKPath string
librarySearchPaths []string
} }
// Option defines a functional option for configuring a Tegra discoverer. // Option defines a functional option for configuring a Tegra discoverer.
@ -41,7 +42,7 @@ func New(opts ...Option) (discover.Discover, error) {
opt(o) opt(o)
} }
csvDiscoverer, err := newDiscovererFromCSVFiles(o.logger, o.csvFiles, o.driverRoot, o.nvidiaCTKPath) csvDiscoverer, err := newDiscovererFromCSVFiles(o.logger, o.csvFiles, o.driverRoot, o.nvidiaCTKPath, o.librarySearchPaths)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create CSV discoverer: %v", err) return nil, fmt.Errorf("failed to create CSV discoverer: %v", err)
} }
@ -98,3 +99,10 @@ func WithNVIDIACTKPath(nvidiaCTKPath string) Option {
o.nvidiaCTKPath = nvidiaCTKPath o.nvidiaCTKPath = nvidiaCTKPath
} }
} }
// WithLibrarySearchPaths sets the library search paths for the discoverer.
func WithLibrarySearchPaths(librarySearchPaths ...string) Option {
return func(o *tegraOptions) {
o.librarySearchPaths = librarySearchPaths
}
}

View File

@ -44,6 +44,7 @@ func (l *csvlib) GetAllDeviceSpecs() ([]specs.Device, error) {
tegra.WithDriverRoot(l.driverRoot), tegra.WithDriverRoot(l.driverRoot),
tegra.WithNVIDIACTKPath(l.nvidiaCTKPath), tegra.WithNVIDIACTKPath(l.nvidiaCTKPath),
tegra.WithCSVFiles(l.csvFiles), tegra.WithCSVFiles(l.csvFiles),
tegra.WithLibrarySearchPaths(l.librarySearchPaths...),
) )
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create discoverer for CSV files: %v", err) return nil, fmt.Errorf("failed to create discoverer for CSV files: %v", err)

View File

@ -38,13 +38,14 @@ type wrapper struct {
} }
type nvcdilib struct { type nvcdilib struct {
logger logger.Interface logger logger.Interface
nvmllib nvml.Interface nvmllib nvml.Interface
mode string mode string
devicelib device.Interface devicelib device.Interface
deviceNamer DeviceNamer deviceNamer DeviceNamer
driverRoot string driverRoot string
nvidiaCTKPath string nvidiaCTKPath string
librarySearchPaths []string
csvFiles []string csvFiles []string

View File

@ -103,3 +103,11 @@ func WithCSVFiles(csvFiles []string) Option {
o.csvFiles = csvFiles o.csvFiles = csvFiles
} }
} }
// WithLibrarySearchPaths sets the library search paths.
// This is currently only used for CSV-mode.
func WithLibrarySearchPaths(paths []string) Option {
return func(o *nvcdilib) {
o.librarySearchPaths = paths
}
}