Merge pull request #926 from giuseppe/fix-race-reload-store

store: fix graphLock reload
This commit is contained in:
Daniel J Walsh 2021-05-27 12:26:57 -04:00 committed by GitHub
commit 5477b9995b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 19 deletions

View File

@ -626,5 +626,5 @@ func (r *containerStore) ReloadIfChanged() error {
if err == nil && modified {
return r.Load()
}
return nil
return err
}

View File

@ -810,5 +810,5 @@ func (r *imageStore) ReloadIfChanged() error {
if err == nil && modified {
return r.Load()
}
return nil
return err
}

View File

@ -1780,7 +1780,7 @@ func (r *layerStore) ReloadIfChanged() error {
if err == nil && modified {
return r.Load()
}
return nil
return err
}
func closeAll(closes ...func() error) (rErr error) {

View File

@ -788,6 +788,15 @@ func (s *store) load() error {
}
s.containerStore = rcs
for _, store := range driver.AdditionalImageStores() {
gipath := filepath.Join(store, driverPrefix+"images")
ris, err := newROImageStore(gipath)
if err != nil {
return err
}
s.roImageStores = append(s.roImageStores, ris)
}
s.digestLockRoot = filepath.Join(s.runRoot, driverPrefix+"locks")
if err := os.MkdirAll(s.digestLockRoot, 0700); err != nil {
return err
@ -910,22 +919,10 @@ func (s *store) ImageStore() (ImageStore, error) {
// Store. Accessing these stores directly will bypass locking and
// synchronization, so it is not a part of the exported Store interface.
func (s *store) ROImageStores() ([]ROImageStore, error) {
if len(s.roImageStores) != 0 {
return s.roImageStores, nil
}
driver, err := s.getGraphDriver()
if err != nil {
return nil, err
}
driverPrefix := s.graphDriverName + "-"
for _, store := range driver.AdditionalImageStores() {
gipath := filepath.Join(store, driverPrefix+"images")
ris, err := newROImageStore(gipath)
if err != nil {
return nil, err
}
s.roImageStores = append(s.roImageStores, ris)
if s.imageStore == nil {
return nil, ErrLoadError
}
return s.roImageStores, nil
}
@ -2655,8 +2652,13 @@ func (s *store) mount(id string, options drivers.MountOpts) (string, error) {
return "", err
}
modified, err := s.graphLock.Modified()
if err != nil {
return "", err
}
/* We need to make sure the home mount is present when the Mount is done. */
if s.graphLock.TouchedSince(s.lastLoaded) {
if modified {
s.graphDriver = nil
s.layerStore = nil
s.graphDriver, err = s.getGraphDriver()