The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/4499
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === 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 <[email protected]>
From 61f68f6bfa11916d158fe89e8e5934eb37d9464f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <[email protected]> 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 <[email protected]> --- 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) } } }
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
