From 6206f0f10a34c0f0fa4fb9da4e2fb7d2ed67a9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Mon, 19 Feb 2024 10:11:09 +0100 Subject: [PATCH] lxd/storage/backend_lxd: Ensure storage snapshot check uses the drivers storage name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Pelizäus --- lxd/storage/backend_lxd.go | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go index f473974bf57f..6be76d78644a 100644 --- a/lxd/storage/backend_lxd.go +++ b/lxd/storage/backend_lxd.go @@ -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) @@ -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 } @@ -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 } @@ -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