[lxc-devel] [lxd/master] Storage: Triggers backup file update at end of BackupInstance
tomponline on Github
lxc-bot at linuxcontainers.org
Fri Jan 10 14:00:12 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 392 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200110/c25e54f5/attachment.bin>
-------------- next part --------------
From 65b81410a6ce9036ed3334f75541d113ffd0d627 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 10 Jan 2020 13:58:07 +0000
Subject: [PATCH] lxd/storage/backend/lxd: Triggers backup file update at end
of BackupInstance
Also improves revert logic.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/storage/backend_lxd.go | 42 ++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 11 deletions(-)
diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index b046e0987d..479a39af5e 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1358,6 +1358,12 @@ func (b *lxdBackend) BackupInstance(inst instance.Instance, targetPath string, o
// Get the volume name on storage.
volStorageName := project.Prefix(inst.Project(), inst.Name())
+ // Ensure the backup file reflects current config.
+ err = b.UpdateInstanceBackupFile(inst, op)
+ if err != nil {
+ return err
+ }
+
vol := b.newVolume(volType, contentType, volStorageName, rootDiskConf)
err = b.driver.BackupVolume(vol, targetPath, optimized, snapshots, op)
if err != nil {
@@ -1563,6 +1569,9 @@ func (b *lxdBackend) RenameInstanceSnapshot(inst instance.Instance, newName stri
logger.Debug("RenameInstanceSnapshot started")
defer logger.Debug("RenameInstanceSnapshot finished")
+ revert := revert.New()
+ defer revert.Fail()
+
if !inst.IsSnapshot() {
return fmt.Errorf("Instance must be a snapshot")
}
@@ -1590,28 +1599,39 @@ func (b *lxdBackend) RenameInstanceSnapshot(inst instance.Instance, newName stri
contentType := InstanceContentType(inst)
volStorageName := project.Prefix(inst.Project(), inst.Name())
- // Rename storage volume snapshot.
- // There's no need to pass config as it's not needed when renaming a volume
- // snapshot.
- vol := b.newVolume(volType, contentType, volStorageName, nil)
-
- err = b.driver.RenameVolumeSnapshot(vol, newName, op)
+ // Rename storage volume snapshot. No need to pass config as it's not needed when renaming a volume.
+ snapVol := b.newVolume(volType, contentType, volStorageName, nil)
+ err = b.driver.RenameVolumeSnapshot(snapVol, newName, op)
if err != nil {
return err
}
newVolName := drivers.GetSnapshotVolumeName(parentName, newName)
+
+ revert.Add(func() {
+ // Revert rename. No need to pass config as it's not needed when renaming a volume.
+ newSnapVol := b.newVolume(volType, contentType, project.Prefix(inst.Project(), newVolName), nil)
+ b.driver.RenameVolumeSnapshot(newSnapVol, oldSnapshotName, op)
+ })
+
+ // Rename DB volume record.
err = b.state.Cluster.StoragePoolVolumeRename(inst.Project(), inst.Name(), newVolName, volDBType, b.ID())
if err != nil {
- // Revert rename.
- // There's no need to pass config as it's not needed when renaming a
- // volume snapshot.
- vol := b.newVolume(volType, contentType, newName, nil)
+ return err
+ }
- b.driver.RenameVolumeSnapshot(vol, oldSnapshotName, op)
+ revert.Add(func() {
+ // Rename DB volume record back.
+ b.state.Cluster.StoragePoolVolumeRename(inst.Project(), newVolName, inst.Name(), volDBType, b.ID())
+ })
+
+ // Ensure the backup file reflects current config.
+ err = b.UpdateInstanceBackupFile(inst, op)
+ if err != nil {
return err
}
+ revert.Success()
return nil
}
More information about the lxc-devel
mailing list