Skip to content

Commit

Permalink
Merge pull request containers#213 from nalind/rolayer-lock
Browse files Browse the repository at this point in the history
Fix a lock inversion
  • Loading branch information
rhatdan authored Sep 12, 2018
2 parents d0cb010 + c8670ef commit 243c4cd
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,11 +1091,6 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
if err != nil {
return nil, err
}
rlstore.Lock()
defer rlstore.Unlock()
if modified, err := rlstore.Modified(); modified || err != nil {
rlstore.Load()
}
if id == "" {
id = stringid.GenerateRandomID()
}
Expand All @@ -1108,6 +1103,10 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
idMappingsOptions := options.IDMappingOptions
if image != "" {
var imageHomeStore ROImageStore
lstores, err := s.ROLayerStores()
if err != nil {
return nil, err
}
istore, err := s.ImageStore()
if err != nil {
return nil, err
Expand All @@ -1116,6 +1115,11 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
if err != nil {
return nil, err
}
rlstore.Lock()
defer rlstore.Unlock()
if modified, err := rlstore.Modified(); modified || err != nil {
rlstore.Load()
}
var cimage *Image
for _, store := range append([]ROImageStore{istore}, istores...) {
store.Lock()
Expand All @@ -1134,10 +1138,6 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
}
imageID = cimage.ID

lstores, err := s.ROLayerStores()
if err != nil {
return nil, err
}
ilayer, err := s.imageTopLayerForMapping(cimage, imageHomeStore, imageHomeStore == istore, rlstore, lstores, idMappingsOptions)
if err != nil {
return nil, err
Expand All @@ -1150,6 +1150,11 @@ func (s *store) CreateContainer(id string, names []string, image, layer, metadat
gidMap = ilayer.GIDMap
}
} else {
rlstore.Lock()
defer rlstore.Unlock()
if modified, err := rlstore.Modified(); modified || err != nil {
rlstore.Load()
}
if !options.HostUIDMapping && len(options.UIDMap) == 0 {
uidMap = s.uidMap
}
Expand Down

0 comments on commit 243c4cd

Please sign in to comment.