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>
This commit is contained in:
Matthew Heon
2019-08-30 16:09:17 -04:00
parent c8193633cd
commit 5a8a71ed81
5 changed files with 183 additions and 4 deletions

View File

@ -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 {