[lxc-devel] [lxd/master] Bugfixes

stgraber on Github lxc-bot at linuxcontainers.org
Thu Mar 17 19:47:28 UTC 2016


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/20160317/30dffb2f/attachment.bin>
-------------- next part --------------
From 1c1d595f10b44c5ac8dac2f8e61e6d120413ece2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 17 Mar 2016 15:06:46 -0400
Subject: [PATCH 1/2] Improve error reporting on image POST
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #1772

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

diff --git a/lxd/images.go b/lxd/images.go
index 96a9f8e..b0cef5b 100644
--- a/lxd/images.go
+++ b/lxd/images.go
@@ -651,9 +651,16 @@ func imagesPost(d *Daemon, r *http.Request) Response {
 	// Is this a container request?
 	post.Seek(0, 0)
 	decoder := json.NewDecoder(post)
+	imageUpload := false
+
 	req := imagePostReq{}
 	err = decoder.Decode(&req)
-	imageUpload := err != nil
+	if err != nil {
+		if r.Header.Get("Content-Type") == "application/json" {
+			return BadRequest(err)
+		}
+		imageUpload = true
+	}
 
 	if !imageUpload && !shared.StringInSlice(req.Source["type"], []string{"container", "snapshot", "image", "url"}) {
 		cleanup(builddir, post)

From d43a119b8ffcb9e58809c6c4e67209acc066118f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 17 Mar 2016 15:46:42 -0400
Subject: [PATCH 2/2] Fix error handling logic around snapshots
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes #1768

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

diff --git a/lxd/container.go b/lxd/container.go
index e0b02c8..b5bea0e 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -482,26 +482,18 @@ func containerCreateAsCopy(d *Daemon, args containerArgs, sourceContainer contai
 }
 
 func containerCreateAsSnapshot(d *Daemon, args containerArgs, sourceContainer container) (container, error) {
-	// Create the snapshot
-	c, err := containerCreateInternal(d, args)
-	if err != nil {
-		return nil, err
-	}
-
 	// Deal with state
 	if args.Stateful {
+		if !sourceContainer.IsRunning() {
+			return nil, fmt.Errorf("Container not running, cannot do stateful snapshot")
+		}
+
 		stateDir := sourceContainer.StatePath()
-		err = os.MkdirAll(stateDir, 0700)
+		err := os.MkdirAll(stateDir, 0700)
 		if err != nil {
-			c.Delete()
 			return nil, err
 		}
 
-		if !sourceContainer.IsRunning() {
-			c.Delete()
-			return nil, fmt.Errorf("Container not running, cannot do stateful snapshot")
-		}
-
 		/* TODO: ideally we would freeze here and unfreeze below after
 		 * we've copied the filesystem, to make sure there are no
 		 * changes by the container while snapshotting. Unfortunately
@@ -520,10 +512,17 @@ func containerCreateAsSnapshot(d *Daemon, args containerArgs, sourceContainer co
 		}
 
 		if err != nil {
+			os.RemoveAll(sourceContainer.StatePath())
 			return nil, err
 		}
 	}
 
+	// Create the snapshot
+	c, err := containerCreateInternal(d, args)
+	if err != nil {
+		return nil, err
+	}
+
 	// Clone the container
 	if err := sourceContainer.Storage().ContainerSnapshotCreate(c, sourceContainer); err != nil {
 		c.Delete()


More information about the lxc-devel mailing list