From 94172b42d638a01a74006281a55612b027aaf352 Mon Sep 17 00:00:00 2001 From: Allen Sun Date: Mon, 9 Apr 2018 14:51:17 +0800 Subject: [PATCH 1/3] refactor: simplify code to make function more readable Signed-off-by: Allen Sun Upstream-commit: a6379399818402be12b9d29e343d348031cbe62f Component: engine --- components/engine/daemon/exec.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/components/engine/daemon/exec.go b/components/engine/daemon/exec.go index 6a94aca417..1b4199ebb5 100644 --- a/components/engine/daemon/exec.go +++ b/components/engine/daemon/exec.go @@ -45,29 +45,29 @@ func (d *Daemon) ExecExists(name string) (bool, error) { // with the exec instance is stopped or paused, it will return an error. func (d *Daemon) getExecConfig(name string) (*exec.Config, error) { ec := d.execCommands.Get(name) + if ec == nil { + return nil, errExecNotFound(name) + } // If the exec is found but its container is not in the daemon's list of // containers then it must have been deleted, in which case instead of // saying the container isn't running, we should return a 404 so that // the user sees the same error now that they will after the // 5 minute clean-up loop is run which erases old/dead execs. - - if ec != nil { - if container := d.containers.Get(ec.ContainerID); container != nil { - if !container.IsRunning() { - return nil, fmt.Errorf("Container %s is not running: %s", container.ID, container.State.String()) - } - if container.IsPaused() { - return nil, errExecPaused(container.ID) - } - if container.IsRestarting() { - return nil, errContainerIsRestarting(container.ID) - } - return ec, nil - } + container := d.containers.Get(ec.ContainerID) + if container == nil { + return nil, containerNotFound(name) } - - return nil, errExecNotFound(name) + if !container.IsRunning() { + return nil, fmt.Errorf("Container %s is not running: %s", container.ID, container.State.String()) + } + if container.IsPaused() { + return nil, errExecPaused(container.ID) + } + if container.IsRestarting() { + return nil, errContainerIsRestarting(container.ID) + } + return ec, nil } func (d *Daemon) unregisterExecCommand(container *container.Container, execConfig *exec.Config) { From d10b7a563e9c4bb2d5eb06e71adb55be48767094 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 10 May 2018 01:55:27 +0200 Subject: [PATCH 2/3] Fix fluentd partial detection The Partial property of the Logger message was replaced by PLogMetaData, causing the build to fail. Signed-off-by: Sebastiaan van Stijn Upstream-commit: daaef83cd24f6eb335b77e9d8d692235eff1b201 Component: engine --- components/engine/daemon/logger/fluentd/fluentd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/daemon/logger/fluentd/fluentd.go b/components/engine/daemon/logger/fluentd/fluentd.go index 03c38749e2..907261f41f 100644 --- a/components/engine/daemon/logger/fluentd/fluentd.go +++ b/components/engine/daemon/logger/fluentd/fluentd.go @@ -163,7 +163,7 @@ func (f *fluentd) Log(msg *logger.Message) error { for k, v := range f.extra { data[k] = v } - if msg.Partial { + if msg.PLogMetaData != nil { data["partial_message"] = "true" } From 53eaee8346ed404621e360f3ae501457da30dbb2 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 10 May 2018 12:01:50 -0700 Subject: [PATCH 3/3] daemon.getSourceMount(): fix for / mount point A recent optimization in getSourceMount() made it return an error in case when the found mount point is "/". This prevented bind-mounted volumes from working in such cases. A (rather trivial but adeqate) unit test case is added. Fixes: 871c957242 ("getSourceMount(): simplify") Signed-off-by: Kir Kolyshkin Upstream-commit: d8fd6137a1f6d95a2bcdfeb6e1dfa6b816790c5e Component: engine --- components/engine/daemon/oci_linux.go | 8 +------- components/engine/daemon/oci_linux_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/components/engine/daemon/oci_linux.go b/components/engine/daemon/oci_linux.go index 62e7c7f1d6..766701a416 100644 --- a/components/engine/daemon/oci_linux.go +++ b/components/engine/daemon/oci_linux.go @@ -405,13 +405,7 @@ func getSourceMount(source string) (string, string, error) { idx = i } } - // and return it unless it's "/" - if mi[idx].Mountpoint != "/" { - return mi[idx].Mountpoint, mi[idx].Optional, nil - } - - // If we are here, we did not find parent mount. Something is wrong. - return "", "", fmt.Errorf("Could not find source mount of %s", source) + return mi[idx].Mountpoint, mi[idx].Optional, nil } const ( diff --git a/components/engine/daemon/oci_linux_test.go b/components/engine/daemon/oci_linux_test.go index 5f2731b8d6..e28fac004e 100644 --- a/components/engine/daemon/oci_linux_test.go +++ b/components/engine/daemon/oci_linux_test.go @@ -1,6 +1,7 @@ package daemon // import "github.com/docker/docker/daemon" import ( + "os" "testing" containertypes "github.com/docker/docker/api/types/container" @@ -86,3 +87,16 @@ func TestIpcPrivateVsReadonly(t *testing.T) { assert.Check(t, is.Equal(false, inSlice(m.Options, "ro"))) } } + +func TestGetSourceMount(t *testing.T) { + // must be able to find source mount for / + mnt, _, err := getSourceMount("/") + assert.NilError(t, err) + assert.Equal(t, mnt, "/") + + // must be able to find source mount for current directory + cwd, err := os.Getwd() + assert.NilError(t, err) + _, _, err = getSourceMount(cwd) + assert.NilError(t, err) +}