Skip to content

Commit 8860878

Browse files
authored
Merge pull request #755 from elezar/fix-libcuda-so
Fix bug where libcuda.so is not found in ldcache
2 parents 771ac6b + fa5a4ac commit 8860878

File tree

23 files changed

+307
-363
lines changed

23 files changed

+307
-363
lines changed

cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go

Lines changed: 0 additions & 102 deletions
This file was deleted.

cmd/nvidia-ctk/system/system.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
devchar "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-dev-char-symlinks"
2323
devicenodes "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-device-nodes"
24-
ldcache "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/print-ldcache"
2524
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2625
)
2726

@@ -47,7 +46,6 @@ func (m command) build() *cli.Command {
4746
system.Subcommands = []*cli.Command{
4847
devchar.NewCommand(m.logger),
4948
devicenodes.NewCommand(m.logger),
50-
ldcache.NewCommand(m.logger),
5149
}
5250

5351
return &system

internal/ldcache/ldcache.go

Lines changed: 5 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ import (
2222
"bytes"
2323
"encoding/binary"
2424
"errors"
25-
"fmt"
2625
"os"
2726
"path/filepath"
28-
"strings"
2927
"syscall"
3028
"unsafe"
3129

3230
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
33-
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
3431
)
3532

3633
const ldcachePath = "/etc/ld.so.cache"
@@ -82,10 +79,9 @@ type entry2 struct {
8279

8380
// LDCache represents the interface for performing lookups into the LDCache
8481
//
85-
//go:generate moq -out ldcache_mock.go . LDCache
82+
//go:generate moq -rm -out ldcache_mock.go . LDCache
8683
type LDCache interface {
8784
List() ([]string, []string)
88-
Lookup(...string) ([]string, []string)
8985
}
9086

9187
type ldcache struct {
@@ -105,14 +101,7 @@ func New(logger logger.Interface, root string) (LDCache, error) {
105101

106102
logger.Debugf("Opening ld.conf at %v", path)
107103
f, err := os.Open(path)
108-
if os.IsNotExist(err) {
109-
logger.Warningf("Could not find ld.so.cache at %v; creating empty cache", path)
110-
e := &empty{
111-
logger: logger,
112-
path: path,
113-
}
114-
return e, nil
115-
} else if err != nil {
104+
if err != nil {
116105
return nil, err
117106
}
118107
defer f.Close()
@@ -196,7 +185,7 @@ type entry struct {
196185
}
197186

198187
// getEntries returns the entires of the ldcache in a go-friendly struct.
199-
func (c *ldcache) getEntries(selected func(string) bool) []entry {
188+
func (c *ldcache) getEntries() []entry {
200189
var entries []entry
201190
for _, e := range c.entries {
202191
bits := 0
@@ -223,9 +212,6 @@ func (c *ldcache) getEntries(selected func(string) bool) []entry {
223212
c.logger.Debugf("Skipping invalid lib")
224213
continue
225214
}
226-
if !selected(lib) {
227-
continue
228-
}
229215
value := bytesToString(c.libs[e.Value:])
230216
if value == "" {
231217
c.logger.Debugf("Skipping invalid value for lib %v", lib)
@@ -236,51 +222,19 @@ func (c *ldcache) getEntries(selected func(string) bool) []entry {
236222
bits: bits,
237223
value: value,
238224
}
239-
240225
entries = append(entries, e)
241226
}
242-
243227
return entries
244228
}
245229

246230
// List creates a list of libraries in the ldcache.
247231
// The 32-bit and 64-bit libraries are returned separately.
248232
func (c *ldcache) List() ([]string, []string) {
249-
all := func(s string) bool { return true }
250-
251-
return c.resolveSelected(all)
252-
}
253-
254-
// Lookup searches the ldcache for the specified prefixes.
255-
// The 32-bit and 64-bit libraries matching the prefixes are returned.
256-
func (c *ldcache) Lookup(libPrefixes ...string) ([]string, []string) {
257-
c.logger.Debugf("Looking up %v in cache", libPrefixes)
258-
259-
// We define a functor to check whether a given library name matches any of the prefixes
260-
matchesAnyPrefix := func(s string) bool {
261-
for _, p := range libPrefixes {
262-
if strings.HasPrefix(s, p) {
263-
return true
264-
}
265-
}
266-
return false
267-
}
268-
269-
return c.resolveSelected(matchesAnyPrefix)
270-
}
271-
272-
// resolveSelected process the entries in the LDCach based on the supplied filter and returns the resolved paths.
273-
// The paths are separated by bittage.
274-
func (c *ldcache) resolveSelected(selected func(string) bool) ([]string, []string) {
275233
paths := make(map[int][]string)
276234
processed := make(map[string]bool)
277235

278-
for _, e := range c.getEntries(selected) {
279-
path, err := c.resolve(e.value)
280-
if err != nil {
281-
c.logger.Debugf("Could not resolve entry: %v", err)
282-
continue
283-
}
236+
for _, e := range c.getEntries() {
237+
path := filepath.Join(c.root, e.value)
284238
if processed[path] {
285239
continue
286240
}
@@ -291,29 +245,6 @@ func (c *ldcache) resolveSelected(selected func(string) bool) ([]string, []strin
291245
return paths[32], paths[64]
292246
}
293247

294-
// resolve resolves the specified ldcache entry based on the value being processed.
295-
// The input is the name of the entry in the cache.
296-
func (c *ldcache) resolve(target string) (string, error) {
297-
name := filepath.Join(c.root, target)
298-
299-
c.logger.Debugf("checking %v", name)
300-
301-
link, err := symlinks.Resolve(name)
302-
if err != nil {
303-
return "", fmt.Errorf("failed to resolve symlink: %v", err)
304-
}
305-
if link == name {
306-
return name, nil
307-
}
308-
309-
// We return absolute paths for all targets
310-
if !filepath.IsAbs(link) || strings.HasPrefix(link, ".") {
311-
link = filepath.Join(filepath.Dir(target), link)
312-
}
313-
314-
return c.resolve(link)
315-
}
316-
317248
// bytesToString converts a byte slice to a string.
318249
// This assumes that the byte slice is null-terminated
319250
func bytesToString(value []byte) string {

internal/ldcache/ldcache_mock.go

Lines changed: 1 addition & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)