[lxc-devel] [lxd/master] migration: restore state when moving container

brauner on Github lxc-bot at linuxcontainers.org
Tue Sep 19 13:42:16 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 1018 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170919/b4d72d7b/attachment.bin>
-------------- next part --------------
From 646aa67e7c850589117f1b08011bd0082e478b17 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 19 Sep 2017 15:06:48 +0200
Subject: [PATCH 1/2] move: use force on delete

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxc/move.go | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lxc/move.go b/lxc/move.go
index 9ec50e59d..122f46fd1 100644
--- a/lxc/move.go
+++ b/lxc/move.go
@@ -98,12 +98,16 @@ func (c *moveCmd) run(conf *config.Config, args []string) error {
 
 	cpy := copyCmd{}
 
+	stateful := !c.stateless
+
 	// A move is just a copy followed by a delete; however, we want to
 	// keep the volatile entries around since we are moving the container.
-	err = cpy.copyContainer(conf, args[0], args[1], true, -1, true, c.containerOnly, mode)
+	err = cpy.copyContainer(conf, args[0], args[1], true, -1, stateful, c.containerOnly, mode)
 	if err != nil {
 		return err
 	}
 
-	return commands["delete"].run(conf, args[:1])
+	del := deleteCmd{}
+	del.force = true
+	return del.run(conf, args[:1])
 }

From 8949500b56603808f6555e8a49de7cfb765b246c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 19 Sep 2017 15:09:25 +0200
Subject: [PATCH 2/2] migration: restore state when moving container

When a container is running users can pass "--stateful" to the lxd command line
tool "lxc move". This will move the container and restore the state of the
container on the target.
My original implementation of this feature only applied to stateless container
copies but not to requests to move a container. The only thing we need to do is
pass the stateless argument along in the move codepath for the "lxc move"
command line tool and then restore state on the receiving side based on the
container's config. This is trivial since we know the source container's state
because we preserve volatile keys when moving containers.

Closes #3798.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/containers_post.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lxd/containers_post.go b/lxd/containers_post.go
index 0427b20bd..4bcf32e86 100644
--- a/lxd/containers_post.go
+++ b/lxd/containers_post.go
@@ -388,6 +388,12 @@ func createFromMigration(d *Daemon, req *api.ContainersPost) Response {
 			return err
 		}
 
+		if !migrationArgs.Live {
+			if req.Config["volatile.last_state.power"] == "RUNNING" {
+				return c.Start(false)
+			}
+		}
+
 		return nil
 	}
 


More information about the lxc-devel mailing list