Skip to content

Commit 815dae7

Browse files
[no-relnote] devel commit
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 1f0719a commit 815dae7

File tree

13 files changed

+99
-334
lines changed

13 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: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -328,43 +328,59 @@ containerEdits:
328328
{
329329
description: "enableChmodHook",
330330
options: options{
331-
format: "yaml",
332-
mode: "nvml",
333-
vendor: "example.com",
334-
class: "device",
335-
driverRoot: driverRoot,
336-
enableChmodHook: true,
331+
format: "yaml",
332+
mode: "management",
333+
vendor: "example.com",
334+
class: "device",
335+
driverRoot: driverRoot,
336+
enabledHooks: []string{"chmod"},
337+
disabledHooks: []string{"enable-cuda-compat", "update-ldcache", "disable-device-node-modification"},
337338
},
338339
expectedOptions: options{
339340
format: "yaml",
340-
mode: "nvml",
341+
mode: "management",
341342
vendor: "example.com",
342343
class: "device",
343344
nvidiaCDIHookPath: "/usr/bin/nvidia-cdi-hook",
344345
driverRoot: driverRoot,
345-
enableChmodHook: true,
346+
enabledHooks: []string{"chmod"},
347+
disabledHooks: []string{"enable-cuda-compat", "update-ldcache", "disable-device-node-modification"},
346348
},
347349
expectedSpec: `---
348350
cdiVersion: 0.5.0
349351
kind: example.com/device
350352
devices:
351-
- name: "0"
352-
containerEdits:
353-
deviceNodes:
354-
- path: /dev/nvidia0
355-
hostPath: {{ .driverRoot }}/dev/nvidia0
356353
- name: all
357354
containerEdits:
358355
deviceNodes:
359356
- path: /dev/nvidia0
360357
hostPath: {{ .driverRoot }}/dev/nvidia0
358+
- path: /dev/nvidiactl
359+
hostPath: {{ .driverRoot }}/dev/nvidiactl
360+
- path: /dev/nvidia-caps-imex-channels/channel0
361+
hostPath: {{ .driverRoot }}/dev/nvidia-caps-imex-channels/channel0
362+
- path: /dev/nvidia-caps-imex-channels/channel1
363+
hostPath: {{ .driverRoot }}/dev/nvidia-caps-imex-channels/channel1
364+
- path: /dev/nvidia-caps-imex-channels/channel2047
365+
hostPath: {{ .driverRoot }}/dev/nvidia-caps-imex-channels/channel2047
366+
- path: /dev/nvidia-caps/nvidia-cap1
367+
hostPath: {{ .driverRoot }}/dev/nvidia-caps/nvidia-cap1
368+
hooks:
369+
- hookName: createContainer
370+
path: /usr/bin/nvidia-cdi-hook
371+
args:
372+
- nvidia-cdi-hook
373+
- chmod
374+
- --mode
375+
- "755"
376+
- --path
377+
- /dev/nvidia-caps
378+
env:
379+
- NVIDIA_CTK_DEBUG=false
361380
containerEdits:
362381
env:
363382
- NVIDIA_CTK_LIBCUDA_DIR=/lib/x86_64-linux-gnu
364383
- NVIDIA_VISIBLE_DEVICES=void
365-
deviceNodes:
366-
- path: /dev/nvidiactl
367-
hostPath: {{ .driverRoot }}/dev/nvidiactl
368384
hooks:
369385
- hookName: createContainer
370386
path: /usr/bin/nvidia-cdi-hook
@@ -375,30 +391,6 @@ containerEdits:
375391
- libcuda.so.1::/lib/x86_64-linux-gnu/libcuda.so
376392
env:
377393
- NVIDIA_CTK_DEBUG=false
378-
- hookName: createContainer
379-
path: /usr/bin/nvidia-cdi-hook
380-
args:
381-
- nvidia-cdi-hook
382-
- enable-cuda-compat
383-
- --host-driver-version=999.88.77
384-
env:
385-
- NVIDIA_CTK_DEBUG=false
386-
- hookName: createContainer
387-
path: /usr/bin/nvidia-cdi-hook
388-
args:
389-
- nvidia-cdi-hook
390-
- update-ldcache
391-
- --folder
392-
- /lib/x86_64-linux-gnu
393-
env:
394-
- NVIDIA_CTK_DEBUG=false
395-
- hookName: createContainer
396-
path: /usr/bin/nvidia-cdi-hook
397-
args:
398-
- nvidia-cdi-hook
399-
- disable-device-node-modification
400-
env:
401-
- NVIDIA_CTK_DEBUG=false
402394
mounts:
403395
- hostPath: {{ .driverRoot }}/lib/x86_64-linux-gnu/libcuda.so.999.88.77
404396
containerPath: /lib/x86_64-linux-gnu/libcuda.so.999.88.77

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/config/hook.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ type RuntimeHookConfig struct {
2323
Path string `toml:"path"`
2424
// SkipModeDetection disables the mode check for the runtime hook.
2525
SkipModeDetection bool `toml:"skip-mode-detection"`
26+
// DisabledHooks specifies the hooks that are disabled for the NVIDIA
27+
// Container Runtime hook.
28+
DisabledHooks []string `toml:"disabled,omitempty"`
2629
}

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 = map[HookName]bool{
56+
// ChmodHook is disabled by default as it was a workaround for older
57+
// versions of crun that has since been fixed.
58+
ChmodHook: true,
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)