diff --git a/lxd/device/cdi/spec.go b/lxd/device/cdi/spec.go index 26ec44658da4..bd39cbdb3f5e 100644 --- a/lxd/device/cdi/spec.go +++ b/lxd/device/cdi/spec.go @@ -77,6 +77,12 @@ func generateNvidiaSpec(s *state.State, cdiID ID, inst instance.Instance) (*spec // rootPath = os.Getenv("SNAP") + "/gpu-2404-2" devRootPath = "/" + + // Let's ensure that user did: + // snap connect mesa-2404:kernel-gpu-2404 pc-kernel + if !shared.PathExists("/snap/lxd/current/gpu-2404-2/usr/bin/nvidia-smi") { + return nil, fmt.Errorf("Failed to find nvidia-smi tool. Please ensure that pc-kernel snap is connected to mesa-2404.") + } } else if shared.InSnap() { rootPath = "/var/lib/snapd/hostfs" devRootPath = rootPath diff --git a/lxd/device/gpu_physical.go b/lxd/device/gpu_physical.go index 17eb4e706e26..c0db2a6934b6 100644 --- a/lxd/device/gpu_physical.go +++ b/lxd/device/gpu_physical.go @@ -75,6 +75,14 @@ func (d *gpuPhysical) validateConfig(instConf instance.ConfigReader) error { return fmt.Errorf(`Cannot use %q when "id" is set`, field) } } + + // If user requests CDI in conjunction with nvidia.runtime=true we should forbid that. + if shared.IsTrue(instConf.ExpandedConfig()["nvidia.runtime"]) { + _, err := cdi.ToCDI(d.config["id"]) + if err == nil { + return fmt.Errorf("CDI mode is incompatible with nvidia.runtime=true") + } + } } return nil