[lxc-devel] [lxd/master] lxd/containers: Fix broken unix hotplug logic

stgraber on Github lxc-bot at linuxcontainers.org
Wed Apr 25 21:07:16 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 542 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180425/4e8d87b5/attachment.bin>
-------------- next part --------------
From 61f68f6bfa11916d158fe89e8e5934eb37d9464f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 25 Apr 2018 17:05:52 -0400
Subject: [PATCH] lxd/containers: Fix broken unix hotplug logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes:
 - Setup of the inotify watch when required=false
 - Empty file created when host file is missing
 - Validation error when required=false an path missing

Closes #4495

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

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 640dbc552..c1d7845b1 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1436,14 +1436,18 @@ func (c *containerLXC) initLXC(config bool) error {
 			if destPath == "" {
 				destPath = m["source"]
 			}
+
+			srcPath := m["source"]
+			if srcPath == "" {
+				srcPath = m["path"]
+			}
+
 			relativeDestPath := strings.TrimPrefix(destPath, "/")
 			sourceDevPath := filepath.Join(c.DevicesPath(), fmt.Sprintf("unix.%s.%s", strings.Replace(k, "/", "-", -1), strings.Replace(relativeDestPath, "/", "-", -1)))
 
-			// Do not fail to start when the device doesn't need to
-			// exist.
-			opts := "none bind,create=file"
-			if m["required"] != "" && !shared.IsTrue(m["required"]) {
-				opts = "none bind,create=file,optional"
+			// Don't add mount entry for devices that don't yet exist
+			if m["required"] != "" && !shared.IsTrue(m["required"]) && srcPath != "" && !shared.PathExists(srcPath) {
+				continue
 			}
 
 			// inform liblxc about the mount
@@ -1451,7 +1455,7 @@ func (c *containerLXC) initLXC(config bool) error {
 				fmt.Sprintf("%s %s %s",
 					shared.EscapePathFstab(sourceDevPath),
 					shared.EscapePathFstab(relativeDestPath),
-					opts))
+					"none bind,create=file"))
 			if err != nil {
 				return err
 			}
@@ -1812,16 +1816,15 @@ func (c *containerLXC) startCommon() (string, error) {
 			if !exist {
 				srcPath = m["path"]
 			}
-			if m["path"] != "" && m["major"] == "" && m["minor"] == "" && !shared.PathExists(srcPath) {
-				return "", fmt.Errorf("Missing source '%s' for device '%s'", srcPath, name)
-			}
 
-			if m["required"] != "" && !shared.IsTrue(m["required"]) {
-				err = deviceInotifyAddClosestLivingAncestor(c.state, srcPath)
+			if srcPath != "" && m["required"] != "" && !shared.IsTrue(m["required"]) {
+				err = deviceInotifyAddClosestLivingAncestor(c.state, filepath.Dir(srcPath))
 				if err != nil {
 					logger.Errorf("Failed to add \"%s\" to inotify targets", srcPath)
-					return "", err
+					return "", fmt.Errorf("Failed to setup inotify watch for '%s': %v", srcPath, err)
 				}
+			} else if srcPath != "" && m["major"] == "" && m["minor"] == "" && !shared.PathExists(srcPath) {
+				return "", fmt.Errorf("Missing source '%s' for device '%s'", srcPath, name)
 			}
 		}
 	}


More information about the lxc-devel mailing list