From 19f3bc00ee837a9622c5a58630891be66bcf6a30 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Fri, 30 Oct 2015 14:55:52 -0400 Subject: [PATCH] Force IPC mount to unmount on daemon shutdown/init Instead of using `MNT_DETACH` to unmount the container's mqueue/shm mounts, force it... but only on daemon init and shutdown. This makes sure that these IPC mounts are cleaned up even when the daemon is killed. Signed-off-by: Brian Goff (cherry picked from commit 78bd17e805b7514505455b10f2fd90962505a3ff) --- daemon/container.go | 2 +- daemon/container_unix.go | 6 +++--- daemon/container_windows.go | 8 ++++++-- daemon/daemon.go | 3 ++- daemon/daemon_linux.go | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index 938bb3714..99c1d8447 100644 --- a/daemon/container.go +++ b/daemon/container.go @@ -333,7 +333,7 @@ func (streamConfig *streamConfig) StderrPipe() io.ReadCloser { func (container *Container) cleanup() { container.releaseNetwork() - if err := container.unmountIpcMounts(); err != nil { + if err := container.unmountIpcMounts(detachMounted); err != nil { logrus.Errorf("%s: Failed to umount ipc filesystems: %v", container.ID, err) } diff --git a/daemon/container_unix.go b/daemon/container_unix.go index 3c51de2ca..0035eeb57 100644 --- a/daemon/container_unix.go +++ b/daemon/container_unix.go @@ -1456,7 +1456,7 @@ func (container *Container) setupIpcDirs() error { return nil } -func (container *Container) unmountIpcMounts() error { +func (container *Container) unmountIpcMounts(unmount func(pth string) error) error { if container.hostConfig.IpcMode.IsContainer() || container.hostConfig.IpcMode.IsHost() { return nil } @@ -1469,7 +1469,7 @@ func (container *Container) unmountIpcMounts() error { logrus.Error(err) errors = append(errors, err.Error()) } else { - if err := detachMounted(shmPath); err != nil { + if err := unmount(shmPath); err != nil { logrus.Errorf("failed to umount %s: %v", shmPath, err) errors = append(errors, err.Error()) } @@ -1483,7 +1483,7 @@ func (container *Container) unmountIpcMounts() error { logrus.Error(err) errors = append(errors, err.Error()) } else { - if err := detachMounted(mqueuePath); err != nil { + if err := unmount(mqueuePath); err != nil { logrus.Errorf("failed to umount %s: %v", mqueuePath, err) errors = append(errors, err.Error()) } diff --git a/daemon/container_windows.go b/daemon/container_windows.go index f0d0c06ea..e97e753f5 100644 --- a/daemon/container_windows.go +++ b/daemon/container_windows.go @@ -183,11 +183,15 @@ func (container *Container) removeMountPoints(_ bool) error { return nil } -func (container *Container) setupIpcDirs() error { +func (container *Container) unmountIpcMounts(unmount func(pth string) error) error { return nil } -func (container *Container) unmountIpcMounts() error { +func detachMounted(path string) error { + return nil +} + +func (container *Container) setupIpcDirs() error { return nil } diff --git a/daemon/daemon.go b/daemon/daemon.go index 66e1a9d14..cf0430b29 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -38,6 +38,7 @@ import ( "github.com/docker/docker/pkg/graphdb" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/ioutils" + "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/namesgenerator" "github.com/docker/docker/pkg/nat" "github.com/docker/docker/pkg/parsers/filters" @@ -222,7 +223,7 @@ func (daemon *Daemon) Register(container *Container) error { } daemon.execDriver.Terminate(cmd) - if err := container.unmountIpcMounts(); err != nil { + if err := container.unmountIpcMounts(mount.Unmount); err != nil { logrus.Errorf("%s: Failed to umount ipc filesystems: %v", container.ID, err) } if err := container.Unmount(); err != nil { diff --git a/daemon/daemon_linux.go b/daemon/daemon_linux.go index 5355fd4f2..cda0e82e8 100644 --- a/daemon/daemon_linux.go +++ b/daemon/daemon_linux.go @@ -9,6 +9,7 @@ import ( "strings" "github.com/Sirupsen/logrus" + "github.com/docker/docker/pkg/mount" ) // cleanupMounts umounts shm/mqueue mounts for old containers @@ -20,7 +21,7 @@ func (daemon *Daemon) cleanupMounts() error { } defer f.Close() - return daemon.cleanupMountsFromReader(f, detachMounted) + return daemon.cleanupMountsFromReader(f, mount.Unmount) } func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {