diff --git a/lxd/storage_volumes_utils.go b/lxd/storage_volumes_utils.go index 6e28820b392a..01ad19178263 100644 --- a/lxd/storage_volumes_utils.go +++ b/lxd/storage_volumes_utils.go @@ -12,12 +12,17 @@ import ( storagePools "github.com/canonical/lxd/lxd/storage" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" + "github.com/canonical/lxd/shared/logger" + "github.com/canonical/lxd/shared/revert" "github.com/canonical/lxd/shared/version" ) var supportedVolumeTypes = []int{cluster.StoragePoolVolumeTypeContainer, cluster.StoragePoolVolumeTypeVM, cluster.StoragePoolVolumeTypeCustom, cluster.StoragePoolVolumeTypeImage} func storagePoolVolumeUpdateUsers(s *state.State, projectName string, oldPoolName string, oldVol *api.StorageVolume, newPoolName string, newVol *api.StorageVolume) error { + revert := revert.New() + defer revert.Fail() + // Update all instances that are using the volume with a local (non-expanded) device. err := storagePools.VolumeUsedByInstanceDevices(s, oldPoolName, projectName, oldVol, false, func(dbInst db.InstanceArgs, project api.Project, usedByDevices []string) error { inst, err := instance.Load(s, dbInst, project) @@ -58,6 +63,17 @@ func storagePoolVolumeUpdateUsers(s *state.State, projectName string, oldPoolNam return err } + revert.Add(func() { + err := inst.Update(dbInst, false) + if err != nil { + logger.Error("Failed to revert instance update", logger.Ctx{ + "project": dbInst.Project, + "instance": dbInst.Name, + "error": err, + }) + } + }) + return nil }) if err != nil { @@ -99,12 +115,29 @@ func storagePoolVolumeUpdateUsers(s *state.State, projectName string, oldPoolNam return err } + revert.Add(func() { + original := api.ProfilePut{ + Config: profile.Config, + Description: profile.Description, + Devices: profile.Devices, + } + err := doProfileUpdate(s, p, profile.Name, profileID, &profile, original) + if err != nil { + logger.Error("Failed reverting profile update", logger.Ctx{ + "project": p.Name, + "profile": profile.Name, + "error": err, + }) + } + }) + return nil }) if err != nil { return err } + revert.Success() return nil }