diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-03-29 10:20:16 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-04-04 12:26:29 -0400 |
commit | 3e066e29202118e6cca60be516ddc08cc7a9060e (patch) | |
tree | 9a2bad85f0ca17592e6936aaf3ac13bdc3f08252 /libpod | |
parent | 7309e38ddda4245a786bb92d036f7836328818c9 (diff) | |
download | podman-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>
Diffstat (limited to 'libpod')
-rw-r--r-- | libpod/runtime_volume_linux.go | 26 |
1 files changed, 21 insertions, 5 deletions
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 |