Skip to content

Commit

Permalink
lxd/device/gpu_physical: forbid CDI GPU hotplugging (#14031)
Browse files Browse the repository at this point in the history
CDI GPU are not hotpluggable because the configuration of a CDI GPU
requires a LXC hook that is only run at instance start. A classic GPU
device can be hotplugged.
  • Loading branch information
tomponline authored Sep 3, 2024
2 parents 8708ed1 + 5432e5a commit 481ebca
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lxd/device/gpu_physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/canonical/lxd/lxd/storage/filesystem"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/logger"
)

const gpuDRIDevPath = "/dev/dri"
Expand Down Expand Up @@ -598,6 +599,31 @@ func (d *gpuPhysical) stopCDIDevices(configDevices cdi.ConfigDevices, runConf *d
return nil
}

// CanHotPlug returns whether the device can be managed whilst the instance is running.
// CDI GPU are not hotpluggable because the configuration of a CDI GPU requires a LXC hook that
// is only run at instance start. A classic GPU device can be hotplugged.
func (d *gpuPhysical) CanHotPlug() bool {
if d.inst.Type() == instancetype.Container {
if d.config["id"] != "" {
// Check if the id of the device match a CDI format.
cdiID, err := cdi.ToCDI(d.config["id"])
if err != nil {
d.logger.Error("Failed to parse CDI ID when hotplugging", logger.Ctx{"err": err})
return false
}

if !cdiID.Empty() {
d.logger.Warn("Hotplugging CDI devices is not supported", logger.Ctx{"id": d.config["id"]})
return false
}
}

return true
}

return false
}

// Stop is run when the device is removed from the instance.
func (d *gpuPhysical) Stop() (*deviceConfig.RunConfig, error) {
runConf := deviceConfig.RunConfig{
Expand Down

0 comments on commit 481ebca

Please sign in to comment.