[lxc-devel] [lxd/master] lxd/instance: Always put snapshots on same pool as parent

stgraber on Github lxc-bot at linuxcontainers.org
Mon Aug 24 22:07:06 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 468 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200824/f4b0c220/attachment.bin>
-------------- next part --------------
From 9757b39a25b28c0f9765e65ddc7b18ed9c254f14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 24 Aug 2020 18:06:19 -0400
Subject: [PATCH] lxd/instance: Always put snapshots on same pool as parent
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/instance/drivers/driver_lxc.go  | 17 ++++++++++++++++-
 lxd/instance/drivers/driver_qemu.go | 18 +++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 85b796ac91..bc4669a06b 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -207,7 +207,22 @@ func lxcCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
 	}
 
 	// Retrieve the container's storage pool
-	_, rootDiskDevice, err := shared.GetRootDiskDevice(c.expandedDevices.CloneNative())
+	var storageInstance instance.Instance
+	if c.IsSnapshot() {
+		parentName, _, _ := shared.InstanceGetParentAndSnapshotName(c.name)
+
+		// Load the parent
+		storageInstance, err = instance.LoadByProjectAndName(c.state, c.project, parentName)
+		if err != nil {
+			c.Delete()
+			logger.Error("Failed creating container", ctxMap)
+			return nil, errors.Wrap(err, "Invalid parent")
+		}
+	} else {
+		storageInstance = c
+	}
+
+	_, rootDiskDevice, err := shared.GetRootDiskDevice(storageInstance.ExpandedDevices().CloneNative())
 	if err != nil {
 		c.Delete()
 		return nil, err
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 793d3668a3..90cb7045f5 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -225,8 +225,24 @@ func qemuCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
 		return nil, errors.Wrap(err, "Invalid devices")
 	}
 
+	// Retrieve the container's storage pool
+	var storageInstance instance.Instance
+	if vm.IsSnapshot() {
+		parentName, _, _ := shared.InstanceGetParentAndSnapshotName(vm.name)
+
+		// Load the parent
+		storageInstance, err = instance.LoadByProjectAndName(vm.state, vm.project, parentName)
+		if err != nil {
+			vm.Delete()
+			logger.Error("Failed creating instance", ctxMap)
+			return nil, errors.Wrap(err, "Invalid parent")
+		}
+	} else {
+		storageInstance = vm
+	}
+
 	// Retrieve the instance's storage pool.
-	_, rootDiskDevice, err := shared.GetRootDiskDevice(vm.expandedDevices.CloneNative())
+	_, rootDiskDevice, err := shared.GetRootDiskDevice(storageInstance.ExpandedDevices().CloneNative())
 	if err != nil {
 		return nil, err
 	}


More information about the lxc-devel mailing list