diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-09-03 15:03:44 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-09-05 17:12:27 -0400 |
commit | a760e325f3180638f9fedd0ee79d4c6695d8ba64 (patch) | |
tree | 7969ab74dfe2c41df7387fd0601014dcd9656052 /libpod/runtime_volume_linux.go | |
parent | 5a8a71ed817a4fa50fd9444846a50b76f25228d1 (diff) | |
download | podman-a760e325f3180638f9fedd0ee79d4c6695d8ba64.tar.gz podman-a760e325f3180638f9fedd0ee79d4c6695d8ba64.tar.bz2 podman-a760e325f3180638f9fedd0ee79d4c6695d8ba64.zip |
Add ability for volumes with options to mount/umount
When volume options and the local volume driver are specified,
the volume is intended to be mounted using the 'mount' command.
Supported options will be used to volume the volume before the
first container using it starts, and unmount the volume after the
last container using it dies.
This should work for any local filesystem, though at present I've
only tested with tmpfs and btrfs.
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/runtime_volume_linux.go')
-rw-r--r-- | libpod/runtime_volume_linux.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libpod/runtime_volume_linux.go b/libpod/runtime_volume_linux.go index 70296248c..cf8055c7b 100644 --- a/libpod/runtime_volume_linux.go +++ b/libpod/runtime_volume_linux.go @@ -48,6 +48,19 @@ func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption) } volume.config.CreatedTime = time.Now() + if volume.config.Driver == "local" { + logrus.Debugf("Validating options for local driver") + // Validate options + for key := range volume.config.Options { + switch key { + case "device", "o", "type": + // Do nothing, valid keys + default: + return nil, errors.Wrapf(define.ErrInvalidArg, "invalid mount option %s for driver 'local'", key) + } + } + } + // Create the mountpoint of this volume volPathRoot := filepath.Join(r.config.VolumePath, volume.config.Name) if err := os.MkdirAll(volPathRoot, 0700); err != nil { @@ -102,6 +115,11 @@ func (r *Runtime) removeVolume(ctx context.Context, v *Volume, force bool) error return define.ErrVolumeRemoved } + // Update volume status to pick up a potential removal from state + if err := v.update(); err != nil { + return err + } + deps, err := r.state.VolumeInUse(v) if err != nil { return err @@ -137,6 +155,11 @@ func (r *Runtime) removeVolume(ctx context.Context, v *Volume, force bool) error } } + // If the volume is still mounted - force unmount it + if err := v.unmount(true); err != nil { + return errors.Wrapf(err, "error unmounting volume %s", v.Name()) + } + // Set volume as invalid so it can no longer be used v.valid = false |