Skip to content

Commit

Permalink
lxd/storage/backend_lxd: Set the volume's UUID at the right place for…
Browse files Browse the repository at this point in the history
… instance migration

Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Feb 19, 2024
1 parent be44fcc commit 04c8e86
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,13 @@ func (b *lxdBackend) CreateInstanceFromMigration(inst instance.Instance, conn io
} else if srcInfo != nil && srcInfo.Config != nil && srcInfo.Config.Volume != nil {
volumeConfig = srcInfo.Config.Volume.Config
volumeDescription = srcInfo.Config.Volume.Description

// Override the source volume's UUID.
// Do this before asking the storage driver if it has the volume.
// Some storage drivers might require the UUID to generate the volume name.
volumeConfig["volatile.uuid"] = uuid.New().String()
} else {
// A new UUID gets created during creation of the record in the DB.
volumeConfig = make(map[string]string)
volumeDescription = args.Description
}
Expand Down Expand Up @@ -2017,12 +2023,9 @@ func (b *lxdBackend) CreateInstanceFromMigration(inst instance.Instance, conn io
return fmt.Errorf("Cannot create volume, already exists on migration target storage")
}
} else {
// Delete the source volume's UUID.
// A new one gets set when creating the record in the DB.
delete(vol.Config(), "volatile.uuid")

// Validate config and create database entry for new storage volume if not refreshing.
// Strip unsupported config keys (in case the export was made from a different type of storage pool).
// A new UUID got already set before.
err = VolumeDBCreate(b, inst.Project().Name, inst.Name(), volumeDescription, volType, false, vol.Config(), inst.CreationDate(), time.Time{}, contentType, true, true)
if err != nil {
return err
Expand Down Expand Up @@ -5165,6 +5168,10 @@ func (b *lxdBackend) CreateCustomVolumeFromMigration(projectName string, conn io
volumeConfig = dbVol.Config
} else {
volumeConfig = args.Config

// Set a new UUID in case the target volume doesn't yet exist.
// Some storage drivers might require the UUID to generate the volume name.
volumeConfig["volatile.uuid"] = uuid.New().String()
}

// Check if the volume exists on storage.
Expand Down Expand Up @@ -5212,12 +5219,9 @@ func (b *lxdBackend) CreateCustomVolumeFromMigration(projectName string, conn io
defer revert.Fail()

if !args.Refresh {
// Delete the source volume's UUID.
// A new one gets set when creating the record in the DB.
delete(vol.Config(), "volatile.uuid")

// Validate config and create database entry for new storage volume.
// Strip unsupported config keys (in case the export was made from a different type of storage pool).
// A new UUID got already set before.
err = VolumeDBCreate(b, projectName, args.Name, args.Description, vol.Type(), false, vol.Config(), time.Now().UTC(), time.Time{}, vol.ContentType(), true, true)
if err != nil {
return err
Expand Down

0 comments on commit 04c8e86

Please sign in to comment.