Also return an error from nvcdi.New

This change allows nvcdi.New to return an error in addition to the
constructed library instead of panicing.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar
2023-03-22 14:04:12 +02:00
parent 1ebbebf5de
commit 226c54613e
4 changed files with 13 additions and 7 deletions

View File

@@ -188,13 +188,16 @@ func (m command) generateSpec(cfg *config) (spec.Interface, error) {
return nil, fmt.Errorf("failed to create device namer: %v", err)
}
cdilib := nvcdi.New(
cdilib, err := nvcdi.New(
nvcdi.WithLogger(m.logger),
nvcdi.WithDriverRoot(cfg.driverRoot),
nvcdi.WithNVIDIACTKPath(cfg.nvidiaCTKPath),
nvcdi.WithDeviceNamer(deviceNamer),
nvcdi.WithMode(string(cfg.mode)),
)
if err != nil {
return nil, fmt.Errorf("failed to create CDI library: %v", err)
}
deviceSpecs, err := cdilib.GetAllDeviceSpecs()
if err != nil {