The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7805

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Pretty much common sense, but in cases where we were overriding the target pool during a migration, this wasn't actually handled properly and would lead to odd errors.
From 9757b39a25b28c0f9765e65ddc7b18ed9c254f14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@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 <stgra...@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
        }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to