1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Rearrange layerstore locking

Signed-off-by: Aidan Hobson Sayers <aidanhs@cantab.net>
This commit is contained in:
Aidan Hobson Sayers 2015-11-20 12:35:01 +00:00
parent a2ab05098d
commit cbf55b924f
3 changed files with 15 additions and 27 deletions

View file

@ -269,7 +269,7 @@ func (ls *layerStore) Register(ts io.Reader, parent ChainID) (Layer, error) {
ls.layerL.Lock() ls.layerL.Lock()
defer ls.layerL.Unlock() defer ls.layerL.Unlock()
if existingLayer := ls.getAndRetainLayer(layer.chainID); existingLayer != nil { if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil {
// Set error for cleanup, but do not return the error // Set error for cleanup, but do not return the error
err = errors.New("layer already exists") err = errors.New("layer already exists")
return existingLayer.getReference(), nil return existingLayer.getReference(), nil
@ -284,18 +284,21 @@ func (ls *layerStore) Register(ts io.Reader, parent ChainID) (Layer, error) {
return layer.getReference(), nil return layer.getReference(), nil
} }
func (ls *layerStore) get(l ChainID) *roLayer { func (ls *layerStore) getWithoutLock(layer ChainID) *roLayer {
ls.layerL.Lock() l, ok := ls.layerMap[layer]
defer ls.layerL.Unlock()
layer, ok := ls.layerMap[l]
if !ok { if !ok {
return nil return nil
} }
layer.referenceCount++ l.referenceCount++
return layer return l
}
func (ls *layerStore) get(l ChainID) *roLayer {
ls.layerL.Lock()
defer ls.layerL.Unlock()
return ls.getWithoutLock(l)
} }
func (ls *layerStore) Get(l ChainID) (Layer, error) { func (ls *layerStore) Get(l ChainID) (Layer, error) {
@ -415,17 +418,6 @@ func (ls *layerStore) saveMount(mount *mountedLayer) error {
return nil return nil
} }
func (ls *layerStore) getAndRetainLayer(layer ChainID) *roLayer {
l, ok := ls.layerMap[layer]
if !ok {
return nil
}
l.referenceCount++
return l
}
func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit) (string, error) { func (ls *layerStore) initMount(graphID, parent, mountLabel string, initFunc MountInit) (string, error) {
// Use "<graph-id>-init" to maintain compatibility with graph drivers // Use "<graph-id>-init" to maintain compatibility with graph drivers
// which are expecting this layer with this special name. If all // which are expecting this layer with this special name. If all
@ -468,9 +460,7 @@ func (ls *layerStore) Mount(name string, parent ChainID, mountLabel string, init
var pid string var pid string
var p *roLayer var p *roLayer
if string(parent) != "" { if string(parent) != "" {
ls.layerL.Lock() p = ls.get(parent)
p = ls.getAndRetainLayer(parent)
ls.layerL.Unlock()
if p == nil { if p == nil {
return nil, ErrLayerDoesNotExist return nil, ErrLayerDoesNotExist
} }

View file

@ -93,7 +93,7 @@ func (ls *layerStore) RegisterDiffID(graphID string, size int64) (Layer, error)
ls.layerL.Lock() ls.layerL.Lock()
defer ls.layerL.Unlock() defer ls.layerL.Unlock()
if existingLayer := ls.getAndRetainLayer(layer.chainID); existingLayer != nil { if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil {
// Set error for cleanup, but do not return // Set error for cleanup, but do not return
err = errors.New("layer already exists") err = errors.New("layer already exists")
return existingLayer.getReference(), nil return existingLayer.getReference(), nil

View file

@ -35,9 +35,7 @@ func (ls *layerStore) MountByGraphID(name string, graphID string, parent ChainID
var p *roLayer var p *roLayer
if string(parent) != "" { if string(parent) != "" {
ls.layerL.Lock() p = ls.get(parent)
p = ls.getAndRetainLayer(parent)
ls.layerL.Unlock()
if p == nil { if p == nil {
return nil, ErrLayerDoesNotExist return nil, ErrLayerDoesNotExist
} }
@ -209,7 +207,7 @@ func (ls *layerStore) RegisterByGraphID(graphID string, parent ChainID, tarDataF
ls.layerL.Lock() ls.layerL.Lock()
defer ls.layerL.Unlock() defer ls.layerL.Unlock()
if existingLayer := ls.getAndRetainLayer(layer.chainID); existingLayer != nil { if existingLayer := ls.getWithoutLock(layer.chainID); existingLayer != nil {
// Set error for cleanup, but do not return // Set error for cleanup, but do not return
err = errors.New("layer already exists") err = errors.New("layer already exists")
return existingLayer.getReference(), nil return existingLayer.getReference(), nil