Skip to content

Commit 108ea3b

Browse files
committed
[no-relote] Minor cleanup of cdi lib construction
Signed-off-by: Evan Lezar <[email protected]>
1 parent 8e66a4a commit 108ea3b

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

internal/cdi/cdi.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,25 @@ func New(infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interf
113113
return nil, err
114114
}
115115

116-
c.cdilibs = make(map[string]nvcdi.SpecGenerator)
117-
118-
c.cdilibs["gpu"], err = nvcdi.New(
119-
nvcdi.WithInfoLib(c.infolib),
120-
nvcdi.WithNvmlLib(c.nvmllib),
116+
commonOptions := []nvcdi.Option{
121117
nvcdi.WithDeviceLib(c.devicelib),
118+
nvcdi.WithDevRoot(c.devRoot),
119+
nvcdi.WithDriverRoot(c.driverRoot),
120+
nvcdi.WithInfoLib(c.infolib),
122121
nvcdi.WithLogger(c.logger),
123122
nvcdi.WithNVIDIACDIHookPath(c.nvidiaCTKPath),
124-
nvcdi.WithDriverRoot(c.driverRoot),
125-
nvcdi.WithDevRoot(c.devRoot),
126-
nvcdi.WithDeviceNamers(deviceNamer),
123+
nvcdi.WithNvmlLib(c.nvmllib),
127124
nvcdi.WithVendor(c.vendor),
128-
nvcdi.WithClass("gpu"),
125+
}
126+
127+
c.cdilibs = make(map[string]nvcdi.SpecGenerator)
128+
129+
c.cdilibs["gpu"], err = nvcdi.New(
130+
append(
131+
commonOptions,
132+
nvcdi.WithDeviceNamers(deviceNamer),
133+
nvcdi.WithClass("gpu"),
134+
)...,
129135
)
130136
if err != nil {
131137
return nil, fmt.Errorf("failed to create nvcdi library: %v", err)
@@ -147,13 +153,10 @@ func New(infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interf
147153

148154
for _, mode := range c.additionalModes {
149155
lib, err := nvcdi.New(
150-
nvcdi.WithInfoLib(c.infolib),
151-
nvcdi.WithLogger(c.logger),
152-
nvcdi.WithNVIDIACDIHookPath(c.nvidiaCTKPath),
153-
nvcdi.WithDriverRoot(c.driverRoot),
154-
nvcdi.WithDevRoot(c.devRoot),
155-
nvcdi.WithVendor(c.vendor),
156-
nvcdi.WithMode(mode),
156+
append(
157+
commonOptions,
158+
nvcdi.WithMode(mode),
159+
)...,
157160
)
158161
if err != nil {
159162
return nil, fmt.Errorf("failed to create nvcdi library: %v", err)

0 commit comments

Comments
 (0)