Skip to content

Commit 8c92344

Browse files
Add enable-chmod-hook option to cdi generate CLI
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 1540b82 commit 8c92344

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

cmd/nvidia-ctk/cdi/generate/generate.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type options struct {
6262
configSearchPaths []string
6363
librarySearchPaths []string
6464
disabledHooks []string
65+
enableChmodHook bool
6566

6667
csv struct {
6768
files []string
@@ -214,6 +215,12 @@ func (m command) build() *cli.Command {
214215
Destination: &opts.disabledHooks,
215216
Sources: cli.EnvVars("NVIDIA_CTK_CDI_GENERATE_DISABLED_HOOKS"),
216217
},
218+
&cli.BoolFlag{
219+
Name: "enable-chmod-hook",
220+
Usage: "Enable the chmod hook for device folder permissions. This hook is disabled by default.",
221+
Destination: &opts.enableChmodHook,
222+
Sources: cli.EnvVars("NVIDIA_CTK_CDI_GENERATE_ENABLE_CHMOD_HOOK"),
223+
},
217224
},
218225
}
219226

@@ -321,6 +328,10 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
321328
cdiOptions = append(cdiOptions, nvcdi.WithDisabledHook(hook))
322329
}
323330

331+
if opts.enableChmodHook {
332+
cdiOptions = append(cdiOptions, nvcdi.WithEnableChmodHook(true))
333+
}
334+
324335
cdilib, err := nvcdi.New(cdiOptions...)
325336
if err != nil {
326337
return nil, fmt.Errorf("failed to create CDI library: %v", err)

cmd/nvidia-ctk/cdi/generate/generate_test.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,91 @@ containerEdits:
359359
- nodev
360360
- rbind
361361
- rprivate
362+
`,
363+
},
364+
{
365+
description: "enableChmodHook",
366+
options: options{
367+
format: "yaml",
368+
mode: "nvml",
369+
vendor: "example.com",
370+
class: "device",
371+
driverRoot: driverRoot,
372+
enableChmodHook: true,
373+
},
374+
expectedOptions: options{
375+
format: "yaml",
376+
mode: "nvml",
377+
vendor: "example.com",
378+
class: "device",
379+
nvidiaCDIHookPath: "/usr/bin/nvidia-cdi-hook",
380+
driverRoot: driverRoot,
381+
enableChmodHook: true,
382+
},
383+
expectedSpec: `---
384+
cdiVersion: 0.5.0
385+
kind: example.com/device
386+
devices:
387+
- name: "0"
388+
containerEdits:
389+
deviceNodes:
390+
- path: /dev/nvidia0
391+
hostPath: {{ .driverRoot }}/dev/nvidia0
392+
- name: all
393+
containerEdits:
394+
deviceNodes:
395+
- path: /dev/nvidia0
396+
hostPath: {{ .driverRoot }}/dev/nvidia0
397+
containerEdits:
398+
env:
399+
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
400+
- NVIDIA_VISIBLE_DEVICES=void
401+
deviceNodes:
402+
- path: /dev/nvidiactl
403+
hostPath: {{ .driverRoot }}/dev/nvidiactl
404+
hooks:
405+
- hookName: createContainer
406+
path: /usr/bin/nvidia-cdi-hook
407+
args:
408+
- nvidia-cdi-hook
409+
- create-symlinks
410+
- --link
411+
- libcuda.so.1::/lib/x86_64-linux-gnu/libcuda.so
412+
env:
413+
- NVIDIA_CTK_DEBUG=false
414+
- hookName: createContainer
415+
path: /usr/bin/nvidia-cdi-hook
416+
args:
417+
- nvidia-cdi-hook
418+
- enable-cuda-compat
419+
- --host-driver-version=999.88.77
420+
env:
421+
- NVIDIA_CTK_DEBUG=false
422+
- hookName: createContainer
423+
path: /usr/bin/nvidia-cdi-hook
424+
args:
425+
- nvidia-cdi-hook
426+
- update-ldcache
427+
- --folder
428+
- /lib/x86_64-linux-gnu
429+
env:
430+
- NVIDIA_CTK_DEBUG=false
431+
- hookName: createContainer
432+
path: /usr/bin/nvidia-cdi-hook
433+
args:
434+
- nvidia-cdi-hook
435+
- disable-device-node-modification
436+
env:
437+
- NVIDIA_CTK_DEBUG=false
438+
mounts:
439+
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
440+
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77
441+
options:
442+
- ro
443+
- nosuid
444+
- nodev
445+
- rbind
446+
- rprivate
362447
`,
363448
},
364449
}

0 commit comments

Comments
 (0)