summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-03-29 10:20:16 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-04-04 12:26:29 -0400
commit3e066e29202118e6cca60be516ddc08cc7a9060e (patch)
tree9a2bad85f0ca17592e6936aaf3ac13bdc3f08252
parent7309e38ddda4245a786bb92d036f7836328818c9 (diff)
downloadpodman-3e066e29202118e6cca60be516ddc08cc7a9060e.tar.gz
podman-3e066e29202118e6cca60be516ddc08cc7a9060e.tar.bz2
podman-3e066e29202118e6cca60be516ddc08cc7a9060e.zip
Volume force-remove now removed dependent containers
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
-rw-r--r--docs/podman-volume-rm.1.md3
-rw-r--r--libpod/runtime_volume_linux.go26
2 files changed, 23 insertions, 6 deletions
diff --git a/docs/podman-volume-rm.1.md b/docs/podman-volume-rm.1.md
index c23d7675c..8c3765235 100644
--- a/docs/podman-volume-rm.1.md
+++ b/docs/podman-volume-rm.1.md
@@ -21,7 +21,8 @@ Remove all volumes.
**-f**, **--force**=""
-Remove a volume by force, even if it is being used by a container
+Remove a volume by force.
+If it is being used by containers, the containers will be removed first.
**--help**
diff --git a/libpod/runtime_volume_linux.go b/libpod/runtime_volume_linux.go
index 39c2f808d..dcefcde4e 100644
--- a/libpod/runtime_volume_linux.go
+++ b/libpod/runtime_volume_linux.go
@@ -99,11 +99,27 @@ func (r *Runtime) removeVolume(ctx context.Context, v *Volume, force bool) error
return errors.Wrapf(ErrVolumeBeingUsed, "volume %s is being used by the following container(s): %s", v.Name(), depsStr)
}
- // TODO: force-removing a volume makes *no sense*
- // I do not believe we should be allowing this at all.
- // For now, return angry errors.
- // TODO: need to do something more sane in this case
- return errors.Wrapf(ErrVolumeBeingUsed, "TODO: FIXME - still refusing to remove because force-removing an in-use volume is not good.")
+ // We need to remove all containers using the volume
+ for _, dep := range deps {
+ ctr, err := r.state.Container(dep)
+ if err != nil {
+ // If the container's removed, no point in
+ // erroring.
+ if errors.Cause(err) == ErrNoSuchCtr || errors.Cause(err) == ErrCtrRemoved {
+ continue
+ }
+
+ return errors.Wrapf(err, "error removing container %s that depends on volume %s", dep, v.Name())
+ }
+
+ // TODO: do we want to set force here when removing
+ // containers?
+ // I'm inclined to say no, in case someone accidentally
+ // wipes a container they're using...
+ if err := r.removeContainer(ctx, ctr, false, true); err != nil {
+ return errors.Wrapf(err, "error removing container %s that depends on volume %s", ctr.ID(), v.Name())
+ }
+ }
}
// Set volume as invalid so it can no longer be used