浏览代码

volume/store: fix couple of races with accessing maps

Signed-off-by: Alexander Morozov <lk4d4@docker.com>
(cherry picked from commit e6d87c0706d178407ffccaab5c3ffc13a9e7b02e)
Alexander Morozov 9 年之前
父节点
当前提交
3fd08cc5e6
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      volume/store/store.go

+ 6 - 1
volume/store/store.go

@@ -267,7 +267,9 @@ func (s *VolumeStore) create(name, driverName string, opts, labels map[string]st
 	if err != nil {
 		return nil, err
 	}
+	s.globalLock.Lock()
 	s.labels[name] = labels
+	s.globalLock.Unlock()
 
 	if s.db != nil {
 		metadata := &volumeMetadata{
@@ -362,7 +364,10 @@ func (s *VolumeStore) getVolume(name string) (volume.Volume, error) {
 	}
 
 	logrus.Debugf("Getting volume reference for name: %s", name)
-	if v, exists := s.names[name]; exists {
+	s.globalLock.Lock()
+	v, exists := s.names[name]
+	s.globalLock.Unlock()
+	if exists {
 		vd, err := volumedrivers.GetDriver(v.DriverName())
 		if err != nil {
 			return nil, err