Skip to content

Commit fdcd250

Browse files
authored
Merge pull request #1129 from elezar/fix-deduplicate-driver-store-wsl
Minor cleanup of WSL2 CDI spec generation
2 parents d59fd3d + b66d37b commit fdcd250

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

pkg/nvcdi/driver-wsl.go

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,46 +40,32 @@ var requiredDriverStoreFiles = []string{
4040

4141
// newWSLDriverDiscoverer returns a Discoverer for WSL2 drivers.
4242
func newWSLDriverDiscoverer(logger logger.Interface, driverRoot string, hookCreator discover.HookCreator, ldconfigPath string) (discover.Discover, error) {
43-
err := dxcore.Init()
44-
if err != nil {
45-
return nil, fmt.Errorf("failed to initialize dxcore: %v", err)
43+
if err := dxcore.Init(); err != nil {
44+
return nil, fmt.Errorf("failed to initialize dxcore: %w", err)
4645
}
4746
defer func() {
4847
if err := dxcore.Shutdown(); err != nil {
49-
logger.Warningf("failed to shutdown dxcore: %v", err)
48+
logger.Warningf("failed to shutdown dxcore: %w", err)
5049
}
5150
}()
5251

5352
driverStorePaths := dxcore.GetDriverStorePaths()
5453
if len(driverStorePaths) == 0 {
5554
return nil, fmt.Errorf("no driver store paths found")
5655
}
56+
if len(driverStorePaths) > 1 {
57+
logger.Warningf("Found multiple driver store paths: %v", driverStorePaths)
58+
}
5759
logger.Infof("Using WSL driver store paths: %v", driverStorePaths)
5860

59-
return newWSLDriverStoreDiscoverer(logger, driverRoot, hookCreator, ldconfigPath, driverStorePaths)
60-
}
61-
62-
// newWSLDriverStoreDiscoverer returns a Discoverer for WSL2 drivers in the driver store associated with a dxcore adapter.
63-
func newWSLDriverStoreDiscoverer(logger logger.Interface, driverRoot string, hookCreator discover.HookCreator, ldconfigPath string, driverStorePaths []string) (discover.Discover, error) {
64-
var searchPaths []string
65-
seen := make(map[string]bool)
66-
for _, path := range driverStorePaths {
67-
if seen[path] {
68-
continue
69-
}
70-
searchPaths = append(searchPaths, path)
71-
}
72-
if len(searchPaths) > 1 {
73-
logger.Warningf("Found multiple driver store paths: %v", searchPaths)
74-
}
75-
searchPaths = append(searchPaths, "/usr/lib/wsl/lib")
61+
driverStorePaths = append(driverStorePaths, "/usr/lib/wsl/lib")
7662

77-
libraries := discover.NewMounts(
63+
driverStoreMounts := discover.NewMounts(
7864
logger,
7965
lookup.NewFileLocator(
8066
lookup.WithLogger(logger),
8167
lookup.WithSearchPaths(
82-
searchPaths...,
68+
driverStorePaths...,
8369
),
8470
lookup.WithCount(1),
8571
),
@@ -89,14 +75,14 @@ func newWSLDriverStoreDiscoverer(logger logger.Interface, driverRoot string, hoo
8975

9076
symlinkHook := nvidiaSMISimlinkHook{
9177
logger: logger,
92-
mountsFrom: libraries,
78+
mountsFrom: driverStoreMounts,
9379
hookCreator: hookCreator,
9480
}
9581

96-
ldcacheHook, _ := discover.NewLDCacheUpdateHook(logger, libraries, hookCreator, ldconfigPath)
82+
ldcacheHook, _ := discover.NewLDCacheUpdateHook(logger, driverStoreMounts, hookCreator, ldconfigPath)
9783

9884
d := discover.Merge(
99-
libraries,
85+
driverStoreMounts,
10086
symlinkHook,
10187
ldcacheHook,
10288
)

0 commit comments

Comments
 (0)