mirror of
https://github.com/containers/podman.git
synced 2025-09-14 20:13:22 +08:00
Update c/storage after https://github.com/containers/storage/pull/1436
... and update to remove the now-deprecated Locker interface. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
33
vendor/github.com/containers/storage/containers.go
generated
vendored
33
vendor/github.com/containers/storage/containers.go
generated
vendored
@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/containers/storage/pkg/idtools"
|
||||
"github.com/containers/storage/pkg/ioutils"
|
||||
"github.com/containers/storage/pkg/lockfile"
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
"github.com/containers/storage/pkg/truncindex"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
@ -140,9 +141,10 @@ type rwContainerStore interface {
|
||||
}
|
||||
|
||||
type containerStore struct {
|
||||
lockfile Locker
|
||||
lockfile *lockfile.LockFile
|
||||
dir string
|
||||
jsonPath [numContainerLocationIndex]string
|
||||
lastWrite lockfile.LastWrite
|
||||
containers []*Container
|
||||
idindex *truncindex.TruncIndex
|
||||
byid map[string]*Container
|
||||
@ -262,7 +264,7 @@ func (r *containerStore) startReading() error {
|
||||
|
||||
r.lockfile.Lock()
|
||||
unlockFn = r.lockfile.Unlock
|
||||
if _, err := r.load(true); err != nil {
|
||||
if _, err := r.reloadIfChanged(true); err != nil {
|
||||
return err
|
||||
}
|
||||
unlockFn()
|
||||
@ -295,19 +297,20 @@ func (r *containerStore) stopReading() {
|
||||
// if it is held for writing.
|
||||
//
|
||||
// If !lockedForWriting and this function fails, the return value indicates whether
|
||||
// load() with lockedForWriting could succeed. In that case the caller MUST
|
||||
// call load(), not reloadIfChanged() (because the “if changed” state will not
|
||||
// be detected again).
|
||||
// reloadIfChanged() with lockedForWriting could succeed.
|
||||
func (r *containerStore) reloadIfChanged(lockedForWriting bool) (bool, error) {
|
||||
r.loadMut.Lock()
|
||||
defer r.loadMut.Unlock()
|
||||
|
||||
modified, err := r.lockfile.Modified()
|
||||
lastWrite, modified, err := r.lockfile.ModifiedSince(r.lastWrite)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if modified {
|
||||
return r.load(lockedForWriting)
|
||||
if tryLockedForWriting, err := r.load(lockedForWriting); err != nil {
|
||||
return tryLockedForWriting, err // r.lastWrite is unchanged, so we will load the next time again.
|
||||
}
|
||||
r.lastWrite = lastWrite
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
@ -363,6 +366,9 @@ func (r *containerStore) datapath(id, key string) string {
|
||||
|
||||
// load reloads the contents of the store from disk.
|
||||
//
|
||||
// Most callers should call reloadIfChanged() instead, to avoid overhead and to correctly
|
||||
// manage r.lastWrite.
|
||||
//
|
||||
// The caller must hold r.lockfile for reading _or_ writing; lockedForWriting is true
|
||||
// if it is held for writing.
|
||||
//
|
||||
@ -469,7 +475,12 @@ func (r *containerStore) save(saveLocations containerLocations) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return r.lockfile.Touch()
|
||||
lw, err := r.lockfile.RecordWrite()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.lastWrite = lw
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *containerStore) saveFor(modifiedContainer *Container) error {
|
||||
@ -487,7 +498,7 @@ func newContainerStore(dir string, runDir string, transient bool) (rwContainerSt
|
||||
}
|
||||
volatileDir = runDir
|
||||
}
|
||||
lockfile, err := GetLockfile(filepath.Join(volatileDir, "containers.lock"))
|
||||
lockfile, err := lockfile.GetLockFile(filepath.Join(volatileDir, "containers.lock"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -507,6 +518,10 @@ func newContainerStore(dir string, runDir string, transient bool) (rwContainerSt
|
||||
if err := cstore.startWritingWithReload(false); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cstore.lastWrite, err = cstore.lockfile.GetLastWrite()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cstore.stopWriting()
|
||||
if _, err := cstore.load(true); err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user