Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store: lock additional store before validating image #1589

Merged
merged 1 commit into from
May 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2470,28 +2470,22 @@ func (s *store) DeleteLayer(id string) error {
func (s *store) DeleteImage(id string, commit bool) (layers []string, err error) {
layersToRemove := []string{}
if err := s.writeToAllStores(func(rlstore rwLayerStore) error {
// Perform delete image on primary imageStore but if image
// is not found on primary store then try delete on any additional
// write-able image store.
imageStores := []rwImageStore{s.imageStore}
imageStores = append(imageStores, s.rwImageStores...)
// Delete image from all available imagestores configured to be used.
imageFound := false
primaryImageStore := true
for _, imageStore := range imageStores {
if !imageStore.Exists(id) {
primaryImageStore = false
continue
}
imageFound = true
if !primaryImageStore {
for _, is := range append([]rwImageStore{s.imageStore}, s.rwImageStores...) {
if is != s.imageStore {
// This is an additional writeable image store
// so we must perform lock
if err := imageStore.startWriting(); err != nil {
if err := is.startWriting(); err != nil {
return err
}
defer imageStore.stopWriting()
defer is.stopWriting()
}
image, err := imageStore.Get(id)
if !is.Exists(id) {
continue
}
imageFound = true
image, err := is.Get(id)
if err != nil {
return err
}
Expand All @@ -2507,7 +2501,7 @@ func (s *store) DeleteImage(id string, commit bool) (layers []string, err error)
if container, ok := aContainerByImage[id]; ok {
return fmt.Errorf("image used by %v: %w", container, ErrImageUsedByContainer)
}
images, err := imageStore.Images()
images, err := is.Images()
if err != nil {
return err
}
Expand All @@ -2529,7 +2523,7 @@ func (s *store) DeleteImage(id string, commit bool) (layers []string, err error)
}
}
if commit {
if err = imageStore.Delete(id); err != nil {
if err = is.Delete(id); err != nil {
return err
}
}
Expand Down