diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-08-30 16:09:17 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-09-05 12:29:36 -0400 |
commit | 5a8a71ed817a4fa50fd9444846a50b76f25228d1 (patch) | |
tree | dee3a3bc42d410ff184acfa38d49ac1e5ad5bbed /libpod/volume.go | |
parent | c8193633cd82228b01e789becead410c2a940227 (diff) | |
download | podman-5a8a71ed817a4fa50fd9444846a50b76f25228d1.tar.gz podman-5a8a71ed817a4fa50fd9444846a50b76f25228d1.tar.bz2 podman-5a8a71ed817a4fa50fd9444846a50b76f25228d1.zip |
Add volume state
We need to be able to track the number of times a volume has been
mounted for tmpfs/nfs/etc volumes. As such, we need a mutable
state for volumes. Add one, with the expected update/save methods
in both states.
There is backwards compat here, in that older volumes without a
state will still be accepted.
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/volume.go')
-rw-r--r-- | libpod/volume.go | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/libpod/volume.go b/libpod/volume.go index e6e92c3ac..5970867c3 100644 --- a/libpod/volume.go +++ b/libpod/volume.go @@ -6,17 +6,20 @@ import ( "github.com/containers/libpod/libpod/lock" ) -// Volume is the type used to create named volumes -// TODO: all volumes should be created using this and the Volume API +// Volume is a libpod named volume. +// Named volumes may be shared by multiple containers, and may be created using +// more complex options than normal bind mounts. They may be backed by a mounted +// filesystem on the host. type Volume struct { config *VolumeConfig + state *VolumeState valid bool runtime *Runtime lock lock.Locker } -// VolumeConfig holds the volume's config information +// VolumeConfig holds the volume's immutable configuration. type VolumeConfig struct { // Name of the volume. Name string `json:"name"` @@ -34,7 +37,15 @@ type VolumeConfig struct { // Options to pass to the volume driver. For the local driver, this is // a list of mount options. For other drivers, they are passed to the // volume driver handling the volume. - Options map[string]string `json:"volumeOptions"` + Options map[string]string `json:"volumeOptions,omitempty"` + // Type is the type of the volume. This is only used with the local + // driver. It the the filesystem that we will attempt to mount - nfs, + // tmpfs, etc. + Type string `json:"type,omitempty"` + // Device is the device of the volume. This is only used with the local + // driver, and only with some filesystem types (e.g., not required by + // tmpfs). It is the device to mount. + Device string `json:"device,omitempty"` // Whether this volume was created for a specific container and will be // removed with it. IsCtrSpecific bool `json:"ctrSpecific"` @@ -44,6 +55,18 @@ type VolumeConfig struct { GID int `json:"gid"` } +// VolumeState holds the volume's mutable state. +// Volumes are not guaranteed to have a state. Only volumes using the Local +// driver that have mount options set will create a state. +type VolumeState struct { + // MountCount is the number of times this volume has been requested to + // be mounted. + // It is incremented on mount() and decremented on unmount(). + // On incrementing from 0, the volume will be mounted on the host. + // On decrementing to 0, the volume will be unmounted on the host. + MountCount uint `json:"mountCount"` +} + // Name retrieves the volume's name func (v *Volume) Name() string { return v.config.Name |