Skip to content

Commit

Permalink
lxd/storage/backend_lxd: Ensure storage snapshot check uses the drive…
Browse files Browse the repository at this point in the history
…rs storage name

Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Feb 19, 2024
1 parent 04c8e86 commit 6206f0f
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6401,8 +6401,9 @@ func (b *lxdBackend) CheckInstanceBackupFileSnapshots(backupConf *backupConfig.C
contentType = drivers.ContentTypeBlock
}

// We don't need to use the volume's config for mounting so set to nil.
vol := b.GetVolume(volType, contentType, volStorageName, nil)
// Use the volume's config from the backup config.
// Some storage drivers might require the UUID to generate the volume name.
vol := b.GetVolume(volType, contentType, volStorageName, backupConf.Volume.Config)

// Get a list of snapshots that exist on storage device.
driverSnapshots, err := vol.Snapshots(op)
Expand All @@ -6418,13 +6419,21 @@ func (b *lxdBackend) CheckInstanceBackupFileSnapshots(backupConf *backupConfig.C

// Check (and optionally delete) snapshots that do not exist in backup config.
for _, driverSnapVol := range driverSnapshots {
inBackupFile := false
_, driverSnapOnly, _ := api.GetParentAndSnapshotName(driverSnapVol.Name())
for _, backupFileSnap := range backupConf.VolumeSnapshots {
backupVol := drivers.NewVolume(b.driver, backupConf.Pool.Name, volType, contentType, backupConf.Container.Name, backupFileSnap.Config, nil)
backupSnapVol, err := backupVol.NewSnapshot(backupFileSnap.Name)
if err != nil {
return nil, err
}

inBackupFile := false
for _, backupFileSnap := range backupConf.Snapshots {
backupFileSnapOnly := backupFileSnap.Name
backupSnapVolName, err := b.driver.GetVolumeStorageName(backupSnapVol)
if err != nil {
return nil, err
}

if driverSnapOnly == backupFileSnapOnly {
if driverSnapOnly == backupSnapVolName {
inBackupFile = true
break
}
Expand All @@ -6448,13 +6457,23 @@ func (b *lxdBackend) CheckInstanceBackupFileSnapshots(backupConf *backupConfig.C

// Check the snapshots in backup config exist on storage device.
existingSnapshots := []*api.InstanceSnapshot{}
for _, backupFileSnap := range backupConf.Snapshots {
for i, backupFileSnap := range backupConf.VolumeSnapshots {
backupFileSnapOnly := backupFileSnap.Name
backupVol := drivers.NewVolume(b.driver, backupConf.Pool.Name, volType, contentType, backupConf.Container.Name, backupFileSnap.Config, nil)
backupSnapVol, err := backupVol.NewSnapshot(backupFileSnap.Name)
if err != nil {
return nil, err
}

backupSnapVolName, err := b.driver.GetVolumeStorageName(backupSnapVol)
if err != nil {
return nil, err
}

onStorageDevice := false
for _, driverSnapVol := range driverSnapshots {
_, driverSnapOnly, _ := api.GetParentAndSnapshotName(driverSnapVol.Name())
if driverSnapOnly == backupFileSnapOnly {
if driverSnapOnly == backupSnapVolName {
onStorageDevice = true
break
}
Expand All @@ -6469,7 +6488,8 @@ func (b *lxdBackend) CheckInstanceBackupFileSnapshots(backupConf *backupConfig.C
continue // Skip snapshots missing on storage device.
}

existingSnapshots = append(existingSnapshots, backupFileSnap)
// Take the instance snapshot after confirming its volume exists.
existingSnapshots = append(existingSnapshots, backupConf.Snapshots[i])
}

return existingSnapshots, nil
Expand Down

0 comments on commit 6206f0f

Please sign in to comment.