Skip to content

Commit 2334a53

Browse files
[no-relnote] devel commit
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent fcb18b5 commit 2334a53

File tree

12 files changed

+99
-334
lines changed

12 files changed

+99
-334
lines changed

cmd/nvidia-ctk-installer/toolkit/toolkit_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ devices:
8484
hostPath: /host/driver/root/dev/nvidia-caps-imex-channels/channel1
8585
- path: /dev/nvidia-caps-imex-channels/channel2047
8686
hostPath: /host/driver/root/dev/nvidia-caps-imex-channels/channel2047
87+
- path: /dev/nvidia-caps/nvidia-cap1
88+
hostPath: /host/driver/root/dev/nvidia-caps/nvidia-cap1
8789
containerEdits:
8890
env:
8991
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu

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

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

6767
csv struct {
6868
files []string
@@ -215,11 +215,12 @@ func (m command) build() *cli.Command {
215215
Destination: &opts.disabledHooks,
216216
Sources: cli.EnvVars("NVIDIA_CTK_CDI_GENERATE_DISABLED_HOOKS"),
217217
},
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"),
218+
&cli.StringSliceFlag{
219+
Name: "enable-hook",
220+
Aliases: []string{"enable-hooks"},
221+
Usage: "Explicitly enable a hook in the generated CDI specification. This overrides disabled hooks. This can be specified multiple times.",
222+
Destination: &opts.enabledHooks,
223+
Sources: cli.EnvVars("NVIDIA_CTK_CDI_GENERATE_ENABLED_HOOKS"),
223224
},
224225
},
225226
}
@@ -328,8 +329,8 @@ func (m command) generateSpec(opts *options) (spec.Interface, error) {
328329
cdiOptions = append(cdiOptions, nvcdi.WithDisabledHook(hook))
329330
}
330331

