[lxc-devel] [lxd/master] lxd/containers: Fix snapshot restore on ephemeral

stgraber on Github lxc-bot at linuxcontainers.org
Fri Jul 5 19:13:49 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190705/a13f5631/attachment.bin>
-------------- next part --------------
From 5a531b4f078d409be758c8b26fcbadea79cc4e0f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 5 Jul 2019 15:13:13 -0400
Subject: [PATCH] lxd/containers: Fix snapshot restore on ephemeral
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #5906

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/container_lxc.go | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 3972dafbaa..86a03fc85d 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -4157,6 +4157,31 @@ func (c *containerLXC) Restore(sourceContainer container, stateful bool) error {
 	if c.IsRunning() {
 		wasRunning = true
 
+		ephemeral := c.IsEphemeral()
+		if ephemeral {
+			// Unset ephemeral flag
+			args := db.ContainerArgs{
+				Architecture: c.Architecture(),
+				Config:       c.LocalConfig(),
+				Description:  c.Description(),
+				Devices:      c.LocalDevices(),
+				Ephemeral:    false,
+				Profiles:     c.Profiles(),
+				Project:      c.Project(),
+			}
+
+			err := c.Update(args, false)
+			if err != nil {
+				return err
+			}
+
+			// On function return, set the flag back on
+			defer func() {
+				args.Ephemeral = ephemeral
+				c.Update(args, true)
+			}()
+		}
+
 		// This will unmount the container storage.
 		err := c.Stop(false)
 		if err != nil {


More information about the lxc-devel mailing list