1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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 <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2015-10-30 14:55:52 -04:00
parent 0aa3bff482
commit 78bd17e805
5 changed files with 13 additions and 7 deletions

View file

@ -337,7 +337,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)
}

View file

@ -1359,7 +1359,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
}
@ -1372,7 +1372,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())
}
@ -1386,7 +1386,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())
}

View file

@ -185,7 +185,11 @@ func (container *Container) setupIpcDirs() error {
return nil
}
func (container *Container) unmountIpcMounts() error {
func (container *Container) unmountIpcMounts(unmount func(pth string) error) error {
return nil
}
func detachMounted(path string) error {
return nil
}

View file

@ -39,6 +39,7 @@ import (
"github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/jsonmessage"
"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"
@ -223,7 +224,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 {

View file

@ -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 {