Skip to content

Commit 13a8626

Browse files
committed
daemon/devices: Turn RegisterGPUDeviceDrivers into func
Change GPU device driver registration from init-time function assignment to direct function exports. This removes the init() function and global function variable pattern in favor of a more explicit approach. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 561a5a9 commit 13a8626

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

daemon/devices.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ import (
1010
"github.com/moby/moby/v2/daemon/config"
1111
"github.com/moby/moby/v2/daemon/internal/capabilities"
1212
"github.com/opencontainers/runtime-spec/specs-go"
13-
"tags.cncf.io/container-device-interface/pkg/cdi"
1413
)
1514

1615
var deviceDrivers = map[string]*deviceDriver{}
1716

18-
var RegisterGPUDeviceDrivers = func(_ *cdi.Cache) {}
19-
2017
type deviceListing struct {
2118
Devices []system.DeviceInfo
2219
Warnings []string

daemon/devices_linux.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@ package daemon
22

33
import "tags.cncf.io/container-device-interface/pkg/cdi"
44

5-
func init() {
6-
RegisterGPUDeviceDrivers = registerGPUDeviceDrivers
7-
}
8-
9-
// registerGPUDeviceDrivers registers GPU device drivers.
5+
// RegisterGPUDeviceDrivers registers GPU device drivers.
106
// If the cdiCache is provided, it is used to detect presence of CDI specs for AMD GPUs.
117
// For NVIDIA GPUs, presence of CDI specs is detected by checking for the nvidia-cdi-hook binary.
12-
func registerGPUDeviceDrivers(cdiCache *cdi.Cache) {
8+
func RegisterGPUDeviceDrivers(cdiCache *cdi.Cache) {
139
// Register NVIDIA device drivers.
1410
if nvidiaDrivers := getNVIDIADeviceDrivers(); len(nvidiaDrivers) > 0 {
1511
for name, driver := range nvidiaDrivers {

daemon/devices_nonlinux.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !linux
2+
3+
package daemon
4+
5+
import "tags.cncf.io/container-device-interface/pkg/cdi"
6+
7+
// RegisterGPUDeviceDrivers is a no-op on non-Linux platforms.
8+
func RegisterGPUDeviceDrivers(_ *cdi.Cache) {}

0 commit comments

Comments
 (0)