Skip to content

Commit df99dc3

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

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
@@ -60,6 +60,8 @@ type options struct {
6060
files cli.StringSlice
6161
ignorePatterns cli.StringSlice
6262
}
63+
64+
noDotSoSymlinks bool
6365
}
6466

6567
// NewCommand constructs a generate-cdi command with the specified logger
@@ -166,6 +168,11 @@ func (m command) build() *cli.Command {
166168
Usage: "Specify a pattern the CSV mount specifications.",
167169
Destination: &opts.csv.ignorePatterns,
168170
},
171+
&cli.BoolFlag{
172+
Name: "no-dot-so-symlinks",
173+
Usage: "Skip the generation of a hook for creating .so symlinks to driver files in the container",
174+
Destination: &opts.noDotSoSymlinks,
175+
},
169176
}
170177

171178
return &c
@@ -270,6 +277,7 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
270277
nvcdi.WithLibrarySearchPaths(opts.librarySearchPaths.Value()),
271278
nvcdi.WithCSVFiles(opts.csv.files.Value()),
272279
nvcdi.WithCSVIgnorePatterns(opts.csv.ignorePatterns.Value()),
280+
nvcdi.WithNoDotSoSymlinks(opts.noDotSoSymlinks),
273281
)
274282
if err != nil {
275283
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+
createDotSoSymlinksHook := discover.NewDotSoSymlinksDiscoverer(l.nvidiaCTKPath, version)
60+
discoverers = append(discoverers, createDotSoSymlinksHook)
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
@@ -63,6 +63,8 @@ type nvcdilib struct {
6363
infolib info.Interface
6464

6565
mergedDeviceOptions []transform.MergedDeviceOption
66+
67+
noDotSoSymlinks bool
6668
}
6769

6870
// New creates a new nvcdi library

Diff for: pkg/nvcdi/options.go

+7
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,10 @@ func WithLibrarySearchPaths(paths []string) Option {
140140
o.librarySearchPaths = paths
141141
}
142142
}
143+
144+
// WithNoDotSoSymlinks sets the no-dot-so-symlinks feature.
145+
func WithNoDotSoSymlinks(noDotSoSymlinks bool) Option {
146+
return func(o *nvcdilib) {
147+
o.noDotSoSymlinks = noDotSoSymlinks
148+
}
149+
}

0 commit comments

Comments
 (0)