331-
if opts.enableChmodHook {
332-
cdiOptions = append(cdiOptions, nvcdi.WithEnableChmodHook(true))
332+
for _, hook := range opts.enabledHooks {
333+
cdiOptions = append(cdiOptions, nvcdi.WithEnabledHook(hook))
333334
}
334335

335336
cdilib, err := nvcdi.New(cdiOptions...)

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

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -364,43 +364,59 @@ containerEdits:
364364
{
365365
description: "enableChmodHook",
366366
options: options{
367-
format: "yaml",
368-
mode: "nvml",
369-
vendor: "example.com",
370-
class: "device",
371-
driverRoot: driverRoot,
372-
enableChmodHook: true,
367+
format: "yaml",
368+
mode: "management",
369+
vendor: "example.com",
370+
class: "device",
371+
driverRoot: driverRoot,
372+
enabledHooks: []string{"chmod"},
373+
disabledHooks: []string{"enable-cuda-compat", "update-ldcache", "disable-device-node-modification"},
373374
},
374375
expectedOptions: options{
375376
format: "yaml",
376-
mode: "nvml",
377+
mode: "management",
377378
vendor: "example.com",
378379
class: "device",
379380
nvidiaCDIHookPath: "/usr/bin/nvidia-cdi-hook",
380381
driverRoot: driverRoot,
381-
enableChmodHook: true,
382+
enabledHooks: []string{"chmod"},
383+
disabledHooks: []string{"enable-cuda-compat", "update-ldcache", "disable-device-node-modification"},
382384
},
383385
expectedSpec: `---
384386
cdiVersion: 0.5.0
385387
kind: example.com/device
386388
devices:
387-
- name: "0"
388-
containerEdits:
389-
deviceNodes:
390-
- path: /dev/nvidia0
391-
hostPath: {{ .driverRoot }}/dev/nvidia0
392389
- name: all
393390
containerEdits:
394391
deviceNodes:
395392
- path: /dev/nvidia0
396393
hostPath: {{ .driverRoot }}/dev/nvidia0
394+
- path: /dev/nvidiactl
395+
hostPath: {{ .driverRoot }}/dev/nvidiactl
396+
- path: /dev/nvidia-caps-imex-channels/channel0
397+
hostPath: {{ .driverRoot }}/dev/nvidia-caps-imex-channels/channel0
398+
- path: /dev/nvidia-caps-imex-channels/channel1
399+
hostPath: {{ .driverRoot }}/dev/nvidia-caps-imex-channels/channel1
400+
- path: /dev/nvidia-caps-imex-channels/channel2047
401+
hostPath: {{ .driverRoot }}/dev/nvidia-caps-imex-channels/channel2047
402+
- path: /dev/nvidia-caps/nvidia-cap1
403+
hostPath: {{ .driverRoot }}/dev/nvidia-caps/nvidia-cap1
404+
hooks:
405+
- hookName: createContainer
406+
path: /usr/bin/nvidia-cdi-hook
407+
args:
408+
- nvidia-cdi-hook
409+
- chmod
410+
- --mode
411+
- "755"
412+
- --path
413+
- /dev/nvidia-caps
414+
env:
415+
- NVIDIA_CTK_DEBUG=false
397416
containerEdits:
398417
env:
399418
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
400419
- NVIDIA_VISIBLE_DEVICES=void
401-
deviceNodes:
402-
- path: /dev/nvidiactl
403-
hostPath: {{ .driverRoot }}/dev/nvidiactl
404420
hooks:
405421
- hookName: createContainer
406422
path: /usr/bin/nvidia-cdi-hook
@@ -411,30 +427,6 @@ containerEdits:
411427
- libcuda.so.1::/lib/x86_64-linux-gnu/libcuda.so
412428
env:
413429
- 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
438430
mounts:
439431
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
440432
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77
@@ -444,6 +436,14 @@ containerEdits:
444436
- nodev
445437
- rbind
446438
- rprivate
439+
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/vdpau/libvdpau_nvidia.so.999.88.77
440+
containerPath: /lib/x86_64-linux-gnu/vdpau/libvdpau_nvidia.so.999.88.77
441+
options:
442+
- ro
443+
- nosuid
444+
- nodev
445+
- rbind
446+
- rprivate
447447
`,
448448
},
449449
}

internal/config/features.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ type features struct {
4242
// possibly bypassing other checks by an orchestration system such as
4343
// kubernetes.
4444
IgnoreImexChannelRequests *feature `toml:"ignore-imex-channel-requests,omitempty"`
45-
// EnableChmodHook allows the chmod hook to be injected for device folder permissions.
46-
// This hook was originally added as a workaround for a specific crun issue with device
47-
// nodes in subdirectories of /dev (e.g., /dev/dri/*, /dev/nvidia-caps/*).
48-
// Since this issue has been resolved in newer versions of crun, this hook is disabled
49-
// by default. Users who still require this functionality can explicitly enable it.
50-
EnableChmodHook *feature `toml:"enable-chmod-hook,omitempty"`
5145
}
5246

5347
type feature bool

internal/config/features_test.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

internal/discover/hooks.go

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ const (
5050
defaultNvidiaCDIHookPath = "/usr/bin/nvidia-cdi-hook"
5151
)
5252

53+
// defaultDisabledHooks defines hooks that are disabled by default.
54+
// These hooks can be explicitly enabled using the WithEnabledHooks option.
55+
var defaultDisabledHooks = []HookName{
56+
// ChmodHook is disabled by default as it was a workaround for older
57+
// versions of crun that has since been fixed.
58+
ChmodHook,
59+
}
60+
5361
var _ Discover = (*Hook)(nil)
5462

