From f768bb5783795aa4d6d9fca5313ac3429adfe250 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 30 Jan 2023 13:36:11 +0100 Subject: [PATCH 1/4] Use device index as CDI device names by default This change uses the `index` mode for the --device-name-strategy when generating CDI specifications by default. This generates device names such as nvidia.com/gpu=0 or nvidia.com/gpu=1:0 by default. Note that this requires a CDI spec version of 0.5.0 and for consumers (e.g. podman) that are only compatible with older versions one of the other stragegies (`type-index` or `uuid`) should be used instead to generate a v0.3.0 or v0.4.0 specification. Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index aeee4967..93334eb3 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -89,8 +89,8 @@ func (m command) build() *cli.Command { }, &cli.StringFlag{ Name: "device-name-strategy", - Usage: "Specify the strategy for generating device names. One of [type-index | index | uuid]", - Value: deviceNameStrategyTypeIndex, + Usage: "Specify the strategy for generating device names. One of [index | uuid | type-index]", + Value: deviceNameStrategyIndex, Destination: &cfg.deviceNameStrategy, }, &cli.StringFlag{ From 201232dae35f5ad1b02e3c8330b3b009b188f795 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 30 Jan 2023 13:39:08 +0100 Subject: [PATCH 2/4] Add logging of minimum CDI version Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index 93334eb3..0b0de708 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -279,6 +279,8 @@ func (m command) generateSpec(root string, nvidiaCTKPath string, namer deviceNam if err != nil { return nil, fmt.Errorf("failed to get minumum required CDI spec version: %v", err) } + m.logger.Infof("Using minimum required CDI spec version: %s", minVersion) + spec.Version = minVersion return &spec, nil From 707e3479f829b1537dead0a0a72a483ab968d5b5 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 30 Jan 2023 13:39:57 +0100 Subject: [PATCH 3/4] Fix lint errors Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 4 ++-- cmd/nvidia-ctk/cdi/generate/namer.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index 0b0de708..23bd17c9 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -117,7 +117,7 @@ func (m command) validateFlags(r *cli.Context, cfg *config) error { return fmt.Errorf("invalid output format: %v", cfg.format) } - _, err := NewDeviceNamer(cfg.deviceNameStrategy) + _, err := newDeviceNamer(cfg.deviceNameStrategy) if err != nil { return err } @@ -126,7 +126,7 @@ func (m command) validateFlags(r *cli.Context, cfg *config) error { } func (m command) run(c *cli.Context, cfg *config) error { - deviceNamer, err := NewDeviceNamer(cfg.deviceNameStrategy) + deviceNamer, err := newDeviceNamer(cfg.deviceNameStrategy) if err != nil { return fmt.Errorf("failed to create device namer: %v", err) } diff --git a/cmd/nvidia-ctk/cdi/generate/namer.go b/cmd/nvidia-ctk/cdi/generate/namer.go index 63131ca9..06e90ea4 100644 --- a/cmd/nvidia-ctk/cdi/generate/namer.go +++ b/cmd/nvidia-ctk/cdi/generate/namer.go @@ -40,9 +40,9 @@ type deviceNameIndex struct { } type deviceNameUUID struct{} -// NewDeviceNamer creates a Device Namer based on the supplied strategy. +// newDeviceNamer creates a Device Namer based on the supplied strategy. // This namer can be used to construct the names for MIG and GPU devices when generating the CDI spec. -func NewDeviceNamer(strategy string) (deviceNamer, error) { +func newDeviceNamer(strategy string) (deviceNamer, error) { switch strategy { case deviceNameStrategyIndex: return deviceNameIndex{}, nil From 5e6f72e8f435456be394d5652e85f695d5f5f1ba Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 30 Jan 2023 13:40:25 +0100 Subject: [PATCH 4/4] Update changelog Signed-off-by: Evan Lezar --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95d8ced1..33ea2c8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## v1.12.0-rc.4 +* Generate a minimum CDI spec version for improved compatibility. +* Add `--device-name-strategy` options to the `nvidia-ctk cdi generate` command that can be used to control how device names are constructed. +* Set default for CDI device name generation to `index` to generate device names such as `nvidia.com/gpu=0` or `nvidia.com/gpu=1:0` by default. ## v1.12.0-rc.3 * Don't fail if by-path symlinks for DRM devices do not exist