Skip to content

Commit

Permalink
Merge pull request docker#20513 from tonistiigi/retake-ref
Browse files Browse the repository at this point in the history
Fix releasing reference on deletion error
  • Loading branch information
calavera committed Feb 19, 2016
2 parents a657cfd + 64530c8 commit e51457e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions layer/layer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,21 @@ func (ls *layerStore) ReleaseRWLayer(l RWLayer) ([]Metadata, error) {

if err := ls.driver.Remove(m.mountID); err != nil {
logrus.Errorf("Error removing mounted layer %s: %s", m.name, err)
m.retakeReference(l)
return nil, err
}

if m.initID != "" {
if err := ls.driver.Remove(m.initID); err != nil {
logrus.Errorf("Error removing init layer %s: %s", m.name, err)
m.retakeReference(l)
return nil, err
}
}

if err := ls.store.RemoveMount(m.name); err != nil {
logrus.Errorf("Error removing mount metadata: %s: %s", m.name, err)
m.retakeReference(l)
return nil, err
}

Expand Down
7 changes: 7 additions & 0 deletions layer/mounted_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ func (ml *mountedLayer) deleteReference(ref RWLayer) error {
return nil
}

func (ml *mountedLayer) retakeReference(r RWLayer) {
if ref, ok := r.(*referencedRWLayer); ok {
ref.activityCount = 0
ml.references[ref] = ref
}
}

type referencedRWLayer struct {
*mountedLayer

Expand Down

0 comments on commit e51457e

Please sign in to comment.