From 8e1ef558eb324767ac46e452c80cc79f7ba2e9d2 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Mon, 30 Jul 2018 09:04:18 -0400 Subject: Add --force to podman umount to force the unmounting of the rootfs podman umount will currently only unmount file system if not other process is using it, otherwise the umount decrements the container storage to indicate that the caller is no longer using the mount point, once the count gets to 0, the file system is actually unmounted. Signed-off-by: Daniel J Walsh Closes: #1184 Approved by: TomSweeneyRedHat --- libpod/container_api.go | 4 ++-- libpod/container_internal.go | 6 +++--- libpod/storage.go | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) (limited to 'libpod') diff --git a/libpod/container_api.go b/libpod/container_api.go index b5104048e..73fd96960 100644 --- a/libpod/container_api.go +++ b/libpod/container_api.go @@ -441,7 +441,7 @@ func (c *Container) Mount() (string, error) { } // Unmount unmounts a container's filesystem on the host -func (c *Container) Unmount() error { +func (c *Container) Unmount(force bool) error { if !c.batched { c.lock.Lock() defer c.lock.Unlock() @@ -469,7 +469,7 @@ func (c *Container) Unmount() error { return errors.Wrapf(err, "can't unmount %s last mount, it is still in use", c.ID()) } } - return c.unmount() + return c.unmount(force) } // Pause pauses a container diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 66d1e44ad..7b5932541 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -839,7 +839,7 @@ func (c *Container) cleanupStorage() error { return nil } - if err := c.unmount(); err != nil { + if err := c.unmount(false); err != nil { // If the container has already been removed, warn but don't // error // We still want to be able to kick the container out of the @@ -1338,9 +1338,9 @@ func (c *Container) mount() (string, error) { } // unmount unmounts the container's root filesystem -func (c *Container) unmount() error { +func (c *Container) unmount(force bool) error { // Also unmount storage - if _, err := c.runtime.storageService.UnmountContainerImage(c.ID()); err != nil { + if _, err := c.runtime.storageService.UnmountContainerImage(c.ID(), force); err != nil { return errors.Wrapf(err, "error unmounting container %s root filesystem", c.ID()) } diff --git a/libpod/storage.go b/libpod/storage.go index 9c5fc858e..10827f13e 100644 --- a/libpod/storage.go +++ b/libpod/storage.go @@ -231,7 +231,7 @@ func (r *storageService) MountContainerImage(idOrName string) (string, error) { return mountPoint, nil } -func (r *storageService) UnmountContainerImage(idOrName string) (bool, error) { +func (r *storageService) UnmountContainerImage(idOrName string, force bool) (bool, error) { if idOrName == "" { return false, ErrEmptyID } @@ -239,7 +239,17 @@ func (r *storageService) UnmountContainerImage(idOrName string) (bool, error) { if err != nil { return false, err } - mounted, err := r.store.Unmount(container.ID, false) + + if !force { + mounted, err := r.store.Mounted(container.ID) + if err != nil { + return false, err + } + if mounted == 0 { + return false, storage.ErrLayerNotMounted + } + } + mounted, err := r.store.Unmount(container.ID, force) if err != nil { logrus.Debugf("failed to unmount container %q: %v", container.ID, err) return false, err -- cgit v1.2.3-54-g00ecf