[lxc-devel] [lxd/master] Bugfixes

stgraber on Github lxc-bot at linuxcontainers.org
Wed Feb 1 18:02:25 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170201/2211380f/attachment.bin>
-------------- next part --------------
From c0334e2f5ac5c33cfdd6488e9237ecf5afc074e4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 1 Feb 2017 18:02:52 +0100
Subject: [PATCH 1/2] Clarify CRIU related errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/container.go     | 10 ++++++----
 lxd/container_lxc.go | 19 ++++++-------------
 lxd/migrate.go       | 12 +++++++-----
 3 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/lxd/container.go b/lxd/container.go
index 2721f47..c151d5f 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"io"
 	"os"
+	"os/exec"
 	"strings"
 	"time"
 
@@ -527,15 +528,16 @@ func containerCreateAsSnapshot(d *Daemon, args containerArgs, sourceContainer co
 	// Deal with state
 	if args.Stateful {
 		if !sourceContainer.IsRunning() {
-			return nil, fmt.Errorf("Container not running, cannot do stateful snapshot")
+			return nil, fmt.Errorf("Unable to create a stateful snapshot. The container isn't running.")
 		}
 
-		if err := findCriu("snapshot"); err != nil {
-			return nil, err
+		_, err := exec.LookPath("criu")
+		if err != nil {
+			return nil, fmt.Errorf("Unable to create a stateful snapshot. CRIU isn't installed.")
 		}
 
 		stateDir := sourceContainer.StatePath()
-		err := os.MkdirAll(stateDir, 0700)
+		err = os.MkdirAll(stateDir, 0700)
 		if err != nil {
 			return nil, err
 		}
diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 631ebfd..2b505b1 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -2509,8 +2509,9 @@ func (c *containerLXC) Restore(sourceContainer container) error {
 	 * filesystem manipulations
 	 */
 	if shared.PathExists(c.StatePath()) {
-		if err := findCriu("snapshot"); err != nil {
-			return err
+		_, err := exec.LookPath("criu")
+		if err != nil {
+			return fmt.Errorf("Failed to restore container state. CRIU isn't installed.")
 		}
 	}
 
@@ -3897,15 +3898,6 @@ func getCRIULogErrors(imagesDir string, method string) (string, error) {
 	return strings.Join(ret, "\n"), nil
 }
 
-func findCriu(host string) error {
-	_, err := exec.LookPath("criu")
-	if err != nil {
-		return fmt.Errorf("CRIU is required for live migration but its binary couldn't be found on the %s server. Is it installed in LXD's path?", host)
-	}
-
-	return nil
-}
-
 func (c *containerLXC) Migrate(cmd uint, stateDir string, function string, stop bool, actionScript bool) error {
 	ctxMap := log.Ctx{"name": c.name,
 		"created":      c.creationDate,
@@ -3915,8 +3907,9 @@ func (c *containerLXC) Migrate(cmd uint, stateDir string, function string, stop
 		"actionscript": actionScript,
 		"stop":         stop}
 
-	if err := findCriu(function); err != nil {
-		return err
+	_, err := exec.LookPath("criu")
+	if err != nil {
+		return fmt.Errorf("Unable to perform container live migration. CRIU isn't installed.")
 	}
 
 	shared.LogInfo("Migrating container", ctxMap)
diff --git a/lxd/migrate.go b/lxd/migrate.go
index db753d0..7e854c7 100644
--- a/lxd/migrate.go
+++ b/lxd/migrate.go
@@ -11,6 +11,7 @@ import (
 	"net/http"
 	"net/url"
 	"os"
+	"os/exec"
 	"path/filepath"
 	"strings"
 	"sync"
@@ -166,8 +167,9 @@ func NewMigrationSource(c container) (*migrationSourceWs, error) {
 	}
 
 	if c.IsRunning() {
-		if err := findCriu("source"); err != nil {
-			return nil, err
+		_, err := exec.LookPath("criu")
+		if err != nil {
+			return nil, fmt.Errorf("Unable to perform container live migration. CRIU isn't installed on the source server.")
 		}
 
 		ret.live = true
@@ -594,11 +596,11 @@ func NewMigrationSink(args *MigrationSinkArgs) (*migrationSink, error) {
 		sink.src.live = ok
 	}
 
-	err = findCriu("destination")
+	_, err = exec.LookPath("criu")
 	if sink.push && sink.dest.live && err != nil {
-		return nil, err
+		return nil, fmt.Errorf("Unable to perform container live migration. CRIU isn't installed on the destination server.")
 	} else if sink.src.live && err != nil {
-		return nil, err
+		return nil, fmt.Errorf("Unable to perform container live migration. CRIU isn't installed on the destination server.")
 	}
 
 	return &sink, nil

From 7371ead4bb98a53e13a29ff331b0649016443eb5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 1 Feb 2017 19:01:47 +0100
Subject: [PATCH 2/2] Don't report migration success on failure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 2b505b1..dbfbb52 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -4042,11 +4042,13 @@ func (c *containerLXC) Migrate(cmd uint, stateDir string, function string, stop
 			shared.LogInfo("Failed migrating container", ctxMap)
 			migrateErr = fmt.Errorf("%s %s failed\n%s", function, prettyCmd, log)
 		}
+
+		return migrateErr
 	}
 
 	shared.LogInfo("Migrated container", ctxMap)
 
-	return migrateErr
+	return nil
 }
 
 func (c *containerLXC) TemplateApply(trigger string) error {


More information about the lxc-devel mailing list