summaryrefslogtreecommitdiff
path: root/pkg/specgen
diff options
context:
space:
mode:
authorEvan Lezar <elezar@nvidia.com>2022-01-12 14:22:29 +0100
committerEvan Lezar <elezar@nvidia.com>2022-01-14 13:35:22 +0100
commit968deb7c2cd2e4fab7edf03f2a73fb62bb652171 (patch)
treeea0349b4a36a44625e5f6dda891034986da8417f /pkg/specgen
parent2c510146aa03c74fb00a15bcf81c62b14df9c7ea (diff)
downloadpodman-968deb7c2cd2e4fab7edf03f2a73fb62bb652171.tar.gz
podman-968deb7c2cd2e4fab7edf03f2a73fb62bb652171.tar.bz2
podman-968deb7c2cd2e4fab7edf03f2a73fb62bb652171.zip
Use new CDI API
This change updates the CDI API to commit 46367ec063fda9da931d050b308ccd768e824364 which addresses some inconistencies in the previous implementation. Signed-off-by: Evan Lezar <elezar@nvidia.com>
Diffstat (limited to 'pkg/specgen')
-rw-r--r--pkg/specgen/generate/container_create.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go
index 7d792b3b1..dc116d1e6 100644
--- a/pkg/specgen/generate/container_create.go
+++ b/pkg/specgen/generate/container_create.go
@@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"
- cdi "github.com/container-orchestrated-devices/container-device-interface/pkg"
+ cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
"github.com/containers/common/libimage"
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
@@ -199,20 +199,21 @@ func ExecuteCreate(ctx context.Context, rt *libpod.Runtime, runtimeSpec *spec.Sp
return ctr, rt.PrepareVolumeOnCreateContainer(ctx, ctr)
}
+// ExtractCDIDevices process the list of Devices in the spec and determines if any of these are CDI devices.
+// The CDI devices are added to the list of CtrCreateOptions.
+// Note that this may modify the device list associated with the spec, which should then only contain non-CDI devices.
func ExtractCDIDevices(s *specgen.SpecGenerator) []libpod.CtrCreateOption {
devs := make([]spec.LinuxDevice, 0, len(s.Devices))
var cdiDevs []string
var options []libpod.CtrCreateOption
for _, device := range s.Devices {
- isCDIDevice, err := cdi.HasDevice(device.Path)
- if err != nil {
- logrus.Debugf("CDI HasDevice Error: %v", err)
- }
- if err == nil && isCDIDevice {
+ if isCDIDevice(device.Path) {
+ logrus.Debugf("Identified CDI device %v", device.Path)
cdiDevs = append(cdiDevs, device.Path)
continue
}
+ logrus.Debugf("Non-CDI device %v; assuming standard device", device.Path)
devs = append(devs, device)
}
s.Devices = devs
@@ -222,6 +223,11 @@ func ExtractCDIDevices(s *specgen.SpecGenerator) []libpod.CtrCreateOption {
return options
}
+// isCDIDevice checks whether the specified device is a CDI device.
+func isCDIDevice(device string) bool {
+ return cdi.IsQualifiedName(device)
+}
+
func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGenerator, pod *libpod.Pod, volumes []*specgen.NamedVolume, overlays []*specgen.OverlayVolume, imageData *libimage.ImageData, command []string, infraVolumes bool, compatibleOptions libpod.InfraInherit) ([]libpod.CtrCreateOption, error) {
var options []libpod.CtrCreateOption
var err error