Skip to content

Commit e20826f

Browse files
committed
Generate hook to create .so symlinks in CDI
Signed-off-by: Evan Lezar <[email protected]>
1 parent baa5096 commit e20826f

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

Diff for: cmd/nvidia-ctk/cdi/generate/generate.go

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type options struct {
5959
files cli.StringSlice
6060
ignorePatterns cli.StringSlice
6161
}
62+
63+
noDotSoSymlinks bool
6264
}
6365

6466
// NewCommand constructs a generate-cdi command with the specified logger
@@ -160,6 +162,11 @@ func (m command) build() *cli.Command {
160162
Usage: "Specify a pattern the CSV mount specifications.",
161163
Destination: &opts.csv.ignorePatterns,
162164
},
165+
&cli.BoolFlag{
166+
Name: "no-dot-so-symlinks",
167+
Usage: "Skip the generation of a hook for creating .so symlinks to driver files in the container",
168+
Destination: &opts.noDotSoSymlinks,
169+
},
163170
}
164171

165172
return &c
@@ -263,6 +270,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
263270
nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()),
264271
nvcdi.WithCSVFiles(opts.csv.files.Value()),
265272
nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()),
273+
nvcdi.WithNoDotSoSymlinks(opts.noDotSoSymlinks),
266274
)
267275
if err != nil {
268276
return nil, fmt.Errorf("failed to create CDI library: %v", err)

Diff for: pkg/nvcdi/common-nvml.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (l *nvmllib) newCommonNVMLDiscoverer() (discover.Discover, error) {
4141
l.logger.Warningf("failed to create discoverer for graphics mounts: %v", err)
4242
}
4343

44-
driverFiles, err := NewDriverDiscoverer(l.logger, l.driver, l.nvidiaCTKPath, l.ldconfigPath, l.nvmllib)
44+
driverFiles, err := l.newDriverDiscoverer()
4545
if err != nil {
4646
return nil, fmt.Errorf("failed to create discoverer for driver files: %v", err)
4747
}

Diff for: pkg/nvcdi/driver-nvml.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,35 @@ import (
3232
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root"
3333
)
3434

35-
// NewDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation.
35+
// newDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation.
3636
// The supplied NVML Library is used to query the expected driver version.
37-
func NewDriverDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPath string, ldconfigPath string, nvmllib nvml.Interface) (discover.Discover, error) {
38-
if r := nvmllib.Init(); r != nvml.SUCCESS {
37+
func (l *nvmllib) newDriverDiscoverer() (discover.Discover, error) {
38+
if r := l.nvmllib.Init(); r != nvml.SUCCESS {
3939
return nil, fmt.Errorf("failed to initialize NVML: %v", r)
4040
}
4141
defer func() {
42-
if r := nvmllib.Shutdown(); r != nvml.SUCCESS {
43-
logger.Warningf("failed to shutdown NVML: %v", r)
42+
if r := l.nvmllib.Shutdown(); r != nvml.SUCCESS {
43+
l.logger.Warningf("failed to shutdown NVML: %v", r)
4444
}
4545
}()
4646

47-
version, r := nvmllib.SystemGetDriverVersion()
47+
version, r := l.nvmllib.SystemGetDriverVersion()
4848
if r != nvml.SUCCESS {
4949
return nil, fmt.Errorf("failed to determine driver version: %v", r)
5050
}
5151

52-
return newDriverVersionDiscoverer(logger, driver, nvidiaCTKPath, ldconfigPath, version)
52+
driver, err := newDriverVersionDiscoverer(l.logger, l.driver, l.nvidiaCTKPath, l.ldconfigPath, version)
53+
if err != nil {
54+
return nil, fmt.Errorf("failed to create discoverer: %w", err)
55+
}
56+
discoverers := []discover.Discover{driver}
57+
58+
if !l.noDotSoSymlinks {
59+
dotSoSymLinks := discover.NewDotSoSymlinksDiscoverer(l.nvidiaCTKPath, version)
60+
discoverers = append(discoverers, dotSoSymLinks)
61+
}
62+
63+
return discover.Merge(discoverers...), nil
5364
}
5465

5566
func newDriverVersionDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCTKPath, ldconfigPath, version string) (discover.Discover, error) {

Diff for: pkg/nvcdi/lib.go

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ type nvcdilib struct {
6262
infolib info.Interface
6363

6464
mergedDeviceOptions []transform.MergedDeviceOption
65+
66+
noDotSoSymlinks bool
6567
}
6668

6769
// New creates a new nvcdi library

Diff for: pkg/nvcdi/options.go

+7
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,10 @@ func WithLibrarySearchPaths(paths []string) Option {
133133
o.librarySearchPaths = paths
134134
}
135135
}
136+
137+
// WithNoDotSoSymlinks sets the no-dot-so-symlinks feature.
138+
func WithNoDotSoSymlinks(noDotSoSymlinks bool) Option {
139+
return func(o *nvcdilib) {
140+
o.noDotSoSymlinks = noDotSoSymlinks
141+
}
142+
}

0 commit comments

Comments
 (0)