[lxc-devel] [lxd/master] migration: start migration storage at the right time

tych0 on Github lxc-bot at linuxcontainers.org
Mon Oct 24 22:51:16 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 804 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161024/6cd5a1a3/attachment.bin>
-------------- next part --------------
From 38d794806a8ca781a0ed69798c8a6e9ea8ea7a70 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Mon, 24 Oct 2016 15:19:12 -0600
Subject: [PATCH] migration: start migration storage at the right time

In particular: the migration storage might have been in use after a
migration, so it's not safe to stop it like we were before (presumably it
was giving EBUSY, but since we didn't cehck the return code it was ok).

Instead, let's only start it before we need it, and stop it when we're
done. The OnStart hook will start the storage again if it is needed by the
actual container, so we don't need to take care of that.

Closes #2505

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/containers_post.go | 6 ------
 lxd/storage.go         | 5 +++++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/lxd/containers_post.go b/lxd/containers_post.go
index 9b2d523..659de32 100644
--- a/lxd/containers_post.go
+++ b/lxd/containers_post.go
@@ -293,20 +293,14 @@ func createFromMigration(d *Daemon, req *containerPostReq) Response {
 	}
 
 	run := func(op *operation) error {
-		// Start the storage for this container (LVM mount/umount)
-		c.StorageStart()
-
 		// And finaly run the migration.
 		err = sink.Do(op)
 		if err != nil {
-			c.StorageStop()
 			shared.LogError("Error during migration sink", log.Ctx{"err": err})
 			c.Delete()
 			return fmt.Errorf("Error transferring container data: %s", err)
 		}
 
-		defer c.StorageStop()
-
 		err = c.TemplateApply("copy")
 		if err != nil {
 			return err
diff --git a/lxd/storage.go b/lxd/storage.go
index 7c25bfd..5bb94dc 100644
--- a/lxd/storage.go
+++ b/lxd/storage.go
@@ -702,6 +702,11 @@ func rsyncMigrationSink(live bool, container container, snapshots []*Snapshot, c
 			return err
 		}
 	} else {
+		if err := container.StorageStart(); err != nil {
+			return err
+		}
+		defer container.StorageStop()
+
 		for _, snap := range snapshots {
 			if err := RsyncRecv(shared.AddSlash(container.Path()), conn); err != nil {
 				return err


More information about the lxc-devel mailing list