diff --git a/cmd/nvidia-ctk/info/generate-cdi/generate-cdi.go b/cmd/nvidia-ctk/info/generate-cdi/generate-cdi.go index e8fa42aa..23508423 100644 --- a/cmd/nvidia-ctk/info/generate-cdi/generate-cdi.go +++ b/cmd/nvidia-ctk/info/generate-cdi/generate-cdi.go @@ -176,6 +176,8 @@ func (m command) generateSpec() (*specs.Spec, error) { return nil, fmt.Errorf("falied to generate CDI spec for MIG devices: %v", err) } + spec.ContainerEdits.DeviceNodes = m.getExistingMetaDeviceNodes() + libraries, err := m.findLibs(nvmllib) if err != nil { return nil, fmt.Errorf("failed to locate driver libraries: %v", err) @@ -201,18 +203,13 @@ func (m command) generateSpec() (*specs.Spec, error) { } func generateEditsForDevice(name string, d deviceInfo) (specs.Device, error) { - var deviceNodes []*specs.DeviceNode - deviceNodePaths, err := d.GetDeviceNodes() if err != nil { return specs.Device{}, fmt.Errorf("failed to get paths for device: %v", err) } - for _, p := range deviceNodePaths { - deviceNode := specs.DeviceNode{ - Path: p, - } - deviceNodes = append(deviceNodes, &deviceNode) - } + + deviceNodes := getDeviceNodesFromPaths(deviceNodePaths) + device := specs.Device{ Name: name, ContainerEdits: specs.ContainerEdits{ @@ -223,6 +220,38 @@ func generateEditsForDevice(name string, d deviceInfo) (specs.Device, error) { return device, nil } +func (m command) getExistingMetaDeviceNodes() []*specs.DeviceNode { + metaDeviceNodePaths := []string{ + "/dev/nvidia-modeset", + "/dev/nvidia-uvm-tools", + "/dev/nvidia-uvm", + "/dev/nvidiactl", + } + + var existingDeviceNodePaths []string + for _, p := range metaDeviceNodePaths { + if _, err := os.Stat(p); err != nil { + m.logger.Infof("Ignoring missing meta device %v", p) + continue + } + existingDeviceNodePaths = append(existingDeviceNodePaths, p) + } + + return getDeviceNodesFromPaths(existingDeviceNodePaths) +} + +func getDeviceNodesFromPaths(deviceNodePaths []string) []*specs.DeviceNode { + var deviceNodes []*specs.DeviceNode + for _, p := range deviceNodePaths { + deviceNode := specs.DeviceNode{ + Path: p, + } + deviceNodes = append(deviceNodes, &deviceNode) + } + + return deviceNodes +} + func (m command) findLibs(nvmllib nvml.Interface) ([]string, error) { version, r := nvmllib.SystemGetDriverVersion() if r != nvml.SUCCESS {