mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-04 03:48:14 +00:00
Use options for NewLibraryLocator
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
64f554ef41
commit
5505886655
@ -49,10 +49,10 @@ func NewDRMNodesDiscoverer(logger logger.Interface, devices image.VisibleDevices
|
|||||||
|
|
||||||
// NewGraphicsMountsDiscoverer creates a discoverer for the mounts required by graphics tools such as vulkan.
|
// NewGraphicsMountsDiscoverer creates a discoverer for the mounts required by graphics tools such as vulkan.
|
||||||
func NewGraphicsMountsDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) (Discover, error) {
|
func NewGraphicsMountsDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) (Discover, error) {
|
||||||
locator, err := lookup.NewLibraryLocator(logger, driverRoot)
|
locator := lookup.NewLibraryLocator(
|
||||||
if err != nil {
|
lookup.WithLogger(logger),
|
||||||
return nil, fmt.Errorf("failed to construct library locator: %v", err)
|
lookup.WithRoot(driverRoot),
|
||||||
}
|
)
|
||||||
libraries := NewMounts(
|
libraries := NewMounts(
|
||||||
logger,
|
logger,
|
||||||
locator,
|
locator,
|
||||||
|
@ -58,13 +58,10 @@ func New(opts ...Options) lookup.Locator {
|
|||||||
c.driverRoot = "/"
|
c.driverRoot = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Do we want to set the Count to 1 here?
|
c.Locator = lookup.NewLibraryLocator(
|
||||||
l, _ := lookup.NewLibraryLocator(
|
lookup.WithLogger(c.logger),
|
||||||
c.logger,
|
lookup.WithRoot(c.driverRoot),
|
||||||
c.driverRoot,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
c.Locator = l
|
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,9 @@ type ldcacheLocator struct {
|
|||||||
|
|
||||||
var _ Locator = (*ldcacheLocator)(nil)
|
var _ Locator = (*ldcacheLocator)(nil)
|
||||||
|
|
||||||
// NewLibraryLocator creates a library locator using the specified logger.
|
// NewLibraryLocator creates a library locator using the specified options.
|
||||||
func NewLibraryLocator(logger logger.Interface, root string) (Locator, error) {
|
func NewLibraryLocator(opts ...Option) Locator {
|
||||||
// We construct a symlink locator for expected library locations.
|
opts = append(opts,
|
||||||
symlinkLocator := NewSymlinkLocator(
|
|
||||||
WithLogger(logger),
|
|
||||||
WithRoot(root),
|
|
||||||
WithSearchPaths([]string{
|
WithSearchPaths([]string{
|
||||||
"/",
|
"/",
|
||||||
"/usr/lib64",
|
"/usr/lib64",
|
||||||
@ -50,24 +47,28 @@ func NewLibraryLocator(logger logger.Interface, root string) (Locator, error) {
|
|||||||
"/lib/aarch64-linux-gnu/nvidia/current",
|
"/lib/aarch64-linux-gnu/nvidia/current",
|
||||||
}...),
|
}...),
|
||||||
)
|
)
|
||||||
|
// We construct a symlink locator for expected library locations.
|
||||||
|
symlinkLocator := NewSymlinkLocator(opts...)
|
||||||
|
|
||||||
l := First(
|
l := First(
|
||||||
symlinkLocator,
|
symlinkLocator,
|
||||||
newLdcacheLocator(logger, root),
|
newLdcacheLocator(opts...),
|
||||||
)
|
)
|
||||||
return l, nil
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLdcacheLocator(logger logger.Interface, root string) Locator {
|
func newLdcacheLocator(opts ...Option) Locator {
|
||||||
cache, err := ldcache.New(logger, root)
|
b := newBuilder(opts...)
|
||||||
|
|
||||||
|
cache, err := ldcache.New(b.logger, b.root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If we failed to open the LDCache, we default to a symlink locator.
|
// If we failed to open the LDCache, we default to a symlink locator.
|
||||||
logger.Warningf("Failed to load ldcache: %v", err)
|
b.logger.Warningf("Failed to load ldcache: %v", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ldcacheLocator{
|
return &ldcacheLocator{
|
||||||
logger: logger,
|
logger: b.logger,
|
||||||
cache: cache,
|
cache: cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,10 @@ func TestLDCacheLocator(t *testing.T) {
|
|||||||
require.NoError(t, os.Symlink(versionLib, sonameLink))
|
require.NoError(t, os.Symlink(versionLib, sonameLink))
|
||||||
require.NoError(t, os.Symlink(sonameLink, soLink))
|
require.NoError(t, os.Symlink(sonameLink, soLink))
|
||||||
|
|
||||||
lut := newLdcacheLocator(logger, testDir)
|
lut := newLdcacheLocator(
|
||||||
|
WithLogger(logger),
|
||||||
|
WithRoot(testDir),
|
||||||
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
@ -94,7 +97,6 @@ func TestLDCacheLocator(t *testing.T) {
|
|||||||
require.EqualValues(t, tc.expected, cleanedCandidates)
|
require.EqualValues(t, tc.expected, cleanedCandidates)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLibraryLocator(t *testing.T) {
|
func TestLibraryLocator(t *testing.T) {
|
||||||
@ -125,8 +127,10 @@ func TestLibraryLocator(t *testing.T) {
|
|||||||
require.NoError(t, os.Symlink(libTarget1, source1))
|
require.NoError(t, os.Symlink(libTarget1, source1))
|
||||||
require.NoError(t, os.Symlink(source1, source2))
|
require.NoError(t, os.Symlink(source1, source2))
|
||||||
|
|
||||||
lut, err := NewLibraryLocator(logger, testDir)
|
lut := NewLibraryLocator(
|
||||||
require.NoError(t, err)
|
WithLogger(logger),
|
||||||
|
WithRoot(testDir),
|
||||||
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
|
Loading…
Reference in New Issue
Block a user