[lxc-devel] [lxd/master] migration: don't defer cleanup of sending snapshots

tych0 on Github lxc-bot at linuxcontainers.org
Fri Mar 11 01:18:49 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 659 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160311/7feb233f/attachment.bin>
-------------- next part --------------
From eb2a87f8d939499a556b6e1c409ea2abd096318e Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Thu, 10 Mar 2016 18:10:00 -0700
Subject: [PATCH] migration: don't defer cleanup of sending snapshots

The problem here is that depending on the migration type, we might delete
the container on the source host directly after the migrate returns, which
can race with defer and cause the delete to fail. Instead, let's explicitly
delete the stuff we need to before returning, so there is no race.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/migrate.go | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lxd/migrate.go b/lxd/migrate.go
index 0150e66..aee88c1 100644
--- a/lxd/migrate.go
+++ b/lxd/migrate.go
@@ -341,19 +341,20 @@ func (s *migrationSourceWs) Do(op *operation) error {
 		driver, _ = rsyncMigrationSource(s.container)
 	}
 
-	defer driver.Cleanup()
-
 	if err := driver.SendWhileRunning(s.fsConn); err != nil {
+		driver.Cleanup()
 		s.sendControl(err)
 		return err
 	}
 
 	if s.live {
 		if header.Criu == nil {
+			driver.Cleanup()
 			err := fmt.Errorf("Got no CRIU socket type for live migration")
 			s.sendControl(err)
 			return err
 		} else if *header.Criu != CRIUType_CRIU_RSYNC {
+			driver.Cleanup()
 			err := fmt.Errorf("Formats other than criu rsync not understood")
 			s.sendControl(err)
 			return err
@@ -361,6 +362,7 @@ func (s *migrationSourceWs) Do(op *operation) error {
 
 		checkpointDir, err := ioutil.TempDir("", "lxd_checkpoint_")
 		if err != nil {
+			driver.Cleanup()
 			s.sendControl(err)
 			return err
 		}
@@ -374,6 +376,7 @@ func (s *migrationSourceWs) Do(op *operation) error {
 		}
 
 		if err != nil {
+			driver.Cleanup()
 			log, err2 := GetCRIULogErrors(checkpointDir, "dump")
 
 			/* couldn't find the CRIU log file which means we
@@ -396,16 +399,20 @@ func (s *migrationSourceWs) Do(op *operation) error {
 		 * p.haul's protocol, it will make sense to do these in parallel.
 		 */
 		if err := RsyncSend(shared.AddSlash(checkpointDir), s.criuConn); err != nil {
+			driver.Cleanup()
 			s.sendControl(err)
 			return err
 		}
 
 		if err := driver.SendAfterCheckpoint(s.fsConn); err != nil {
+			driver.Cleanup()
 			s.sendControl(err)
 			return err
 		}
 	}
 
+	driver.Cleanup()
+
 	msg := MigrationControl{}
 	if err := s.recv(&msg); err != nil {
 		s.disconnect()


More information about the lxc-devel mailing list