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 cfa2591d3f26)
via a very expensive call to mount.Mounted().
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
| ... | ... |
@@ -174,8 +174,8 @@ func (container *Container) HasMountFor(path string) bool {
|
| 174 | 174 |
return false |
| 175 | 175 |
} |
| 176 | 176 |
|
| 177 |
-// UnmountIpcMount uses the provided unmount function to unmount shm if it was mounted |
|
| 178 |
-func (container *Container) UnmountIpcMount(unmount func(pth string) error) error {
|
|
| 177 |
+// UnmountIpcMount unmounts shm if it was mounted |
|
| 178 |
+func (container *Container) UnmountIpcMount() error {
|
|
| 179 | 179 |
if container.HasMountFor("/dev/shm") {
|
| 180 | 180 |
return nil |
| 181 | 181 |
} |
| ... | ... |
@@ -189,10 +189,8 @@ func (container *Container) UnmountIpcMount(unmount func(pth string) error) erro |
| 189 | 189 |
if shmPath == "" {
|
| 190 | 190 |
return nil |
| 191 | 191 |
} |
| 192 |
- if err = unmount(shmPath); err != nil && !os.IsNotExist(err) {
|
|
| 193 |
- if mounted, mErr := mount.Mounted(shmPath); mounted || mErr != nil {
|
|
| 194 |
- return errors.Wrapf(err, "umount %s", shmPath) |
|
| 195 |
- } |
|
| 192 |
+ if err = mount.Unmount(shmPath); err != nil && !os.IsNotExist(err) {
|
|
| 193 |
+ return errors.Wrapf(err, "umount %s", shmPath) |
|
| 196 | 194 |
} |
| 197 | 195 |
return nil |
| 198 | 196 |
} |
| ... | ... |
@@ -22,7 +22,7 @@ const ( |
| 22 | 22 |
|
| 23 | 23 |
// UnmountIpcMount unmounts Ipc related mounts. |
| 24 | 24 |
// This is a NOOP on windows. |
| 25 |
-func (container *Container) UnmountIpcMount(unmount func(pth string) error) error {
|
|
| 25 |
+func (container *Container) UnmountIpcMount() error {
|
|
| 26 | 26 |
return nil |
| 27 | 27 |
} |
| 28 | 28 |
|
| ... | ... |
@@ -351,10 +351,6 @@ func killProcessDirectly(cntr *container.Container) error {
|
| 351 | 351 |
return nil |
| 352 | 352 |
} |
| 353 | 353 |
|
| 354 |
-func detachMounted(path string) error {
|
|
| 355 |
- return unix.Unmount(path, unix.MNT_DETACH) |
|
| 356 |
-} |
|
| 357 |
- |
|
| 358 | 354 |
func isLinkable(child *container.Container) bool {
|
| 359 | 355 |
// A container is linkable only if it belongs to the default network |
| 360 | 356 |
_, ok := child.NetworkSettings.Networks[runconfig.DefaultDaemonNetworkMode().NetworkName()] |
| ... | ... |
@@ -78,10 +78,6 @@ func (daemon *Daemon) mountVolumes(container *container.Container) error {
|
| 78 | 78 |
return nil |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
-func detachMounted(path string) error {
|
|
| 82 |
- return nil |
|
| 83 |
-} |
|
| 84 |
- |
|
| 85 | 81 |
func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
|
| 86 | 82 |
if len(c.SecretReferences) == 0 {
|
| 87 | 83 |
return nil |
| ... | ... |
@@ -216,7 +216,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint |
| 216 | 216 |
func (daemon *Daemon) Cleanup(container *container.Container) {
|
| 217 | 217 |
daemon.releaseNetwork(container) |
| 218 | 218 |
|
| 219 |
- if err := container.UnmountIpcMount(detachMounted); err != nil {
|
|
| 219 |
+ if err := container.UnmountIpcMount(); err != nil {
|
|
| 220 | 220 |
logrus.Warnf("%s cleanup: failed to unmount IPC: %s", container.ID, err)
|
| 221 | 221 |
} |
| 222 | 222 |
|