aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2020-08-19 17:41:36 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-08-20 12:18:22 -0400
commit402d002184fa33b8aa7bfe91a83b04ba80425e28 (patch)
tree7ba3fd9206e09e1edb0acfab5d8c6a3fb7dd55b9
parentee956b04b05eed25d3aec967d8c68e7d1418fa09 (diff)
downloadpodman-402d002184fa33b8aa7bfe91a83b04ba80425e28.tar.gz
podman-402d002184fa33b8aa7bfe91a83b04ba80425e28.tar.bz2
podman-402d002184fa33b8aa7bfe91a83b04ba80425e28.zip
Unmount c/storage containers before removing them
When `podman rmi --force` is run, it will remove any containers that depend on the image. This includes Podman containers, but also any other c/storage users who may be using it. With Podman containers, we use the standard Podman removal function for containers, which handles all edge cases nicely, shutting down running containers, ensuring they're unmounted, etc. Unfortunately, no such convient function exists (or can exist) for all c/storage containers. Identifying the PID of a Buildah, CRI-O, or Podman container is extremely different, and those are just the implementations under the containers org. We can't reasonably be able to know if a c/storage container is *in use* and safe for removal if it's not a Podman container. At the very least, though, we can attempt to unmount a storage container before removing it. If it is in use, this will fail (probably with a not-particularly-helpful error message), but if it is not in use but not fully cleaned up, this should make our removing it much more robust than it normally is. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
-rw-r--r--libpod/runtime_img.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go
index 8f2f82ad3..9515aa468 100644
--- a/libpod/runtime_img.go
+++ b/libpod/runtime_img.go
@@ -140,6 +140,10 @@ func storageContainers(imageID string, store storage.Store) ([]string, error) {
// Removes the containers passed in the array.
func removeStorageContainers(ctrIDs []string, store storage.Store) error {
for _, ctrID := range ctrIDs {
+ if _, err := store.Unmount(ctrID, true); err != nil {
+ return errors.Wrapf(err, "could not unmount container %q to remove it", ctrID)
+ }
+
if err := store.DeleteContainer(ctrID); err != nil {
return errors.Wrapf(err, "could not remove container %q", ctrID)
}