From 3916561619d45a3d8ca17dfa467149824111023a Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 19 May 2015 09:32:19 -0700 Subject: [PATCH] Fix Put without Get in overlay It is called for example on daemon start after crash Signed-off-by: Alexander Morozov --- daemon/graphdriver/overlay/overlay.go | 8 ++++++++ integration-cli/docker_cli_daemon_test.go | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/daemon/graphdriver/overlay/overlay.go b/daemon/graphdriver/overlay/overlay.go index 5b0d3b7f53..df6a7dbd93 100644 --- a/daemon/graphdriver/overlay/overlay.go +++ b/daemon/graphdriver/overlay/overlay.go @@ -318,6 +318,14 @@ func (d *Driver) Put(id string) error { mount := d.active[id] if mount == nil { logrus.Debugf("Put on a non-mounted device %s", id) + // but it might be still here + if d.Exists(id) { + mergedDir := path.Join(d.dir(id), "merged") + err := syscall.Unmount(mergedDir, 0) + if err != nil { + logrus.Debugf("Failed to unmount %s overlay: %v", id, err) + } + } return nil } diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 65e1fed364..d907eacd76 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -1161,7 +1161,7 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) { runCommand(exec.Command(dockerBinary, args...)) } -func (s *DockerDaemonSuite) TestDaemonRestartWithSockerAsVolume(c *check.C) { +func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) { c.Assert(s.d.StartWithBusybox(), check.IsNil) socket := filepath.Join(s.d.folder, "docker.sock") @@ -1170,3 +1170,16 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithSockerAsVolume(c *check.C) { c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) c.Assert(s.d.Restart(), check.IsNil) } + +func (s *DockerDaemonSuite) TestCleanupMountsAfterCrash(c *check.C) { + c.Assert(s.d.StartWithBusybox(), check.IsNil) + + out, err := s.d.Cmd("run", "-d", "busybox", "top") + c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) + id := strings.TrimSpace(out) + c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil) + c.Assert(s.d.Start(), check.IsNil) + mountOut, err := exec.Command("mount").CombinedOutput() + c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) + c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, check.Commentf("Something mounted from older daemon start: %s", mountOut)) +}