Skip to content

Commit e83c3cf

Browse files
committed
Add libcuda.so symlink to CDI spec
This change adds a hook to create a libcuda.so symlink to the CDI specification. This aligns the CDI spec behaviour with the libnvidia-container implementation. Signed-off-by: Evan Lezar <[email protected]>
1 parent 79c59ae commit e83c3cf

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

pkg/nvcdi/driver-nvml.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ import (
3232
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/root"
3333
)
3434

35+
type driverVersionDiscoverer struct {
36+
discover.Discover
37+
nvidiaCDIHookPath string
38+
version string
39+
}
40+
3541
// NewDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation.
3642
// The supplied NVML Library is used to query the expected driver version.
3743
func NewDriverDiscoverer(logger logger.Interface, driver *root.Driver, nvidiaCDIHookPath string, ldconfigPath string, nvmllib nvml.Interface) (discover.Discover, error) {
@@ -100,7 +106,11 @@ func NewDriverLibraryDiscoverer(logger logger.Interface, driver *root.Driver, nv
100106
hooks, _ := discover.NewLDCacheUpdateHook(logger, libraries, nvidiaCDIHookPath, ldconfigPath)
101107

102108
d := discover.Merge(
103-
libraries,
109+
&driverVersionDiscoverer{
110+
Discover: libraries,
111+
nvidiaCDIHookPath: nvidiaCDIHookPath,
112+
version: version,
113+
},
104114
hooks,
105115
)
106116

@@ -220,3 +230,35 @@ func getVersionLibs(logger logger.Interface, driver *root.Driver, version string
220230

221231
return relative, nil
222232
}
233+
234+
func (d driverVersionDiscoverer) Hooks() ([]discover.Hook, error) {
235+
mounts, err := d.Discover.Mounts()
236+
if err != nil {
237+
return nil, fmt.Errorf("failed to get library mounts: %v", err)
238+
}
239+
240+
var links []string
241+
for _, mount := range mounts {
242+
dir, filename := filepath.Split(mount.Path)
243+
if d.isDriverLibrary(filename, "libcuda.so") {
244+
// create libcuda.so -> libcuda.so.RM_VERSION symlink
245+
links = append(links, fmt.Sprintf("%s::%s", filename, filepath.Join(dir, "libcuda.so")))
246+
}
247+
}
248+
249+
if len(links) == 0 {
250+
return nil, nil
251+
}
252+
253+
hooks := discover.CreateCreateSymlinkHook(d.nvidiaCDIHookPath, links)
254+
255+
return hooks.Hooks()
256+
257+
}
258+
259+
// isDriverLibrary checks whether the specified filename is a specific driver library.
260+
func (d driverVersionDiscoverer) isDriverLibrary(filename string, libraryName string) bool {
261+
pattern := strings.TrimSuffix(libraryName, ".") + d.version
262+
match, _ := filepath.Match(pattern, filename)
263+
return match
264+
}

0 commit comments

Comments
 (0)