[lxc-devel] [lxd/master] Storage: Fix snapshot remove subsequent

tomponline on Github lxc-bot at linuxcontainers.org
Fri Dec 18 12:19:55 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1406 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201218/bbe8136e/attachment.bin>
-------------- next part --------------
From 35398d973bb5e87d12a40fe46449a7da849c7f7d Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 18 Dec 2020 12:13:10 +0000
Subject: [PATCH 1/3] lxd/storage/drivers/driver/zfs/volumes: Error quoting in
 RestoreVolume

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/drivers/driver_zfs_volumes.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/drivers/driver_zfs_volumes.go b/lxd/storage/drivers/driver_zfs_volumes.go
index 29e38998d8..cec417f814 100644
--- a/lxd/storage/drivers/driver_zfs_volumes.go
+++ b/lxd/storage/drivers/driver_zfs_volumes.go
@@ -1788,14 +1788,14 @@ func (d *zfs) RestoreVolume(vol Volume, snapshotName string, op *operations.Oper
 
 		if strings.HasPrefix(entry, "@") {
 			// Located an internal snapshot.
-			return fmt.Errorf("Snapshot '%s' cannot be restored due to subsequent internal snapshot(s) (from a copy)", snapshotName)
+			return fmt.Errorf("Snapshot %q cannot be restored due to subsequent internal snapshot(s) (from a copy)", snapshotName)
 		}
 	}
 
 	// Check if snapshot removal is allowed.
 	if len(snapshots) > 0 {
 		if !shared.IsTrue(vol.ExpandedConfig("zfs.remove_snapshots")) {
-			return fmt.Errorf("Snapshot '%s' cannot be restored due to subsequent snapshot(s). Set zfs.remove_snapshots to override", snapshotName)
+			return fmt.Errorf("Snapshot %q cannot be restored due to subsequent snapshot(s). Set zfs.remove_snapshots to override", snapshotName)
 		}
 
 		// Setup custom error to tell the backend what to delete.

From 4efdfbc4fc20fdca860f99e9ac55d0948c3bd8ca Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 18 Dec 2020 12:13:35 +0000
Subject: [PATCH 2/3] lxd/storage/backend/lxd: Don't fail in
 DeleteInstanceSnapshot if volume DB record already deleted

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/backend_lxd.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 2ca935dc0c..8d3358b2ca 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1996,9 +1996,9 @@ func (b *lxdBackend) DeleteInstanceSnapshot(inst instance.Instance, op *operatio
 		return err
 	}
 
-	// Remove the snapshot volume record from the database.
+	// Remove the snapshot volume record from the database if exists.
 	err = b.state.Cluster.RemoveStoragePoolVolume(inst.Project(), drivers.GetSnapshotVolumeName(parentName, snapName), volDBType, b.ID())
-	if err != nil {
+	if err != nil && err != db.ErrNoSuchObject {
 		return err
 	}
 

From 841fcd1491216e470944a6c087a2e6fb61988e30 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Fri, 18 Dec 2020 12:14:16 +0000
Subject: [PATCH 3/3] lxd/storage/backend/lxd: Fix deleting subsequent
 snapshots for ZFS in RestoreInstanceSnapshot

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/backend_lxd.go | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 8d3358b2ca..09ff3c95c5 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -2064,23 +2064,25 @@ func (b *lxdBackend) RestoreInstanceSnapshot(inst instance.Instance, src instanc
 
 			// Go through all the snapshots.
 			for _, snap := range snaps {
-				_, snapName, _ := shared.InstanceGetParentAndSnapshotName(src.Name())
+				_, snapName, _ := shared.InstanceGetParentAndSnapshotName(snap.Name())
 				if !shared.StringInSlice(snapName, snapErr.Snapshots) {
 					continue
 				}
 
-				// Delete if listed.
-				err := b.DeleteInstanceSnapshot(snap, op)
+				// Delete snapshot instance if listed in the error as one that needs removing.
+				err := snap.Delete(true)
 				if err != nil {
 					return err
 				}
 			}
 
-			// Now try again.
+			// Now try restoring again.
 			err = b.driver.RestoreVolume(vol, snapshotName, op)
 			if err != nil {
 				return err
 			}
+
+			return nil
 		}
 
 		return err


More information about the lxc-devel mailing list