From 8553fce68ac9ad3c7b1c970ec2668a658cc16b11 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 18 Jul 2023 12:02:37 +0200 Subject: [PATCH] Specify library search paths for CSV CDI spec generation Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 9 ++++++++- internal/platform-support/tegra/csv.go | 9 +++++++-- internal/platform-support/tegra/tegra.go | 18 +++++++++++++----- pkg/nvcdi/lib-csv.go | 1 + pkg/nvcdi/lib.go | 15 ++++++++------- pkg/nvcdi/options.go | 8 ++++++++ 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index 8f6917d6..8a6f061b 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -51,7 +51,8 @@ type options struct { class string 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()...), 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 @@ -227,6 +233,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) { nvcdi.WithDeviceNamer(deviceNamer), nvcdi.WithMode(string(opts.mode)), nvcdi.WithCSVFiles(opts.csv.files.Value()), + nvcdi.WithLibrarySearchPaths(opts.csv.librarySearchPaths.Value()), ) if err != nil { return nil, fmt.Errorf("failed to create CDI library: %v", err) diff --git a/internal/platform-support/tegra/csv.go b/internal/platform-support/tegra/csv.go index 3a66f471..3da4b0dd 100644 --- a/internal/platform-support/tegra/csv.go +++ b/internal/platform-support/tegra/csv.go @@ -28,7 +28,7 @@ import ( // 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 // 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 { logger.Warningf("No CSV files specified") return discover.None{}, nil @@ -51,7 +51,12 @@ func newDiscovererFromCSVFiles(logger logger.Interface, files []string, driverRo ) // 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( logger, symlinkLocator, diff --git a/internal/platform-support/tegra/tegra.go b/internal/platform-support/tegra/tegra.go index a52cb6f4..019d2730 100644 --- a/internal/platform-support/tegra/tegra.go +++ b/internal/platform-support/tegra/tegra.go @@ -25,10 +25,11 @@ import ( ) type tegraOptions struct { - logger logger.Interface - csvFiles []string - driverRoot string - nvidiaCTKPath string + logger logger.Interface + csvFiles []string + driverRoot string + nvidiaCTKPath string + librarySearchPaths []string } // Option defines a functional option for configuring a Tegra discoverer. @@ -41,7 +42,7 @@ func New(opts ...Option) (discover.Discover, error) { 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 { return nil, fmt.Errorf("failed to create CSV discoverer: %v", err) } @@ -98,3 +99,10 @@ func WithNVIDIACTKPath(nvidiaCTKPath string) Option { o.nvidiaCTKPath = nvidiaCTKPath } } + +// WithLibrarySearchPaths sets the library search paths for the discoverer. +func WithLibrarySearchPaths(librarySearchPaths ...string) Option { + return func(o *tegraOptions) { + o.librarySearchPaths = librarySearchPaths + } +} diff --git a/pkg/nvcdi/lib-csv.go b/pkg/nvcdi/lib-csv.go index 244f473c..5ae17964 100644 --- a/pkg/nvcdi/lib-csv.go +++ b/pkg/nvcdi/lib-csv.go @@ -44,6 +44,7 @@ func (l *csvlib) GetAllDeviceSpecs() ([]specs.Device, error) { tegra.WithDriverRoot(l.driverRoot), tegra.WithNVIDIACTKPath(l.nvidiaCTKPath), tegra.WithCSVFiles(l.csvFiles), + tegra.WithLibrarySearchPaths(l.librarySearchPaths...), ) if err != nil { return nil, fmt.Errorf("failed to create discoverer for CSV files: %v", err) diff --git a/pkg/nvcdi/lib.go b/pkg/nvcdi/lib.go index 4c7febe0..30d12aae 100644 --- a/pkg/nvcdi/lib.go +++ b/pkg/nvcdi/lib.go @@ -38,13 +38,14 @@ type wrapper struct { } type nvcdilib struct { - logger logger.Interface - nvmllib nvml.Interface - mode string - devicelib device.Interface - deviceNamer DeviceNamer - driverRoot string - nvidiaCTKPath string + logger logger.Interface + nvmllib nvml.Interface + mode string + devicelib device.Interface + deviceNamer DeviceNamer + driverRoot string + nvidiaCTKPath string + librarySearchPaths []string csvFiles []string diff --git a/pkg/nvcdi/options.go b/pkg/nvcdi/options.go index 9ac772ba..f354e6df 100644 --- a/pkg/nvcdi/options.go +++ b/pkg/nvcdi/options.go @@ -103,3 +103,11 @@ func WithCSVFiles(csvFiles []string) Option { 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 + } +}