From d17ad5f92026a8811cc681e68f23f5b70bf40cfc Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 28 May 2024 12:05:38 +0200 Subject: [PATCH] Ensure consistent construction order for libs This change ensures that nvnllib and devicelib are constructed before these are used to construct infolib. Signed-off-by: Evan Lezar --- CHANGELOG.md | 1 + pkg/nvcdi/lib.go | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e3eab37..79555126 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Use : as a config --set list separator. This fixes a bug in modifying lists in the config file with the `nvidia-ctk config` command. * Add `RUNTIME_CONFIG_OVERRIDE` (`--runtime-config-override`) to the `nvidia-ctk runtime configure` command and the toolkit container to allow for containerd runtime options to be set directly. This can be used to override the `SystemdCroup` option explicitly, for example. +* Ensure consistent construction of libraries for CDI spec generation. ## v1.15.0 diff --git a/pkg/nvcdi/lib.go b/pkg/nvcdi/lib.go index e3c162e7..1d136a7b 100644 --- a/pkg/nvcdi/lib.go +++ b/pkg/nvcdi/lib.go @@ -81,14 +81,25 @@ func New(opts ...Option) (Interface, error) { indexNamer, _ := NewDeviceNamer(DeviceNameStrategyIndex) l.deviceNamers = []DeviceNamer{indexNamer} } + if l.nvidiaCTKPath == "" { + l.nvidiaCTKPath = "/usr/bin/nvidia-ctk" + } if l.driverRoot == "" { l.driverRoot = "/" } if l.devRoot == "" { l.devRoot = l.driverRoot } - if l.nvidiaCTKPath == "" { - l.nvidiaCTKPath = "/usr/bin/nvidia-ctk" + l.driver = root.New( + root.WithLogger(l.logger), + root.WithDriverRoot(l.driverRoot), + root.WithLibrarySearchPaths(l.librarySearchPaths...), + ) + if l.nvmllib == nil { + l.nvmllib = nvml.New() + } + if l.devicelib == nil { + l.devicelib = device.New(device.WithNvml(l.nvmllib)) } if l.infolib == nil { l.infolib = info.New( @@ -99,12 +110,6 @@ func New(opts ...Option) (Interface, error) { ) } - l.driver = root.New( - root.WithLogger(l.logger), - root.WithDriverRoot(l.driverRoot), - root.WithLibrarySearchPaths(l.librarySearchPaths...), - ) - var lib Interface switch l.resolveMode() { case ModeCSV: @@ -118,13 +123,6 @@ func New(opts ...Option) (Interface, error) { } lib = (*managementlib)(l) case ModeNvml: - if l.nvmllib == nil { - l.nvmllib = nvml.New() - } - if l.devicelib == nil { - l.devicelib = device.New(device.WithNvml(l.nvmllib)) - } - lib = (*nvmllib)(l) case ModeWsl: lib = (*wsllib)(l)