Skip to content

Commit

Permalink
lxd/instance/drivers/common: Clone the device config
Browse files Browse the repository at this point in the history
When instantiating a new device make sure to clone it's config.
This ensures that the downstream drivers don't modify the original config map.

Signed-off-by: Julian Pelizäus <julian.pelizaeus@canonical.com>
  • Loading branch information
roosterfish committed Mar 18, 2024
1 parent 289bba7 commit 81156fe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lxd/instance/drivers/driver_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,9 @@ func (d *common) canMigrate(inst instance.Instance) (migrate bool, live bool) {
volatileGet := func() map[string]string { return map[string]string{} }
volatileSet := func(_ map[string]string) error { return nil }
for deviceName, rawConfig := range d.ExpandedDevices() {
dev, err := device.New(inst, d.state, deviceName, rawConfig, volatileGet, volatileSet)
// Make sure to clone the devices config for new devices.
// Some device drivers might modify the configuration and populate additional settings.
dev, err := device.New(inst, d.state, deviceName, rawConfig.Clone(), volatileGet, volatileSet)
if err != nil {
logger.Warn("Instance will not be migrated due to a device error", logger.Ctx{"project": inst.Project().Name, "instance": inst.Name(), "device": dev.Name(), "err": err})
return false, false
Expand Down

0 comments on commit 81156fe

Please sign in to comment.