volumes: add synchronization to Count and List

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
Upstream-commit: 2d21996eec8d3e6100f19fa0d0fa7adad25285ca
Component: engine
This commit is contained in:
Alexander Morozov
2015-09-15 10:38:53 -07:00
parent 19987593e7
commit 8dd1931b2b

View File

@ -227,6 +227,8 @@ func (s *volumeStore) Decrement(v volume.Volume) {
// Count returns the usage count of the passed in volume
func (s *volumeStore) Count(v volume.Volume) int {
s.mu.Lock()
defer s.mu.Unlock()
vc, exists := s.vols[v.Name()]
if !exists {
return 0
@ -236,6 +238,8 @@ func (s *volumeStore) Count(v volume.Volume) int {
// List returns all the available volumes
func (s *volumeStore) List() []volume.Volume {
s.mu.Lock()
defer s.mu.Unlock()
var ls []volume.Volume
for _, vc := range s.vols {
ls = append(ls, vc.Volume)