[lxc-devel] [lxd/master] Dont fail early removing disks

tych0 on Github lxc-bot at linuxcontainers.org
Thu Apr 28 17:53:20 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/20160428/df1088a9/attachment.bin>
-------------- next part --------------
From f43557585c709639f550ae9763a2a814c29bfb7c Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Thu, 28 Apr 2016 08:41:42 -0600
Subject: [PATCH 1/3] don't fail early when removing disks

We should try to unmount /everything/, no matter what.

Closes #1964

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/container_lxc.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 70f483f..009dac1 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -4005,9 +4005,10 @@ func (c *containerLXC) removeDiskDevices() error {
 		_ = syscall.Unmount(filepath.Join(c.DevicesPath(), f.Name()), syscall.MNT_DETACH)
 
 		// Remove the entry
-		err := os.Remove(filepath.Join(c.DevicesPath(), f.Name()))
+		diskPath := filepath.Join(c.DevicesPath(), f.Name())
+		err := os.Remove(diskPath)
 		if err != nil {
-			return err
+			shared.Log.Error("Failed to remove disk device path", log.Ctx{"err": err, "path": diskPath})
 		}
 	}
 

From 9f95110b41f118bf81fb81fa72e26e56359f329a Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Thu, 28 Apr 2016 11:34:06 -0600
Subject: [PATCH 2/3] devices cleanup: don't recursively delete devices

the remove{Unix,Char}Devices when successful should leave this directory
empty, and when they're not succesful the recursiveness has the potential
to delete external data if things aren't unmounted correctly.

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/container_lxc.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 009dac1..ffcd6fe 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1773,7 +1773,7 @@ func (c *containerLXC) cleanup() {
 	SeccompDeleteProfile(c)
 
 	// Remove the devices path
-	os.RemoveAll(c.DevicesPath())
+	os.Remove(c.DevicesPath())
 
 	// Remove the shmounts path
 	os.RemoveAll(shared.VarPath("shmounts", c.Name()))

From 52d8c8bddf1987e1baf0af7ccdc928f199e118b6 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen at canonical.com>
Date: Thu, 28 Apr 2016 11:51:24 -0600
Subject: [PATCH 3/3] as with disk devices, don't fail when some unix devices
 fail to be deleted

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
---
 lxd/container_lxc.go | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index ffcd6fe..5ec9e8e 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -3555,9 +3555,10 @@ func (c *containerLXC) removeUnixDevices() error {
 		}
 
 		// Remove the entry
-		err := os.Remove(filepath.Join(c.DevicesPath(), f.Name()))
+		devicePath := filepath.Join(c.DevicesPath(), f.Name())
+		err := os.Remove(devicePath)
 		if err != nil {
-			return err
+			shared.Log.Error("failed removing unix device", log.Ctx{"err": err, "path": devicePath})
 		}
 	}
 


More information about the lxc-devel mailing list