[lxc-devel] [lxd/master] After stateful stop, mark the container DB entry

stgraber on Github lxc-bot at linuxcontainers.org
Mon Feb 29 21:33:51 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160229/e722cf20/attachment.bin>
-------------- next part --------------
From 73b8fb847f49e1da24a7c07b33afa1471c01ecfc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 29 Feb 2016 16:33:08 -0500
Subject: [PATCH] After stateful stop, mark the container DB entry
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 | 18 +++++++++++++++++-
 lxd/db_containers.go | 10 ++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 64594e1..a2b636e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1088,7 +1088,11 @@ func (c *containerLXC) Start(stateful bool) error {
 	}
 
 	// If stateful, restore now
-	if stateful && shared.PathExists(c.StatePath()) {
+	if stateful {
+		if !c.stateful {
+			return fmt.Errorf("Container has no existing state to restore.")
+		}
+
 		err := c.c.Restore(lxc.RestoreOptions{
 			Directory: c.StatePath(),
 			Verbose:   true,
@@ -1103,6 +1107,12 @@ func (c *containerLXC) Start(stateful bool) error {
 			return err
 		}
 
+		c.stateful = false
+		err = dbContainerSetStateful(c.daemon.db, c.id, false)
+		if err != nil {
+			return err
+		}
+
 		return nil
 	}
 
@@ -1279,6 +1289,12 @@ func (c *containerLXC) Stop(stateful bool) error {
 			return err
 		}
 
+		c.stateful = true
+		err = dbContainerSetStateful(c.daemon.db, c.id, true)
+		if err != nil {
+			return err
+		}
+
 		return nil
 	}
 
diff --git a/lxd/db_containers.go b/lxd/db_containers.go
index a6d2e84..28ce6f0 100644
--- a/lxd/db_containers.go
+++ b/lxd/db_containers.go
@@ -220,6 +220,16 @@ func dbContainerConfigRemove(db *sql.DB, id int, name string) error {
 	return err
 }
 
+func dbContainerSetStateful(db *sql.DB, id int, stateful bool) error {
+	statefulInt := 0
+	if stateful {
+		statefulInt = 1
+	}
+
+	_, err := dbExec(db, "UPDATE containers SET stateful=? WHERE id=?", statefulInt, id)
+	return err
+}
+
 func dbContainerProfilesInsert(tx *sql.Tx, id int, profiles []string) error {
 	applyOrder := 1
 	str := `INSERT INTO containers_profiles (container_id, profile_id, apply_order) VALUES


More information about the lxc-devel mailing list