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

UnmountIpcMount: simplify

As standard mount.Unmount does what we need, let's use it.

In addition, this adds ignoring "not mounted" condition, which
was previously implemented (see PR#33329, commit cfa2591d3f)
via a very expensive call to mount.Mounted().

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2018-10-24 17:29:03 -07:00
parent 8072e62d83
commit 77bc327e24
5 changed files with 6 additions and 16 deletions

View file

@ -174,8 +174,8 @@ func (container *Container) HasMountFor(path string) bool {
return false
}
// UnmountIpcMount uses the provided unmount function to unmount shm if it was mounted
func (container *Container) UnmountIpcMount(unmount func(pth string) error) error {
// UnmountIpcMount unmounts shm if it was mounted
func (container *Container) UnmountIpcMount() error {
if container.HasMountFor("/dev/shm") {
return nil
}
@ -189,10 +189,8 @@ func (container *Container) UnmountIpcMount(unmount func(pth string) error) erro
if shmPath == "" {
return nil
}
if err = unmount(shmPath); err != nil && !os.IsNotExist(err) {
if mounted, mErr := mount.Mounted(shmPath); mounted || mErr != nil {
return errors.Wrapf(err, "umount %s", shmPath)
}
if err = mount.Unmount(shmPath); err != nil && !os.IsNotExist(err) {
return errors.Wrapf(err, "umount %s", shmPath)
}
return nil
}

View file

@ -22,7 +22,7 @@ const (
// UnmountIpcMount unmounts Ipc related mounts.
// This is a NOOP on windows.
func (container *Container) UnmountIpcMount(unmount func(pth string) error) error {
func (container *Container) UnmountIpcMount() error {
return nil
}

View file

@ -351,10 +351,6 @@ func killProcessDirectly(cntr *container.Container) error {
return nil
}
func detachMounted(path string) error {
return unix.Unmount(path, unix.MNT_DETACH)
}
func isLinkable(child *container.Container) bool {
// A container is linkable only if it belongs to the default network
_, ok := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()]

View file

@ -78,10 +78,6 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
return nil
}
func detachMounted(path string) error {
return nil
}
func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
if len(c.SecretReferences) == 0 {
return nil

View file

@ -216,7 +216,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
func (daemon *Daemon) Cleanup(container *container.Container) {
daemon.releaseNetwork(container)
if err := container.UnmountIpcMount(detachMounted); err != nil {
if err := container.UnmountIpcMount(); err != nil {
logrus.Warnf("%s cleanup: failed to unmount IPC: %s", container.ID, err)
}