[lxc-devel] [lxd/master] lxd/containers: Adapt to go-lxc Release

stgraber on Github lxc-bot at linuxcontainers.org
Mon Jan 7 21:29:21 UTC 2019


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/20190107/91bbe4a4/attachment.bin>
-------------- next part --------------
From 5ffb1c503a6a674f9d656feb2c8cc1e629c051bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 7 Jan 2019 16:09:16 -0500
Subject: [PATCH] lxd/containers: Adapt to go-lxc Release
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 | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 998358b459..6440c69411 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -497,7 +497,7 @@ func containerLXCLoad(s *state.State, args db.ContainerArgs, profiles []api.Prof
 func containerLXCUnload(c *containerLXC) {
 	runtime.SetFinalizer(c, nil)
 	if c.c != nil {
-		lxc.Release(c.c)
+		c.c.Release()
 		c.c = nil
 	}
 }
@@ -918,6 +918,13 @@ func (c *containerLXC) initLXC(config bool) error {
 		return err
 	}
 
+	freeContainer := true
+	defer func() {
+		if freeContainer {
+			cc.Release()
+		}
+	}()
+
 	// Setup logging
 	logfile := c.LogFilePath()
 	err = lxcSetConfigItem(cc, "lxc.log.file", logfile)
@@ -961,7 +968,12 @@ func (c *containerLXC) initLXC(config bool) error {
 	// Allow for lightweight init
 	c.cConfig = config
 	if !config {
+		if c.c != nil {
+			c.c.Release()
+		}
+
 		c.c = cc
+		freeContainer = false
 		return nil
 	}
 
@@ -1756,7 +1768,11 @@ func (c *containerLXC) initLXC(config bool) error {
 		}
 	}
 
+	if c.c != nil {
+		c.c.Release()
+	}
 	c.c = cc
+	freeContainer = false
 
 	return nil
 }
@@ -3684,7 +3700,11 @@ func (c *containerLXC) Rename(newName string) error {
 	c.storage.SetStoragePoolVolumeWritable(&sNew)
 
 	// Invalidate the go-lxc cache
-	c.c = nil
+	if c.c != nil {
+		c.c.Release()
+		c.c = nil
+	}
+
 	c.cConfig = false
 
 	// Update lease files
@@ -3999,7 +4019,10 @@ func (c *containerLXC) Update(args db.ContainerArgs, userRequested bool) error {
 			c.localConfig = oldLocalConfig
 			c.localDevices = oldLocalDevices
 			c.profiles = oldProfiles
-			c.c = nil
+			if c.c != nil {
+				c.c.Release()
+				c.c = nil
+			}
 			c.cConfig = false
 			c.initLXC(true)
 			deviceTaskSchedulerTrigger("container", c.name, "changed")
@@ -4059,7 +4082,10 @@ func (c *containerLXC) Update(args db.ContainerArgs, userRequested bool) error {
 	}
 
 	// Run through initLXC to catch anything we missed
-	c.c = nil
+	if c.c != nil {
+		c.c.Release()
+		c.c = nil
+	}
 	c.cConfig = false
 	err = c.initLXC(true)
 	if err != nil {
@@ -7627,7 +7653,7 @@ func (c *containerLXC) fillNetworkDevice(name string, m types.Device) (types.Dev
 		cname := projectPrefix(c.Project(), c.Name())
 		cc, err := lxc.NewContainer(cname, c.state.OS.LxcPath)
 		if err == nil {
-			defer lxc.Release(cc)
+			defer cc.Release()
 
 			interfaces, err := cc.Interfaces()
 			if err == nil {
@@ -7894,7 +7920,7 @@ func (c *containerLXC) removeNetworkDevice(name string, m types.Device) error {
 	if err != nil {
 		return err
 	}
-	defer lxc.Release(cc)
+	defer cc.Release()
 
 	// Remove the interface from the container
 	err = cc.DetachInterfaceRename(m["name"], hostName)


More information about the lxc-devel mailing list