layerStore.Load(): avoid double-locking the mounts list for Save

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>
This commit is contained in:
Nalin Dahyabhai 2019-09-10 12:52:27 -04:00
parent 1201761454
commit d46d549322
1 changed files with 12 additions and 8 deletions

View File

@ -372,7 +372,7 @@ func (r *layerStore) Load() error {
}
}
if shouldSave {
return r.Save()
return r.saveLayers()
}
}
return err
@ -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())
}
@ -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 {