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/in_memory_state.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/in_memory_state.go')
-rw-r--r-- | libpod/in_memory_state.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libpod/in_memory_state.go b/libpod/in_memory_state.go index a9b735327..280ae5f5c 100644 --- a/libpod/in_memory_state.go +++ b/libpod/in_memory_state.go @@ -507,6 +507,36 @@ func (s *InMemoryState) RemoveVolume(volume *Volume) error { return nil } +// UpdateVolume updates a volume from the database. +// For the in-memory state, this is a no-op. +func (s *InMemoryState) UpdateVolume(volume *Volume) error { + if !volume.valid { + return define.ErrVolumeRemoved + } + + if _, ok := s.volumes[volume.Name()]; !ok { + volume.valid = false + return errors.Wrapf(define.ErrNoSuchVolume, "volume with name %q not found in state", volume.Name()) + } + + return nil +} + +// SaveVolume saves a volume's state to the database. +// For the in-memory state, this is a no-op. +func (s *InMemoryState) SaveVolume(volume *Volume) error { + if !volume.valid { + return define.ErrVolumeRemoved + } + + if _, ok := s.volumes[volume.Name()]; !ok { + volume.valid = false + return errors.Wrapf(define.ErrNoSuchVolume, "volume with name %q not found in state", volume.Name()) + } + + return nil +} + // VolumeInUse checks if the given volume is being used by at least one container func (s *InMemoryState) VolumeInUse(volume *Volume) ([]string, error) { if !volume.valid { |