summaryrefslogtreecommitdiff
path: root/libpod/container_api.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2018-07-19 16:59:42 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2018-07-19 17:01:07 -0400
commit85db3f09bff68efb0a8509f7470b61604aefb447 (patch)
treed3f8c2b92dde29066cb9c20fd79db4dc67a86f0e /libpod/container_api.go
parent98703eb204923f06555605c648fc165a55214520 (diff)
downloadpodman-85db3f09bff68efb0a8509f7470b61604aefb447.tar.gz
podman-85db3f09bff68efb0a8509f7470b61604aefb447.tar.bz2
podman-85db3f09bff68efb0a8509f7470b61604aefb447.zip
Let containers/storage keep track of mounts
Currently we unmount storage that is still in use. We should not be unmounting storeage that we mounted via a different command or by podman mount. This change relies on containers/storage to umount keep track of how many times the storage was mounted before really unmounting it from the system. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'libpod/container_api.go')
-rw-r--r--libpod/container_api.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/libpod/container_api.go b/libpod/container_api.go
index a3756ac5f..bb9727ec1 100644
--- a/libpod/container_api.go
+++ b/libpod/container_api.go
@@ -437,11 +437,7 @@ func (c *Container) Mount() (string, error) {
}
}
- if err := c.mountStorage(); err != nil {
- return "", err
- }
-
- return c.state.Mountpoint, nil
+ return c.mount()
}
// Unmount unmounts a container's filesystem on the host
@@ -456,15 +452,24 @@ func (c *Container) Unmount() error {
}
if c.state.State == ContainerStateRunning || c.state.State == ContainerStatePaused {
- return errors.Wrapf(ErrCtrStateInvalid, "cannot remove storage for container %s as it is running or paused", c.ID())
+ return errors.Wrapf(ErrCtrStateInvalid, "cannot unmount storage for container %s as it is running or paused", c.ID())
}
// Check if we have active exec sessions
if len(c.state.ExecSessions) != 0 {
- return errors.Wrapf(ErrCtrStateInvalid, "container %s has active exec sessions, refusing to clean up", c.ID())
+ return errors.Wrapf(ErrCtrStateInvalid, "container %s has active exec sessions, refusing to unmount", c.ID())
}
- return c.cleanupStorage()
+ if c.state.Mounted {
+ mounted, err := c.runtime.storageService.MountedContainerImage(c.ID())
+ if err != nil {
+ return errors.Wrapf(err, "can't determine how many times %s is mounted, refusing to unmount", c.ID())
+ }
+ if mounted == 1 {
+ return errors.Wrapf(err, "can't unmount %s last mount, it is still in use", c.ID())
+ }
+ }
+ return c.unmount()
}
// Pause pauses a container