5563
// Devices returns an empty list of devices for a Hook discoverer.
@@ -82,7 +90,7 @@ type Option func(*cdiHookCreator)
8290
type cdiHookCreator struct {
8391
nvidiaCDIHookPath string
8492
disabledHooks map[HookName]bool
85-
enableChmodHook bool
93+
enabledHooks map[HookName]bool
8694

8795
fixedArgs []string
8896
debugLogging bool
@@ -101,7 +109,7 @@ type HookCreator interface {
101109
Create(HookName, ...string) *Hook
102110
}
103111

104-
// WithDisabledHooks sets the set of hooks that are disabled for the CDI hook creator.
112+
// WithDisabledHooks explicitly disables the specified hooks.
105113
// This can be specified multiple times.
106114
func WithDisabledHooks(hooks ...HookName) Option {
107115
return func(c *cdiHookCreator) {
@@ -111,31 +119,45 @@ func WithDisabledHooks(hooks ...HookName) Option {
111119
}
112120
}
113121

114-
// WithNVIDIACDIHookPath sets the path to the nvidia-cdi-hook binary.
115-
func WithNVIDIACDIHookPath(nvidiaCDIHookPath string) Option {
122+
// WithEnabledHooks explicitly enables the specified hooks.
123+
// This is useful for enabling hooks that are disabled by default.
124+
func WithEnabledHooks(hooks ...HookName) Option {
116125
return func(c *cdiHookCreator) {
117-
c.nvidiaCDIHookPath = nvidiaCDIHookPath
126+
for _, hook := range hooks {
127+
c.enabledHooks[hook] = true
128+
}
118129
}
119130
}
120131

121-
// WithEnableChmodHook allows the chmod hook to be enabled.
122-
// By default, the chmod hook is disabled as it was a workaround for older
123-
// versions of crun that has since been fixed.
124-
func WithEnableChmodHook(enabled bool) Option {
132+
// WithNVIDIACDIHookPath sets the path to the nvidia-cdi-hook binary.
133+
func WithNVIDIACDIHookPath(nvidiaCDIHookPath string) Option {
125134
return func(c *cdiHookCreator) {
126-
c.enableChmodHook = enabled
135+
c.nvidiaCDIHookPath = nvidiaCDIHookPath
127136
}
128137
}
129138

130139
func NewHookCreator(opts ...Option) HookCreator {
140+
disabledHooks := make(map[HookName]bool)
141+
enabledHooks := make(map[HookName]bool)
142+
for _, hook := range defaultDisabledHooks {
143+
disabledHooks[hook] = true
144+
}
145+
131146
cdiHookCreator := &cdiHookCreator{
132147
nvidiaCDIHookPath: defaultNvidiaCDIHookPath,
133-
disabledHooks: make(map[HookName]bool),
148+
disabledHooks: disabledHooks,
149+
enabledHooks: enabledHooks,
134150
}
135151
for _, opt := range opts {
136152
opt(cdiHookCreator)
137153
}
138154

155+
// Correct the disabledHooks map to ensure that explicitly enabled hooks
156+
// are not disabled.
157+
for hook := range enabledHooks {
158+
cdiHookCreator.disabledHooks[hook] = false
159+
}
160+
139161
if cdiHookCreator.disabledHooks[AllHooks] {
140162
return &allDisabledHookCreator{}
141163
}
@@ -160,25 +182,15 @@ func (c cdiHookCreator) Create(name HookName, args ...string) *Hook {
160182
}
161183
}
162184

163-
// isDisabled checks if the specified hook name is disabled.
164185
func (c cdiHookCreator) isDisabled(name HookName, args ...string) bool {
165186
if c.disabledHooks[name] {
166187
return true
167188
}
168189

190+
// still reject hooks that require args if none were provided
169191
switch name {
170-
case CreateSymlinksHook:
171-
if len(args) == 0 {
172-
return true
173-
}
174-
case ChmodHook:
175-
// ChmodHook is disabled by default unless explicitly enabled
176-
if !c.enableChmodHook {
177-
return true
178-
}
179-
if len(args) == 0 {
180-
return true
181-
}
192+
case CreateSymlinksHook, ChmodHook:
193+
return len(args) == 0
182194
}
183195
return false
184196
}

0 commit comments

Comments
 (0)