Skip to content

Commit

Permalink
Merge pull request #1090 from flouthoc/race-free-manifest-add
Browse files Browse the repository at this point in the history
libimage, ManifestList: `fslock` and `reload` to provide race-free `Add` API
  • Loading branch information
openshift-ci[bot] authored Jul 15, 2022
2 parents 415ead5 + 8a786cc commit 2ac10fa
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion libimage/manifest_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ func (m *ManifestList) saveAndReload() error {
return nil
}

// Reload the image and list instances from storage
func (m *ManifestList) reload() error {
listID := m.ID()
if err := m.image.reload(); err != nil {
return err
}
image, list, err := m.image.runtime.lookupManifestList(listID)
if err != nil {
return err
}
m.image = image
m.list = list
return nil
}

// getManifestList is a helper to obtain a manifest list
func (i *Image) getManifestList() (manifests.List, error) {
_, list, err := manifests.LoadFromImage(i.runtime.store, i.ID())
Expand Down Expand Up @@ -253,7 +268,17 @@ func (m *ManifestList) Add(ctx context.Context, name string, options *ManifestLi
Password: options.Password,
}
}

locker, err := manifests.LockerForImage(m.image.runtime.store, m.ID())
if err != nil {
return "", err
}
locker.Lock()
defer locker.Unlock()
// Make sure to reload the image from the containers storage to fetch
// the latest data (e.g., new or delete digests).
if err := m.reload(); err != nil {
return "", err
}
newDigest, err := m.list.Add(ctx, systemContext, ref, options.All)
if err != nil {
return "", err
Expand Down

0 comments on commit 2ac10fa

Please sign in to comment.