[lxc-devel] [lxd/master] Storage: Only apply config changes when restoring snapshot if non-nil config is supplied

tomponline on Github lxc-bot at linuxcontainers.org
Tue Sep 1 16:50:30 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 496 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200901/d2251a85/attachment.bin>
-------------- next part --------------
From a4ac1148607aa6a39d6b73cacc751e2dae937b3b Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Sep 2020 17:48:01 +0100
Subject: [PATCH] lxd/storage/volumes: Only apply config changes when restoring
 snapshot if non-nil config is supplied

Fixes #7831

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

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index ba15bd80bf..f00d210fbb 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -968,9 +968,13 @@ func storagePoolVolumeTypePut(d *Daemon, r *http.Request, volumeTypeName string)
 		}
 
 		// Handle custom volume update requests.
-		err = pool.UpdateCustomVolume(projectName, vol.Name, req.Description, req.Config, nil)
-		if err != nil {
-			return response.SmartError(err)
+		// Only apply changes during a snapshot restore if a non-nil config is supplied to avoid clearing
+		// the volume's config if only restoring snapshot.
+		if req.Restore != "" && req.Config != nil || req.Restore == "" {
+			err = pool.UpdateCustomVolume(projectName, vol.Name, req.Description, req.Config, nil)
+			if err != nil {
+				return response.SmartError(err)
+			}
 		}
 	} else if volumeType == db.StoragePoolVolumeTypeContainer || volumeType == db.StoragePoolVolumeTypeVM {
 		inst, err := instance.LoadByProjectAndName(d.State(), projectName, vol.Name)


More information about the lxc-devel mailing list