[lxc-devel] [lxd/master] container: remove from db on storage failure

brauner on Github lxc-bot at linuxcontainers.org
Thu Sep 7 22:46:16 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 381 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170907/dd3ed079/attachment.bin>
-------------- next part --------------
From bddaa8238a37264348c758bad81ed9dd9bdf021e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Fri, 8 Sep 2017 00:41:30 +0200
Subject: [PATCH] container: remove from db on storage failure

Closes #3782.

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 lxd/container.go | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lxd/container.go b/lxd/container.go
index 295d1c579..a427ae84a 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -510,7 +510,7 @@ func containerCreateAsEmpty(d *Daemon, args db.ContainerArgs) (container, error)
 
 	// Now create the empty storage
 	if err := c.Storage().ContainerCreate(c); err != nil {
-		c.Delete()
+		db.ContainerRemove(d.db, args.Name)
 		return nil, err
 	}
 
@@ -533,7 +533,7 @@ func containerCreateEmptySnapshot(s *state.State, args db.ContainerArgs) (contai
 
 	// Now create the empty snapshot
 	if err := c.Storage().ContainerSnapshotCreateEmpty(c); err != nil {
-		c.Delete()
+		db.ContainerRemove(s.DB, args.Name)
 		return nil, err
 	}
 
@@ -564,12 +564,13 @@ func containerCreateFromImage(s *state.State, args db.ContainerArgs, hash string
 	}
 
 	if err := db.ImageLastAccessUpdate(s.DB, hash, time.Now().UTC()); err != nil {
+		db.ContainerRemove(s.DB, args.Name)
 		return nil, fmt.Errorf("Error updating image last use date: %s", err)
 	}
 
 	// Now create the storage from an image
 	if err := c.Storage().ContainerCreateFromImage(c, hash); err != nil {
-		c.Delete()
+		db.ContainerRemove(s.DB, args.Name)
 		return nil, err
 	}
 
@@ -594,6 +595,7 @@ func containerCreateAsCopy(s *state.State, args db.ContainerArgs, sourceContaine
 	if !containerOnly {
 		snapshots, err := sourceContainer.Snapshots()
 		if err != nil {
+			db.ContainerRemove(s.DB, args.Name)
 			return nil, err
 		}
 
@@ -623,7 +625,10 @@ func containerCreateAsCopy(s *state.State, args db.ContainerArgs, sourceContaine
 
 	// Now clone the storage.
 	if err := ct.Storage().ContainerCopy(ct, sourceContainer, containerOnly); err != nil {
-		ct.Delete()
+		for _, v := range csList {
+			db.ContainerRemove(s.DB, (*v).Name())
+		}
+		db.ContainerRemove(s.DB, args.Name)
 		return nil, err
 	}
 
@@ -691,7 +696,7 @@ func containerCreateAsSnapshot(s *state.State, args db.ContainerArgs, sourceCont
 
 	// Clone the container
 	if err := sourceContainer.Storage().ContainerSnapshotCreate(c, sourceContainer); err != nil {
-		c.Delete()
+		db.ContainerRemove(s.DB, args.Name)
 		return nil, err
 	}
 
@@ -802,6 +807,7 @@ func containerCreateInternal(s *state.State, args db.ContainerArgs) (container,
 	// Read the timestamp from the database
 	dbArgs, err := db.ContainerGet(s.DB, args.Name)
 	if err != nil {
+		db.ContainerRemove(s.DB, args.Name)
 		return nil, err
 	}
 	args.CreationDate = dbArgs.CreationDate
@@ -810,6 +816,7 @@ func containerCreateInternal(s *state.State, args db.ContainerArgs) (container,
 	// Setup the container struct and finish creation (storage and idmap)
 	c, err := containerLXCCreate(s, args)
 	if err != nil {
+		db.ContainerRemove(s.DB, args.Name)
 		return nil, err
 	}
 


More information about the lxc-devel mailing list