From d46d549322163d04271b907dd6ad4f488f32f6ba Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Tue, 10 Sep 2019 12:52:27 -0400 Subject: [PATCH 1/2] 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 --- layers.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/layers.go b/layers.go index d746ba0612..eb918b2bf5 100644 --- a/layers.go +++ b/layers.go @@ -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 { From 2fffa4842d2e3d319fd23e9cb061e08835c49e40 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Tue, 10 Sep 2019 12:58:33 -0400 Subject: [PATCH 2/2] Update generated files Signed-off-by: Nalin Dahyabhai --- layers_ffjson.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layers_ffjson.go b/layers_ffjson.go index 3a10952263..f1fbbcb5bc 100644 --- a/layers_ffjson.go +++ b/layers_ffjson.go @@ -1,5 +1,5 @@ // Code generated by ffjson . DO NOT EDIT. -// source: layers.go +// source: ./layers.go package storage