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:
parent
8072e62d83
commit
77bc327e24
5 changed files with 6 additions and 16 deletions
|
@ -174,8 +174,8 @@ func (container *Container) HasMountFor(path string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmountIpcMount uses the provided unmount function to unmount shm if it was mounted
|
// UnmountIpcMount unmounts shm if it was mounted
|
||||||
func (container *Container) UnmountIpcMount(unmount func(pth string) error) error {
|
func (container *Container) UnmountIpcMount() error {
|
||||||
if container.HasMountFor("/dev/shm") {
|
if container.HasMountFor("/dev/shm") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -189,11 +189,9 @@ func (container *Container) UnmountIpcMount(unmount func(pth string) error) erro
|
||||||
if shmPath == "" {
|
if shmPath == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err = unmount(shmPath); err != nil && !os.IsNotExist(err) {
|
if err = mount.Unmount(shmPath); err != nil && !os.IsNotExist(err) {
|
||||||
if mounted, mErr := mount.Mounted(shmPath); mounted || mErr != nil {
|
|
||||||
return errors.Wrapf(err, "umount %s", shmPath)
|
return errors.Wrapf(err, "umount %s", shmPath)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ const (
|
||||||
|
|
||||||
// UnmountIpcMount unmounts Ipc related mounts.
|
// UnmountIpcMount unmounts Ipc related mounts.
|
||||||
// This is a NOOP on windows.
|
// This is a NOOP on windows.
|
||||||
func (container *Container) UnmountIpcMount(unmount func(pth string) error) error {
|
func (container *Container) UnmountIpcMount() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -351,10 +351,6 @@ func killProcessDirectly(cntr *container.Container) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func detachMounted(path string) error {
|
|
||||||
return unix.Unmount(path, unix.MNT_DETACH)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isLinkable(child *container.Container) bool {
|
func isLinkable(child *container.Container) bool {
|
||||||
// A container is linkable only if it belongs to the default network
|
// A container is linkable only if it belongs to the default network
|
||||||
_, ok := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()]
|
_, ok := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()]
|
||||||
|
|
|
@ -78,10 +78,6 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func detachMounted(path string) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
||||||
if len(c.SecretReferences) == 0 {
|
if len(c.SecretReferences) == 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -216,7 +216,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
|
||||||
func (daemon *Daemon) Cleanup(container *container.Container) {
|
func (daemon *Daemon) Cleanup(container *container.Container) {
|
||||||
daemon.releaseNetwork(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)
|
logrus.Warnf("%s cleanup: failed to unmount IPC: %s", container.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue