@@ -36,21 +36,21 @@ import (
3636// TODO: The logic for creating DRM devices should be consolidated between this
3737// and the logic for generating CDI specs for a single device. This is only used
3838// when applying OCI spec modifications to an incoming spec in "legacy" mode.
39- func NewDRMNodesDiscoverer (logger logger.Interface , devices image.VisibleDevices , devRoot string , nvidiaCDIHookPath string ) (Discover , error ) {
39+ func NewDRMNodesDiscoverer (logger logger.Interface , devices image.VisibleDevices , devRoot string , hookCreator HookCreator ) (Discover , error ) {
4040 drmDeviceNodes , err := newDRMDeviceDiscoverer (logger , devices , devRoot )
4141 if err != nil {
4242 return nil , fmt .Errorf ("failed to create DRM device discoverer: %v" , err )
4343 }
4444
45- drmByPathSymlinks := newCreateDRMByPathSymlinks (logger , drmDeviceNodes , devRoot , nvidiaCDIHookPath )
45+ drmByPathSymlinks := newCreateDRMByPathSymlinks (logger , drmDeviceNodes , devRoot , hookCreator )
4646
4747 discover := Merge (drmDeviceNodes , drmByPathSymlinks )
4848 return discover , nil
4949}
5050
5151// NewGraphicsMountsDiscoverer creates a discoverer for the mounts required by graphics tools such as vulkan.
52- func NewGraphicsMountsDiscoverer (logger logger.Interface , driver * root.Driver , nvidiaCDIHookPath string ) (Discover , error ) {
53- libraries := newGraphicsLibrariesDiscoverer (logger , driver , nvidiaCDIHookPath )
52+ func NewGraphicsMountsDiscoverer (logger logger.Interface , driver * root.Driver , hookCreator HookCreator ) (Discover , error ) {
53+ libraries := newGraphicsLibrariesDiscoverer (logger , driver , hookCreator )
5454
5555 configs := NewMounts (
5656 logger ,
@@ -95,13 +95,13 @@ func newVulkanConfigsDiscover(logger logger.Interface, driver *root.Driver) Disc
9595
9696type graphicsDriverLibraries struct {
9797 Discover
98- logger logger.Interface
99- nvidiaCDIHookPath string
98+ logger logger.Interface
99+ hookCreator HookCreator
100100}
101101
102102var _ Discover = (* graphicsDriverLibraries )(nil )
103103
104- func newGraphicsLibrariesDiscoverer (logger logger.Interface , driver * root.Driver , nvidiaCDIHookPath string ) Discover {
104+ func newGraphicsLibrariesDiscoverer (logger logger.Interface , driver * root.Driver , hookCreator HookCreator ) Discover {
105105 cudaLibRoot , cudaVersionPattern := getCUDALibRootAndVersionPattern (logger , driver )
106106
107107 libraries := NewMounts (
@@ -140,9 +140,9 @@ func newGraphicsLibrariesDiscoverer(logger logger.Interface, driver *root.Driver
140140 )
141141
142142 return & graphicsDriverLibraries {
143- Discover : Merge (libraries , xorgLibraries ),
144- logger : logger ,
145- nvidiaCDIHookPath : nvidiaCDIHookPath ,
143+ Discover : Merge (libraries , xorgLibraries ),
144+ logger : logger ,
145+ hookCreator : hookCreator ,
146146 }
147147}
148148
@@ -203,9 +203,9 @@ func (d graphicsDriverLibraries) Hooks() ([]Hook, error) {
203203 return nil , nil
204204 }
205205
206- hooks := CreateCreateSymlinkHook ( d . nvidiaCDIHookPath , links )
206+ hook := d . hookCreator . Create ( "create-symlinks" , links ... )
207207
208- return hooks .Hooks ()
208+ return hook .Hooks ()
209209}
210210
211211// isDriverLibrary checks whether the specified filename is a specific driver library.
@@ -275,19 +275,19 @@ func buildXOrgSearchPaths(libRoot string) []string {
275275
276276type drmDevicesByPath struct {
277277 None
278- logger logger.Interface
279- nvidiaCDIHookPath string
280- devRoot string
281- devicesFrom Discover
278+ logger logger.Interface
279+ hookCreator HookCreator
280+ devRoot string
281+ devicesFrom Discover
282282}
283283
284284// newCreateDRMByPathSymlinks creates a discoverer for a hook to create the by-path symlinks for DRM devices discovered by the specified devices discoverer
285- func newCreateDRMByPathSymlinks (logger logger.Interface , devices Discover , devRoot string , nvidiaCDIHookPath string ) Discover {
285+ func newCreateDRMByPathSymlinks (logger logger.Interface , devices Discover , devRoot string , hookCreator HookCreator ) Discover {
286286 d := drmDevicesByPath {
287- logger : logger ,
288- nvidiaCDIHookPath : nvidiaCDIHookPath ,
289- devRoot : devRoot ,
290- devicesFrom : devices ,
287+ logger : logger ,
288+ hookCreator : hookCreator ,
289+ devRoot : devRoot ,
290+ devicesFrom : devices ,
291291 }
292292
293293 return & d
@@ -315,13 +315,9 @@ func (d drmDevicesByPath) Hooks() ([]Hook, error) {
315315 args = append (args , "--link" , l )
316316 }
317317
318- hook := CreateNvidiaCDIHook (
319- d .nvidiaCDIHookPath ,
320- "create-symlinks" ,
321- args ... ,
322- )
318+ hook := d .hookCreator .Create ("create-symlinks" , args ... )
323319
324- return [] Hook { hook }, nil
320+ return hook . Hooks ()
325321}
326322
327323// getSpecificLinkArgs returns the required specific links that need to be created
0 commit comments