Skip to content

Commit 29c0f82

Browse files
authored
Merge pull request #327 from elezar/add-driver-config
Add config search path option to driver root
2 parents e1417be + 2a9e353 commit 29c0f82

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

cmd/nvidia-ctk/cdi/generate/generate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type options struct {
5353
vendor string
5454
class string
5555

56+
configSearchPaths cli.StringSlice
5657
librarySearchPaths cli.StringSlice
5758

5859
csv struct {
@@ -86,6 +87,11 @@ func (m command) build() *cli.Command {
8687
}
8788

8889
c.Flags = []cli.Flag{
90+
&cli.StringSliceFlag{
91+
Name: "config-search-path",
92+
Usage: "Specify the path to search for config files when discovering the entities that should be included in the CDI specification.",
93+
Destination: &opts.configSearchPaths,
94+
},
8995
&cli.StringFlag{
9096
Name: "output",
9197
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) {
260266
nvcdi.WithLdconfigPath(opts.ldconfigPath),
261267
nvcdi.WithDeviceNamers(deviceNamers...),
262268
nvcdi.WithMode(opts.mode),
269+
nvcdi.WithConfigSearchPaths(opts.configSearchPaths.Value()),
263270
nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()),
264271
nvcdi.WithCSVFiles(opts.csv.files.Value()),
265272
nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()),

internal/discover/graphics.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ func NewGraphicsMountsDiscoverer(logger logger.Interface, driver *root.Driver, n
6161

6262
jsonMounts := NewMounts(
6363
logger,
64-
lookup.NewFileLocator(
65-
lookup.WithLogger(logger),
66-
lookup.WithRoot(driver.Root),
67-
lookup.WithSearchPaths("/etc", "/usr/share"),
68-
),
64+
driver.Configs(),
6965
driver.Root,
7066
[]string{
7167
"glvnd/egl_vendor.d/10_nvidia.json",
@@ -292,11 +288,7 @@ func newXorgDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPa
292288

293289
xorgConfig := NewMounts(
294290
logger,
295-
lookup.NewFileLocator(
296-
lookup.WithLogger(logger),
297-
lookup.WithRoot(driver.Root),
298-
lookup.WithSearchPaths("/usr/share"),
299-
),
291+
driver.Configs(),
300292
driver.Root,
301293
[]string{"X11/xorg.conf.d/10-nvidia.conf"},
302294
)

internal/lookup/root/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ func WithLibrarySearchPaths(paths ...string) Option {
3737
d.librarySearchPaths = paths
3838
}
3939
}
40+
41+
func WithConfigSearchPaths(paths ...string) Option {
42+
return func(d *Driver) {
43+
d.configSearchPaths = paths
44+
}
45+
}

internal/lookup/root/root.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type Driver struct {
3030
Root string
3131
// librarySearchPaths specifies explicit search paths for discovering libraries.
3232
librarySearchPaths []string
33+
// configSearchPaths specified explicit search paths for discovering driver config files.
34+
configSearchPaths []string
3335
}
3436

3537
// New creates a new Driver root using the specified options.
@@ -53,6 +55,24 @@ func (r *Driver) Libraries() lookup.Locator {
5355
)
5456
}
5557

58+
// Configs returns a locator for driver configs.
59+
// If configSearchPaths is specified, these paths are used as absolute paths,
60+
// otherwise, /etc and /usr/share are searched.
61+
func (r *Driver) Configs() lookup.Locator {
62+
searchRoot := r.Root
63+
searchPaths := []string{"/etc", "/usr/share"}
64+
if len(r.configSearchPaths) > 0 {
65+
searchRoot = "/"
66+
searchPaths = normalizeSearchPaths(r.configSearchPaths...)
67+
}
68+
69+
return lookup.NewFileLocator(
70+
lookup.WithLogger(r.logger),
71+
lookup.WithRoot(searchRoot),
72+
lookup.WithSearchPaths(searchPaths...),
73+
)
74+
}
75+
5676
// normalizeSearchPaths takes a list of paths and normalized these.
5777
// Each of the elements in the list is expanded if it is a path list and the
5878
// resultant list is returned.

pkg/nvcdi/lib.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type nvcdilib struct {
5050
devRoot string
5151
nvidiaCTKPath string
5252
ldconfigPath string
53+
configSearchPaths []string
5354
librarySearchPaths []string
5455

5556
csvFiles []string

pkg/nvcdi/options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ func WithCSVIgnorePatterns(csvIgnorePatterns []string) Option {
126126
}
127127
}
128128

129+
// WithConfigSearchPaths sets the search paths for config files.
130+
func WithConfigSearchPaths(paths []string) Option {
131+
return func(o *nvcdilib) {
132+
o.configSearchPaths = paths
133+
}
134+
}
135+
129136
// WithLibrarySearchPaths sets the library search paths.
130137
// This is currently only used for CSV-mode.
131138
func WithLibrarySearchPaths(paths []string) Option {

0 commit comments

Comments
 (0)