Skip to content

Commit

Permalink
layerStore.Load(): avoid double-locking the mounts list for Save
Browse files Browse the repository at this point in the history
If we need to re-save the layers list when we've loaded it, to either
solve a duplicate name issue or to clean up a partially-constructed
layer, don't make the mistake of attempting to take another lock on the
mounts list.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
  • Loading branch information
nalind committed Sep 10, 2019
1 parent 1201761 commit d46d549
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions layers.go
Expand Up @@ -372,7 +372,7 @@ func (r *layerStore) Load() error {
}
}
if shouldSave {
return r.Save()
return r.saveLayers()
}
}
return err
Expand Down Expand Up @@ -416,6 +416,16 @@ func (r *layerStore) loadMounts() error {
}

func (r *layerStore) Save() error {
r.mountsLockfile.Lock()
defer r.mountsLockfile.Unlock()
defer r.mountsLockfile.Touch()
if err := r.saveLayers(); err != nil {
return err
}
return r.saveMounts()
}

func (r *layerStore) saveLayers() error {
if !r.IsReadWrite() {
return errors.Wrapf(ErrStoreIsReadOnly, "not allowed to modify the layer store at %q", r.layerspath())
}
Expand All @@ -431,13 +441,7 @@ func (r *layerStore) Save() error {
return err
}
defer r.Touch()
if err := ioutils.AtomicWriteFile(rpath, jldata, 0600); err != nil {
return err
}
r.mountsLockfile.Lock()
defer r.mountsLockfile.Unlock()
defer r.mountsLockfile.Touch()
return r.saveMounts()
return ioutils.AtomicWriteFile(rpath, jldata, 0600)
}

func (r *layerStore) saveMounts() error {
Expand Down

0 comments on commit d46d549

Please sign in to comment.