@@ -43,6 +43,7 @@ const (
4343 nvidiaCapsDeviceName = "nvidia-caps"
4444 nvidiaCapsImexChannelsDeviceName = "nvidia-caps-imex-channels"
4545 nvidiaCapFabricImexMgmtPath = "/proc/driver/nvidia/capabilities/fabric-imex-mgmt"
46+ hostDevContainerPath = "/host/dev"
4647)
4748
4849type deviceLib struct {
@@ -89,6 +90,10 @@ func newDeviceLib(driverRoot root) (*deviceLib, error) {
8990 return nil , fmt .Errorf ("error recursively unmounting %s: %w" , procDriverNvidiaPath , err )
9091 }
9192
93+ if err := d .conditionallyBindMountHostDev (); err != nil {
94+ return nil , fmt .Errorf ("error conditionally bind mounting host dev: %w" , err )
95+ }
96+
9297 return & d , nil
9398}
9499
@@ -418,3 +423,27 @@ func (l deviceLib) unmountRecursively(root string) error {
418423
419424 return helper (root )
420425}
426+
427+ // conditionallyBindMountHostDev bind mounts hostDevContainerPath over /dev when devRoot is "/".
428+ // Introduced to address the issues described in https://github.com/NVIDIA/k8s-dra-driver-gpu/issues/477.
429+ // TODO: Revisit with a more comprehensive solution as proposed in https://github.com/NVIDIA/k8s-dra-driver-gpu/pull/307.
430+ func (l deviceLib ) conditionallyBindMountHostDev () error {
431+ // If devRoot != "/" then we don't need to do the mount
432+ if l .devRoot != "/" {
433+ return nil
434+ }
435+
436+ // Get a reference to the mount executable.
437+ mountExecutable , err := exec .LookPath ("mount" )
438+ if err != nil {
439+ return fmt .Errorf ("error looking up mount executable: %w" , err )
440+ }
441+ mounter := mount .New (mountExecutable )
442+
443+ // Bind mount hostDevContainerPath over /dev
444+ if err := mounter .Mount (hostDevContainerPath , "/dev" , "" , []string {"bind" }); err != nil {
445+ return fmt .Errorf ("failed to bind mount %s over /dev: %w" , hostDevContainerPath , err )
446+ }
447+
448+ return nil
449+ }
0 commit comments